From a7c60275ce56f39cab6c95c2b1c73a0faa3f26b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20R=C3=B8ed=20Hestvik?= Date: Mon, 17 Jun 2024 11:40:58 +0200 Subject: [PATCH 1/3] Include attachmentValues in getFormTexts --- packages/bygger/src/translations/utils.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/bygger/src/translations/utils.ts b/packages/bygger/src/translations/utils.ts index 5fbbe893d..2e6b993b5 100644 --- a/packages/bygger/src/translations/utils.ts +++ b/packages/bygger/src/translations/utils.ts @@ -205,11 +205,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]); From 9c400ec8030ceb8e205951740d75f33ab3520e1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20R=C3=B8ed=20Hestvik?= Date: Mon, 17 Jun 2024 12:30:28 +0200 Subject: [PATCH 2/3] Add global attachment option text --- packages/bygger/src/translations/utils.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/bygger/src/translations/utils.ts b/packages/bygger/src/translations/utils.ts index 2e6b993b5..de2a00ce1 100644 --- a/packages/bygger/src/translations/utils.ts +++ b/packages/bygger/src/translations/utils.ts @@ -17,6 +17,7 @@ import { NavFormType, navFormUtils, signatureUtils, + TEXTS, } from '@navikt/skjemadigitalisering-shared-domain'; type TextObjectType = { text: string; type?: InputType }; @@ -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]; }); }; From 40087ec9e8ac985d900cdffd74a78c28e45633f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20R=C3=B8ed=20Hestvik?= Date: Tue, 18 Jun 2024 14:50:52 +0200 Subject: [PATCH 3/3] Tests for getting texts from the new attachment component --- .../bygger/src/translations/utils.test.ts | 41 ++++++++++++++++++ .../summary/MockedComponentObjectForTest.ts | 43 +++++++++++-------- 2 files changed, 66 insertions(+), 18 deletions(-) diff --git a/packages/bygger/src/translations/utils.test.ts b/packages/bygger/src/translations/utils.test.ts index fe8c48f85..4f6f453a5 100644 --- a/packages/bygger/src/translations/utils.test.ts +++ b/packages/bygger/src/translations/utils.test.ts @@ -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, @@ -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( diff --git a/packages/shared-domain/src/summary/MockedComponentObjectForTest.ts b/packages/shared-domain/src/summary/MockedComponentObjectForTest.ts index 3e1baf444..f1e5f7cee 100644 --- a/packages/shared-domain/src/summary/MockedComponentObjectForTest.ts +++ b/packages/shared-domain/src/summary/MockedComponentObjectForTest.ts @@ -1,3 +1,4 @@ +import { AttachmentSettingValues } from '../attachment'; import type { Component, ComponentProperties, FormPropertiesType, NavFormType } from '../form'; import FormioUtils from '../utils/formio/FormioUtils'; @@ -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; @@ -366,6 +372,7 @@ const mockedComponentObjectForTest = { createDummyEmail, createDummyRadioPanel, createDummyAttachment, + createDummyAttachmentValues, createDummyRadioPanelWithNumberValues, createDummySelectboxes, createDummyImage,