Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/missing translations for attachments #1218

Merged
merged 3 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions packages/bygger/src/translations/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import {
FormioTranslationMap,
MockedComponentObjectForTest,
NavFormType,
TEXTS,
} from '@navikt/skjemadigitalisering-shared-domain';
import { getFormTexts, getTextsAndTranslationsForForm, getTextsAndTranslationsHeaders } from './utils';

const {
createDummyAttachment,
createDummyAttachmentValues,
createDummyCheckbox,
createDummyContainerElement,
createDummyContentElement,
Expand Down Expand Up @@ -284,6 +287,44 @@ describe('testGetAllTextsAndTypeForForm', () => {
{ text: 'Juice', type: 'text' },
]);
});

it('Test form with Attachment', () => {
const actual = getFormTexts(
createFormObject(
[
createPanelObject(
'Vedleggspanel',
[
createDummyAttachment(
'Mitt vedlegg',
{ vedleggstittel: 'Vedleggstittel', vedleggskode: 'ABC' },
createDummyAttachmentValues([
{ key: 'leggerVedNaa' },
{ key: 'ettersender', label: 'Ettersending label', description: 'Ettersending description' },
{ key: 'harIkke', label: 'Har ikke label' },
]),
),
],
'Vedleggspanel',
),
],
'title',
),
true,
);
expect(actual).toEqual([
{ text: 'title', type: 'text' },
{ text: 'Vedleggspanel', type: 'text' },
{ text: 'Mitt vedlegg', type: 'text' },
{ text: TEXTS.statiske.attachment.leggerVedNaa, type: 'text' },
{ text: TEXTS.statiske.attachment.ettersender, type: 'text' },
{ text: 'Ettersending label', type: 'text' },
{ text: 'Ettersending description', type: 'text' },
{ text: TEXTS.statiske.attachment.harIkke, type: 'text' },
{ text: 'Har ikke label', type: 'text' },
]);
});

it('Test form with button component', () => {
const actual = getFormTexts(
createFormObject(
Expand Down
13 changes: 8 additions & 5 deletions packages/bygger/src/translations/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
NavFormType,
navFormUtils,
signatureUtils,
TEXTS,
} from '@navikt/skjemadigitalisering-shared-domain';

type TextObjectType = { text: string; type?: InputType };
Expand Down Expand Up @@ -183,10 +184,12 @@ const getAttachmentTexts = (attachmentValues?: AttachmentSettingValues): undefin
return undefined;
}

return Object.values(attachmentValues).flatMap((value: AttachmentSettingValue) => {
return value.additionalDocumentation
return Object.entries(attachmentValues).flatMap(([key, value]: [string, AttachmentSettingValue]) => {
const option = value.enabled ? [TEXTS.statiske.attachment[key]] : [];
const additionalDocumentation = value.additionalDocumentation
? [value?.additionalDocumentation?.label, value?.additionalDocumentation?.description]
: [];
return [...option, ...additionalDocumentation];
});
};

Expand All @@ -205,11 +208,11 @@ const getFormTexts = (form?: NavFormType, withInputType = false): TextObjectType
return simplifiedComponentObject
.flatMap((component) =>
Object.keys(component)
.filter((key) => component[key] !== undefined && key !== 'attachmentValues')
.filter((key) => component[key] !== undefined)
.flatMap((key) => {
if (key === 'values' || key === 'data' || key === 'accordionValues') {
if (key === 'values' || key === 'data' || key === 'accordionValues' || key === 'attachmentValues') {
return component[key]
.filter((value) => value !== '')
.filter((value) => !!value)
.map((value) => textObject(withInputType, value)) as TextObjectType;
}
return textObject(withInputType, component[key]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AttachmentSettingValues } from '../attachment';
import type { Component, ComponentProperties, FormPropertiesType, NavFormType } from '../form';
import FormioUtils from '../utils/formio/FormioUtils';

Expand Down Expand Up @@ -70,38 +71,43 @@ const createDummyRadioPanel = (
navId,
}) as Component;

const defaultAttachmentValues: RadioPanelOption[] = [
{
value: 'leggerVedNaa',
label: 'Jeg legger det ved denne søknaden (anbefalt)',
},
{
value: 'ettersender',
label:
'Jeg ettersender dokumentasjonen senere (jeg er klar over at NAV ikke kan behandle søknaden før jeg har levert dokumentasjonen)',
},
{
value: 'levertTidligere',
label: 'Jeg har levert denne dokumentasjonen tidligere',
},
];
const defaultAttachmentValues: AttachmentSettingValues = {
leggerVedNaa: { enabled: true },
ettersender: { enabled: true },
levertTidligere: { enabled: true },
};

const defaultAttachmentProperties: ComponentProperties = {
vedleggstittel: 'Bekreftelse fra skole',
vedleggskode: 'S1',
};

const createDummyAttachmentValues = (
values: Array<{ key: keyof AttachmentSettingValues; label?: string; description?: string; showDeadline?: boolean }>,
): AttachmentSettingValues => {
return Object.fromEntries(
values.map(({ key, label, description, showDeadline }) => [
key,
{
enabled: true,
showDeadline,
...{ additionalDocumentation: label || description ? { enabled: true, label, description } : undefined },
},
]),
);
};

const createDummyAttachment = (
label = 'Vedlegg1',
properties: ComponentProperties = defaultAttachmentProperties,
values: RadioPanelOption[] = defaultAttachmentValues,
attachmentValues: AttachmentSettingValues = defaultAttachmentValues,
navId: string = createNavId(),
): Component =>
({
label,
key: keyFromLabel(label),
type: 'radiopanel',
values,
type: 'attachment',
attachmentValues,
properties,
navId,
}) as Component;
Expand Down Expand Up @@ -366,6 +372,7 @@ const mockedComponentObjectForTest = {
createDummyEmail,
createDummyRadioPanel,
createDummyAttachment,
createDummyAttachmentValues,
createDummyRadioPanelWithNumberValues,
createDummySelectboxes,
createDummyImage,
Expand Down