Skip to content

Commit a1d0ea2

Browse files
authored
Merge pull request #979 from navikt/feature/remove-old-values-from-submission
Feature/remove old values from submission
2 parents 90fdb04 + 8af0aa2 commit a1d0ea2

File tree

13 files changed

+377
-28
lines changed

13 files changed

+377
-28
lines changed

mocks/mocks/data/formio-api/test-mellomlagring.json

+89
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,95 @@
11011101
"id": "e3vwglb",
11021102
"defaultValue": null,
11031103
"navId": "edqy1v"
1104+
},
1105+
{
1106+
"label": "Ønskeliste",
1107+
"key": "datagrid",
1108+
"input": false,
1109+
"tableView": false,
1110+
"validateOn": "blur",
1111+
"validate": {
1112+
"required": false,
1113+
"custom": "",
1114+
"customPrivate": false,
1115+
"strictDateValidation": false,
1116+
"multiple": false,
1117+
"unique": false
1118+
},
1119+
"type": "datagrid",
1120+
"isNavDataGrid": true,
1121+
"components": [
1122+
{
1123+
"validate": {
1124+
"required": false,
1125+
"custom": "",
1126+
"customPrivate": false,
1127+
"strictDateValidation": false,
1128+
"multiple": false,
1129+
"unique": false
1130+
},
1131+
"label": "Gaveønske",
1132+
"key": "tekstfelt",
1133+
"input": true,
1134+
"tableView": false,
1135+
"type": "textfield",
1136+
"navId": "e0tpgrm"
1137+
}
1138+
],
1139+
"navId": "e5z29dy",
1140+
"placeholder": "",
1141+
"prefix": "",
1142+
"customClass": "",
1143+
"suffix": "",
1144+
"multiple": false,
1145+
"defaultValue": null,
1146+
"protected": false,
1147+
"unique": false,
1148+
"persistent": true,
1149+
"hidden": false,
1150+
"clearOnHide": true,
1151+
"refreshOn": "",
1152+
"redrawOn": "",
1153+
"modalEdit": false,
1154+
"dataGridLabel": false,
1155+
"labelPosition": "top",
1156+
"description": "",
1157+
"errorLabel": "",
1158+
"tooltip": "",
1159+
"hideLabel": false,
1160+
"tabindex": "",
1161+
"disabled": false,
1162+
"autofocus": false,
1163+
"dbIndex": false,
1164+
"customDefaultValue": "",
1165+
"calculateValue": "",
1166+
"calculateServer": false,
1167+
"widget": null,
1168+
"attributes": {},
1169+
"conditional": {
1170+
"show": null,
1171+
"when": null,
1172+
"eq": ""
1173+
},
1174+
"overlay": {
1175+
"style": "",
1176+
"left": "",
1177+
"top": "",
1178+
"width": "",
1179+
"height": ""
1180+
},
1181+
"allowCalculateOverride": false,
1182+
"encrypted": false,
1183+
"showCharCount": false,
1184+
"showWordCount": false,
1185+
"properties": {},
1186+
"allowMultipleMasks": false,
1187+
"addons": [],
1188+
"tree": true,
1189+
"lazyLoad": false,
1190+
"disableAddingRemovingRows": false,
1191+
"id": "euimv9",
1192+
"keyModified": true
11041193
}
11051194
],
11061195
"placeholder": "",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"brukerId": "19876898104",
3+
"skjemanr": "testMellomlagring",
4+
"tittel": "Test mellomlagring",
5+
"tema": "BAR",
6+
"spraak": "nb",
7+
"hoveddokument": {
8+
"vedleggsnr": "testMellomlagring",
9+
"tittel": "Test mellomlagring",
10+
"label": "Test mellomlagring",
11+
"pakrevd": true,
12+
"beskrivelse": null,
13+
"mimetype": "application/pdf",
14+
"document": null,
15+
"propertyNavn": null,
16+
"formioId": null
17+
},
18+
"hoveddokumentVariant": {
19+
"vedleggsnr": "testMellomlagring",
20+
"tittel": "Test mellomlagring",
21+
"label": "Test mellomlagring",
22+
"pakrevd": false,
23+
"beskrivelse": null,
24+
"mimetype": "application/json",
25+
"document": {
26+
"language": "nb-NO",
27+
"data": {
28+
"data": {
29+
"hvaDrakkDuTilFrokost": "",
30+
"hvaSpisteDuTilFrokost": "",
31+
"hvaSyntesDuOmFrokosten": "Helt ok",
32+
"slettetTekstfelt": "Verdi som skal fjernes",
33+
"datagrid": [{"tekstfelt": "Hoppeslott", "tekstfelt1": "Grønn"}, {"tekstfelt": "Hund", "tekstfelt1": "Svart"}],
34+
"datagrid1": [{"tekstfelt": "Katt", "tekstfelt1": "Blå"}, {"tekstfelt": "Kanarifugl", "tekstfelt1": "Gul"}],
35+
"container.slettetTekstFelt": "Verdi fra container som skal fjernes",
36+
"onskerDuAFaGavenInnpakket": "nei",
37+
"hemmeligKode": "",
38+
"kryssAvHvisDuOnskerDagligReklamePaEPost": false,
39+
"hvordanOnskerDuAMottaPakken": {
40+
"label": "På døra",
41+
"value": "paDora"
42+
}
43+
}
44+
}
45+
},
46+
"propertyNavn": null,
47+
"formioId": null
48+
},
49+
"innsendingsId": "01234567-abcd-4ebd-90d4-34448ebaaaa2",
50+
"status": "Opprettet",
51+
"vedleggsListe": [],
52+
"kanLasteOppAnnet": true,
53+
"fristForEttersendelse": 14,
54+
"endretDato": "2023-08-30T12:33:30.399543+02:00"
55+
}

