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] 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,