Skip to content

Commit

Permalink
Tests for getting texts from the new attachment component
Browse files Browse the repository at this point in the history
  • Loading branch information
magnurh-cx committed Jun 18, 2024
1 parent 9c400ec commit 40087ec
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 18 deletions.
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
43 changes: 25 additions & 18 deletions packages/shared-domain/src/summary/MockedComponentObjectForTest.ts
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

0 comments on commit 40087ec

Please sign in to comment.