mocks/mocks/routes/innsending-api.js

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const responseWithInnsendingsId = require('../data/innsending-api/mellomlagring/responseWithInnsendingsId.json');
22
const mellomlagringValid1 = require('../data/innsending-api/mellomlagring/getTestMellomlagring-valid-1.json');
33
const mellomlagringValid2 = require('../data/innsending-api/mellomlagring/getTestMellomlagring-valid-2.json');
4+
const mellomlagringValidExtraValues = require('../data/innsending-api/mellomlagring/getTestMellomlagring-valid-extra-values.json');
45
const prefillDataNames = require('../data/innsending-api/prefill-data/prefill-data-names.json');
56

67
const paabegyntMellomlagringOgInnsendt = require('../data/innsending-api/active-tasks/mellomlagringOgEttersending.json');
@@ -162,6 +163,14 @@ module.exports = [
162163
body: convertToInnsendingApiResponse(mellomlagringValid2),
163164
},
164165
},
166+
{
167+
id: 'success-extra-values',
168+
type: 'json',
169+
options: {
170+
status: 200,
171+
body: convertToInnsendingApiResponse(mellomlagringValidExtraValues),
172+
},
173+
},
165174
{
166175
id: 'success-prefill-data',
167176
type: 'json',

packages/bygger/src/Forms/publish/PublishModalComponents.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { ConfirmationModal, useModal } from '@navikt/skjemadigitalisering-shared-components';
2-
import { navFormUtils } from '@navikt/skjemadigitalisering-shared-domain';
2+
import { NavFormType, navFormUtils } from '@navikt/skjemadigitalisering-shared-domain';
33
import { useEffect, useState } from 'react';
44
import ConfirmPublishModal from './ConfirmPublishModal';
55
import PublishSettingsModal from './PublishSettingsModal';
66

7-
const validateAttachments = (form) =>
7+
const validateAttachments = (form: NavFormType) =>
88
navFormUtils
99
.flattenComponents(form.components)
1010
.filter(navFormUtils.isAttachment)

packages/fyllut/cypress/e2e/mellomlagring.cy.ts

+29-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ describe('Mellomlagring', () => {
194194
cy.intercept('PUT', '/fyllut/api/send-inn/utfyltsoknad', (req) => {
195195
const { submission: bodySubmission, ...bodyRest } = req.body;
196196
const { submission: fixtureSubmission, ...fixtureRest } = fixture;
197-
expect(bodySubmission.data).to.deep.contain(fixtureSubmission.data);
197+
expect(bodySubmission.data).to.deep.eq(fixtureSubmission.data);
198198
expect(bodyRest).to.deep.eq(fixtureRest);
199199
}).as('submitMellomlagring');
200200
});
@@ -303,6 +303,34 @@ describe('Mellomlagring', () => {
303303
cy.findByText(TEXTS.statiske.mellomlagringError.update.message).should('be.visible');
304304
});
305305
});
306+
307+
describe('When stored submission contains values for inputs that have been removed from the form', () => {
308+
beforeEach(() => {
309+
cy.mocksUseRouteVariant('get-soknad:success-extra-values');
310+
cy.intercept('PUT', '/fyllut/api/send-inn/utfyltsoknad', (req) => {
311+
const { submission } = req.body;
312+
expect(submission.data['slettetTekstfelt']).to.be.undefined;
313+
// Container
314+
expect(submission.data['container.slettetTekstFelt']).to.be.undefined;
315+
// Datagrid
316+
expect(submission.data['datagrid']).to.deep.eq([{ tekstfelt: 'Hoppeslott' }, { tekstfelt: 'Hund' }]);
317+
expect(submission.data['datagrid1']).to.be.undefined;
318+
// value should be removed if the corresponding field is conditionally hidden
319+
expect(submission.data['hvaSyntesDuOmFrokosten']).to.be.undefined;
320+
}).as('submitMellomlagring');
321+
});
322+
323+
it('removes the unused values from submission before submitting', () => {
324+
cy.visit(
325+
'/fyllut/testmellomlagring/oppsummering?sub=digital&innsendingsId=8e3c3621-76d7-4ebd-90d4-34448ebcccc3&lang=nb-NO',
326+
);
327+
cy.wait('@getMellomlagringValid');
328+
cy.findByRole('heading', { name: TEXTS.statiske.summaryPage.title }).should('exist');
329+
cy.findByText('Ønsker du å få gaven innpakket').should('exist');
330+
cy.findByRole('button', { name: TEXTS.grensesnitt.navigation.saveAndContinue }).click();
331+
cy.wait('@submitMellomlagring');
332+
});
333+
});
306334
});
307335
});
308336
});

packages/fyllut/cypress/fixtures/mellomlagring/submitTestMellomlagring.json

+89-4
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,95 @@
11031103
"id": "e3vwglb",
11041104
"defaultValue": null,
11051105
"navId": "edqy1v"
1106+
},
1107+
{
1108+
"label": "Ønskeliste",
1109+
"key": "datagrid",
1110+
"input": false,
1111+
"tableView": false,
1112+
"validateOn": "blur",
1113+
"validate": {
1114+
"required": false,
1115+
"custom": "",
1116+
"customPrivate": false,
1117+
"strictDateValidation": false,
1118+
"multiple": false,
1119+
"unique": false
1120+
},
1121+
"type": "datagrid",
1122+
"isNavDataGrid": true,
1123+
"components": [
1124+
{
1125+
"validate": {
1126+
"required": false,
1127+
"custom": "",
1128+
"customPrivate": false,
1129+
"strictDateValidation": false,
1130+
"multiple": false,
1131+
"unique": false
1132+
},
1133+
"label": "Gaveønske",
1134+
"key": "tekstfelt",
1135+
"input": true,
1136+
"tableView": false,
1137+
"type": "textfield",
1138+
"navId": "e0tpgrm"
1139+
}
1140+
],
1141+
"navId": "e5z29dy",
1142+
"placeholder": "",
1143+
"prefix": "",
1144+
"customClass": "",
1145+
"suffix": "",
1146+
"multiple": false,
1147+
"defaultValue": null,
1148+
"protected": false,
1149+
"unique": false,
1150+
"persistent": true,
1151+
"hidden": false,
1152+
"clearOnHide": true,
1153+
"refreshOn": "",
1154+
"redrawOn": "",
1155+
"modalEdit": false,
1156+
"dataGridLabel": false,
1157+
"labelPosition": "top",
1158+
"description": "",
1159+
"errorLabel": "",
1160+
"tooltip": "",
1161+
"hideLabel": false,
1162+
"tabindex": "",
1163+
"disabled": false,
1164+
"autofocus": false,
1165+
"dbIndex": false,
1166+
"customDefaultValue": "",
1167+
"calculateValue": "",
1168+
"calculateServer": false,
1169+
"widget": null,
1170+
"attributes": {},
1171+
"conditional": {
1172+
"show": null,
1173+
"when": null,
1174+
"eq": ""
1175+
},
1176+
"overlay": {
1177+
"style": "",
1178+
"left": "",
1179+
"top": "",
1180+
"width": "",
1181+
"height": ""
1182+
},
1183+
"allowCalculateOverride": false,
1184+
"encrypted": false,
1185+
"showCharCount": false,
1186+
"showWordCount": false,
1187+
"properties": {},
1188+
"allowMultipleMasks": false,
1189+
"addons": [],
1190+
"tree": true,
1191+
"lazyLoad": false,
1192+
"disableAddingRemovingRows": false,
1193+
"id": "euimv9",
1194+
"keyModified": true
11061195
}
11071196
],
11081197
"placeholder": "",
@@ -1862,11 +1951,7 @@
18621951
},
18631952
"submission": {
18641953
"data": {
1865-
"hvaDrakkDuTilFrokost": "",
1866-
"hvaSpisteDuTilFrokost": "",
18671954
"onskerDuAFaGavenInnpakket": "nei",
1868-
"hemmeligKode": "",
1869-
"kryssAvHvisDuOnskerDagligReklamePaEPost": false,
18701955
"hvordanOnskerDuAMottaPakken": {
18711956
"label": "På døra",
18721957
"value": "paDora"

packages/shared-components/src/context/sendInn/sendInnContext.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ const SendInnProvider = ({
105105
const response = await getSoknad(innsendingsId, appConfig);
106106
if (response?.hoveddokumentVariant.document) {
107107
addSearchParamToUrl('lang', response.hoveddokumentVariant.document.language);
108-
updateSubmission(getSubmissionWithFyllutState(response));
108+
updateSubmission(getSubmissionWithFyllutState(response, form));
109109
dispatchFyllutMellomlagring({ type: 'init', response });
110110
}
111111
};

0 commit comments

Comments
 (0)