@ukhomeoffice/cop-react-form-renderer 6.15.11-alpha → 6.15.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/components/FormComponent/FormComponent.js +6 -0
  2. package/dist/components/FormComponent/helpers/addLabel.js +3 -2
  3. package/dist/components/FormPage/FormPage.js +20 -7
  4. package/dist/components/FormPage/FormPage.test.js +53 -0
  5. package/dist/components/FormRenderer/FormRenderer.js +8 -3
  6. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/cop-reassign-task-to-rcc.json +446 -0
  7. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-chained-component-show-whens-containerised.json +1 -0
  8. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-chained-component-show-whens-dependent-component-nested-block.json +1 -0
  9. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-chained-component-show-whens-dependent-component-nested.json +1 -0
  10. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-chained-component-show-whens-refdata.json +1 -0
  11. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-chained-component-show-whens-target-component-nested.json +1 -0
  12. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-chained-component-show-whens.json +1 -0
  13. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-chained-show-whens-page-hidden.json +1 -0
  14. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-cop-airpax.json +1 -0
  15. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-cop-mandec.json +1 -0
  16. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-hidden-collection-component-dependent-on-external-data.json +1 -0
  17. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-hidden-collection-component.json +1 -0
  18. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-hidden-component-referring-to-collection.json +1 -0
  19. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-hidden-component-referring-to-hidden-collection.json +1 -0
  20. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-hidden-component-show-when-in-component-and-page.json +1 -0
  21. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-hidden-component-with-nested-questions.json +1 -0
  22. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-hidden-component.json +1 -0
  23. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-hidden-containerised-component.json +1 -0
  24. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-hidden-embedded-collection-component.json +1 -0
  25. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-hidden-embedded-component.json +1 -0
  26. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-hidden-multilevel-containerised-component-leaf-hidden.json +1 -0
  27. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-hidden-multilevel-containerised-component.json +1 -0
  28. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-hidden-options.json +1 -0
  29. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-hidden-page-collection.json +1 -0
  30. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-hidden-page-component-used-elsewhere.json +1 -0
  31. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-hidden-page-same-component-reused.json +1 -0
  32. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-hidden-page.json +1 -0
  33. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-nested-answers-hidden-by-option.json +1 -0
  34. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-page-nested-radio-component.json +201 -0
  35. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-page-same-component-reused-one-shown.json +1 -0
  36. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-variance-breach.json +4272 -0
  37. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/input/cop-airpax-carrier.json +407 -0
  38. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/input/cop-variance-breach-with-upload-files.json +1264 -0
  39. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/input/data-page-nested-radio-component.json +45 -0
  40. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/input/reassign-to-rcc.json +72 -0
  41. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/output/data-page-nested-radio-component-removed.json +45 -0
  42. package/dist/components/FormRenderer/helpers/clearOutUncompletedRoutes.js +32 -18
  43. package/dist/components/FormRenderer/helpers/clearOutUncompletedRoutes.test.js +73 -31
  44. package/dist/components/FormRenderer/helpers/clearOutUncompletedRoutesUtils.js +15 -7
  45. package/dist/components/FormRenderer/onCYAAction.js +3 -3
  46. package/dist/components/FormRenderer/onCYAAction.test.js +2 -1
  47. package/dist/components/FormRenderer/onPageAction.js +2 -2
  48. package/dist/components/FormRenderer/onPageAction.test.js +2 -1
  49. package/dist/utils/Component/getComponentTests/getComponent.multifile.test.js +2 -1
  50. package/package.json +5 -4
@@ -0,0 +1,45 @@
1
+ {
2
+ "id": "8d4674c4-1adb-11f0-a7ba-620783054865",
3
+ "businessKey": "DEV-20250416-1142",
4
+ "port": {
5
+ "id": 1639,
6
+ "name": "Dover",
7
+ "sea": true,
8
+ "air": false,
9
+ "land": false,
10
+ "rail": false,
11
+ "countryid": 234,
12
+ "iata": null,
13
+ "value": "1639",
14
+ "label": "Dover",
15
+ "hint": ""
16
+ },
17
+ "modeOfTransport": {
18
+ "id": 9,
19
+ "mode": "RoRo Tourist",
20
+ "modecode": "rorotour",
21
+ "crossingtype": [
22
+ "sea"
23
+ ],
24
+ "value": "RoRo Tourist",
25
+ "label": "RoRo Tourist"
26
+ },
27
+ "whatHappened": "peopleHidingVehicle",
28
+ "formInstanceId": "5b3b4c37-df21-4e61-bffe-3034c55d4429",
29
+ "driverOwnVehicle": "noSomeoneElseOwns",
30
+ "otherVehicleOwner": {
31
+ "vehicleOwnerAddress": "no",
32
+ "fullName": "Robert Flecher",
33
+ "telephoneNumber": "07835442994",
34
+ "emailAddress": "robrotheram@gmail.com",
35
+ "nonUkAddressText": "Dickinson St",
36
+ "country": {
37
+ "id": 211,
38
+ "name": "Sudan (the)",
39
+ "iso31661alpha3": "SDN",
40
+ "value": "211",
41
+ "label": "Sudan (the)",
42
+ "hint": ""
43
+ }
44
+ }
45
+ }
@@ -0,0 +1,72 @@
1
+ {
2
+ "businessKey": "SIT-20250312-1016",
3
+ "definitionKey": "cop-ncc-task-form",
4
+ "port": {
5
+ "fixedpcp": null,
6
+ "updatedby": "Michaela Cook",
7
+ "geolong": "-3.3391",
8
+ "municipality": null,
9
+ "nonoperational": false,
10
+ "air": true,
11
+ "commandid": 22,
12
+ "juxtaposed": false,
13
+ "sea": false,
14
+ "subdivision": "NA",
15
+ "land": false,
16
+ "id": 9937,
17
+ "helipad": false,
18
+ "value": "9937",
19
+ "portablepcp": null,
20
+ "unlocode": null,
21
+ "rail": false,
22
+ "geolat": "51.39859",
23
+ "localcode": null,
24
+ "label": "Cardiff International Airport",
25
+ "countryid": 234,
26
+ "addressid": null,
27
+ "egates": null,
28
+ "iata": "CWL",
29
+ "locationid": null,
30
+ "hint": "",
31
+ "name": "Cardiff International Airport",
32
+ "icao": "EGFF",
33
+ "portsizeid": 1,
34
+ "validfrom": "2025-03-04T00:01:01.000Z",
35
+ "freightparcelposthub": false,
36
+ "validto": null
37
+ },
38
+ "terminal": null,
39
+ "leadOfficerEmail": null,
40
+ "officerEmails": null,
41
+ "regionalCommandCentre": {
42
+ "code": "BFCENT",
43
+ "updatedby": null,
44
+ "directorateid": 2,
45
+ "hint": "",
46
+ "name": "Central",
47
+ "validfrom": "2019-01-01T00:01:00.000Z",
48
+ "id": 23,
49
+ "label": "Central",
50
+ "value": "23",
51
+ "validto": null
52
+ },
53
+ "autoClose": "13 March 2025",
54
+ "assignWhere": "RCC",
55
+ "assignMessage": "test message",
56
+ "formStatus": {
57
+ "page": "cya"
58
+ },
59
+ "formInstanceId": "46d1b27d-5a6e-428b-a20e-4a432e37875f",
60
+ "form": {
61
+ "formVersionId": "7b941ec0bb281e2b93ba32058b81e1a88f0f0a9a",
62
+ "title": "Assign task to RCC",
63
+ "name": "cop-reassign-task-to-rcc",
64
+ "submissionDate": "2025-03-12T15:41:08.880Z",
65
+ "submittedBy": "acceptance.portuser1@system.local",
66
+ "submittingUsersName": "acceptance.portuser1",
67
+ "draftForm": true,
68
+ "submissionStartDate": "2025-03-12T15:41:08.880Z",
69
+ "formInstanceId": "46d1b27d-5a6e-428b-a20e-4a432e37875f",
70
+ "submissionTeam": "96e2d9db-8b3f-4b36-9ec3-eb1b7506d8c2"
71
+ }
72
+ }
@@ -0,0 +1,45 @@
1
+ {
2
+ "id": "8d4674c4-1adb-11f0-a7ba-620783054865",
3
+ "businessKey": "DEV-20250416-1142",
4
+ "port": {
5
+ "id": 1639,
6
+ "name": "Dover",
7
+ "sea": true,
8
+ "air": false,
9
+ "land": false,
10
+ "rail": false,
11
+ "countryid": 234,
12
+ "iata": null,
13
+ "value": "1639",
14
+ "label": "Dover",
15
+ "hint": ""
16
+ },
17
+ "modeOfTransport": {
18
+ "id": 9,
19
+ "mode": "RoRo Tourist",
20
+ "modecode": "rorotour",
21
+ "crossingtype": [
22
+ "sea"
23
+ ],
24
+ "value": "RoRo Tourist",
25
+ "label": "RoRo Tourist"
26
+ },
27
+ "whatHappened": "peopleHidingVehicle",
28
+ "formInstanceId": "5b3b4c37-df21-4e61-bffe-3034c55d4429",
29
+ "driverOwnVehicle": "noSomeoneElseOwns",
30
+ "otherVehicleOwner": {
31
+ "vehicleOwnerAddress": "no",
32
+ "fullName": "Robert Flecher",
33
+ "telephoneNumber": "07835442994",
34
+ "emailAddress": "robrotheram@gmail.com",
35
+ "nonUkAddressText": "Dickinson St",
36
+ "country": {
37
+ "id": 211,
38
+ "name": "Sudan (the)",
39
+ "iso31661alpha3": "SDN",
40
+ "value": "211",
41
+ "label": "Sudan (the)",
42
+ "hint": ""
43
+ }
44
+ }
45
+ }
@@ -7,6 +7,7 @@ exports.default = void 0;
7
7
  var _mergeCollectionPages = _interopRequireDefault(require("../../../utils/CollectionPage/mergeCollectionPages"));
8
8
  var Utils = _interopRequireWildcard(require("./clearOutUncompletedRoutesUtils"));
9
9
  var _optionIsSelected = _interopRequireDefault(require("../../../utils/Component/optionIsSelected"));
10
+ var _getSourceData = _interopRequireDefault(require("../../../utils/Data/getSourceData"));
10
11
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
11
12
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
12
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -30,15 +31,19 @@ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e =
30
31
  * once with the same path).
31
32
  *
32
33
  * @param {Array} condensedPages All pages in the form, with the collection pages collated into a single object per collection
33
- * @param {Map} allCollections A map of collection objects, which are a grouping of the pages that make up a single collection
34
34
  * @param {Object} formData The form payload
35
35
  * @param {Map} componentByIdMap Map of all components, to enable performant lookup by id
36
36
  * @param {Map} componentByFieldIdMap Map of all components, to enable performant lookup by fieldId
37
- * @param {Map} allComponents All components in form (including nested), keyed by path
38
- * @param {Object} componentsToKeep A count of how many times each component is used, to prevent us deleting components defined > 1 times
39
- * @return allComponents and componentsToKeep updated in place
37
+ * @param {Object}
38
+ * @return {Map, Object, Map} allComponents All components in form (including nested), keyed by path:
39
+ * componentsToKeep A count of how many times each component is used, to prevent us deleting components defined > 1 times
40
+ * allCollections A map of collection objects, which are a grouping of the pages that make up a single collection
40
41
  */
41
- const createComponentMapsFromForm = (condensedPages, allCollections, componentByIdMap, componentByFieldIdMap, allComponents, componentsToKeep, formData) => {
42
+ const createComponentMapsFromForm = (condensedPages, componentByIdMap, componentByFieldIdMap, formData) => {
43
+ const allComponents = new Map();
44
+ const componentsToKeep = {};
45
+ const allCollections = new Map();
46
+
42
47
  /*
43
48
  * Inner function to support the recursion required to traverse through the nested structures of the form
44
49
  */
@@ -63,7 +68,8 @@ const createComponentMapsFromForm = (condensedPages, allCollections, componentBy
63
68
  var _component$data2;
64
69
  component === null || component === void 0 || (_component$data2 = component.data) === null || _component$data2 === void 0 || (_component$data2 = _component$data2.options) === null || _component$data2 === void 0 || _component$data2.forEach(option => {
65
70
  if (option.nested) {
66
- if (!(0, _optionIsSelected.default)(formData[component.id], option)) {
71
+ // in container need to use the JPath for the data since the field that the component is looking at is nested in the container.
72
+ if (!(0, _optionIsSelected.default)((0, _getSourceData.default)(formData, path), option)) {
67
73
  option.nested.forEach(nestedComponent => {
68
74
  // delete hidden nested question payload items when the parent option is not selected
69
75
  Utils.deleteNodeByPath(formData, Utils.getNestedQuestionPath(path, nestedComponent.fieldId));
@@ -80,6 +86,7 @@ const createComponentMapsFromForm = (condensedPages, allCollections, componentBy
80
86
  });
81
87
  }
82
88
  };
89
+
83
90
  // Entry point for the recursive traverse of the form specification.
84
91
  condensedPages === null || condensedPages === void 0 || condensedPages.forEach(page => {
85
92
  // Make the distinction between collections (which will be processed separately) and non-collections, which will be processed here.
@@ -89,10 +96,15 @@ const createComponentMapsFromForm = (condensedPages, allCollections, componentBy
89
96
  var _page$components;
90
97
  (_page$components = page.components) === null || _page$components === void 0 || _page$components.forEach(useComponentInPage => {
91
98
  const componentObj = Utils.findComponentDefinitionInForm(useComponentInPage, componentByIdMap, componentByFieldIdMap);
92
- recursivelyMapFieldsAndDeleteHiddenNested(page, componentObj, null);
99
+ recursivelyMapFieldsAndDeleteHiddenNested(page, componentObj, null, allComponents, componentsToKeep, formData);
93
100
  });
94
101
  }
95
102
  });
103
+ return {
104
+ allComponents,
105
+ componentsToKeep,
106
+ allCollections
107
+ };
96
108
  };
97
109
  /**
98
110
  *
@@ -102,9 +114,10 @@ const createComponentMapsFromForm = (condensedPages, allCollections, componentBy
102
114
  *
103
115
  * @param {Map} allDependencyRelationships A map of each component with dependencies. The key is the fully qualified path and the value is a Set of all the paths that this component is dependent on.
104
116
  * @param {Map} allComponents All components in form (including nested), keyed by path. Used to build the allDependencyRelationships
105
- * @return allDependencyRelationships updated in place
117
+ * @return {Map }allDependencyRelationships graph of the relationships between all entities
106
118
  */
107
- const createComponentDependenciesGraph = (allComponents, allDependencyRelationships) => {
119
+ const createComponentDependenciesGraph = allComponents => {
120
+ const allDependencyRelationships = new Map();
108
121
  allComponents === null || allComponents === void 0 || allComponents.forEach(componentArray => {
109
122
  componentArray === null || componentArray === void 0 || componentArray.forEach(component => {
110
123
  if (!component.fieldId) return;
@@ -119,6 +132,7 @@ const createComponentDependenciesGraph = (allComponents, allDependencyRelationsh
119
132
  }
120
133
  });
121
134
  });
135
+ return allDependencyRelationships;
122
136
  };
123
137
 
124
138
  /**
@@ -287,22 +301,22 @@ const cleanseCollectionData = (allCollections, formData, componentByIdMap, compo
287
301
  * @param {*} formData
288
302
  * @returns {*} cleansed form data
289
303
  */
290
- const clearOutUncompletedRoutes = (form, formData) => {
304
+ const clearOutUncompletedRoutes = (cleanseHiddenData, form, formData) => {
305
+ if (!cleanseHiddenData) return formData;
306
+
291
307
  // Load components into maps keyed on id and field for subsequent performant access
292
308
  const componentByIdMap = new Map(form.components.map(c => [c.id, c]));
293
309
  const componentByFieldIdMap = new Map(form.components.map(c => [c.fieldId, c]));
294
310
 
295
- // Instantiate data structures to hold the form specification and the dependency graph
296
- const allComponents = new Map();
297
- const componentsToKeep = {};
298
- const allCollections = new Map();
299
- const allDependencyRelationships = new Map();
300
-
301
311
  // Group all pages relating to a page-collection into a single object to aid collection
302
312
  // processing, and to allow us to differentiate between a collection and non-collection page.
303
313
  const condensedPages = (0, _mergeCollectionPages.default)(form.pages);
304
- createComponentMapsFromForm(condensedPages, allCollections, componentByIdMap, componentByFieldIdMap, allComponents, componentsToKeep, formData);
305
- createComponentDependenciesGraph(allComponents, allDependencyRelationships);
314
+ const {
315
+ allComponents,
316
+ componentsToKeep,
317
+ allCollections
318
+ } = createComponentMapsFromForm(condensedPages, componentByIdMap, componentByFieldIdMap, formData);
319
+ const allDependencyRelationships = createComponentDependenciesGraph(allComponents);
306
320
  resolveComponentDependenciesGraph(allDependencyRelationships, allComponents, componentsToKeep, allCollections, form, formData);
307
321
  cleanseCollectionData(allCollections, formData, componentByIdMap, componentByFieldIdMap);
308
322
 
@@ -85,11 +85,19 @@ var _copMandecRemoveCriminalityBefore = _interopRequireDefault(require("../clear
85
85
  var _copMandecRemoveCriminalityAfter = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/output/cop-mandec-remove-criminality-after.json"));
86
86
  var _copMandecRemoveUnspentConvictionsBefore = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/input/cop-mandec-remove-unspent-convictions-before.json"));
87
87
  var _copMandecRemoveUnspentConvictionsAfter = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/output/cop-mandec-remove-unspent-convictions-after.json"));
88
+ var _copReassignTaskToRcc = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/forms/cop-reassign-task-to-rcc.json"));
89
+ var _reassignToRcc = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/input/reassign-to-rcc.json"));
88
90
  var _formCopAirpax = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/forms/form-cop-airpax.json"));
89
91
  var _copAirpaxRemovePhotosBefore = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/input/cop-airpax-remove-photos-before.json"));
90
92
  var _copAirpaxRemovePhotosAfter = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/output/cop-airpax-remove-photos-after.json"));
91
93
  var _copAirpaxChangeWhatHappenedBefore = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/input/cop-airpax-change-what-happened-before.json"));
92
94
  var _copAirpaxChangeWhatHappenedAfter = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/output/cop-airpax-change-what-happened-after.json"));
95
+ var _copAirpaxCarrier = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/input/cop-airpax-carrier.json"));
96
+ var _formPageNestedRadioComponent = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/forms/form-page-nested-radio-component.json"));
97
+ var _dataPageNestedRadioComponent = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/input/data-page-nested-radio-component.json"));
98
+ var _dataPageNestedRadioComponentRemoved = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/output/data-page-nested-radio-component-removed.json"));
99
+ var _formVarianceBreach = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/forms/form-variance-breach.json"));
100
+ var _copVarianceBreachWithUploadFiles = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/input/cop-variance-breach-with-upload-files.json"));
93
101
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
94
102
  // Hidden component
95
103
 
@@ -149,112 +157,128 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
149
157
 
150
158
  // Mandec Unspent convictions
151
159
 
160
+ // TMS reassign-task-to-rcc
161
+
152
162
  // Airpax photos
153
163
 
164
+ // Who decided
165
+
166
+ // Carrier not removed
167
+
168
+ // Form with no componets but componet listed in page.
169
+
170
+ // Upload files not removed from variance breach on in-flight forms with no 'cleanseHiddenData' flag.
171
+
154
172
  describe('FormRenderer', () => {
155
173
  describe('helpers', () => {
156
174
  describe('clearOutUncompletedRoutes', () => {
175
+ it('should not remove upload files from variance breach.', () => {
176
+ const submissionData = JSON.parse(JSON.stringify(_copVarianceBreachWithUploadFiles.default));
177
+ const form = JSON.parse(JSON.stringify(_formVarianceBreach.default));
178
+ const result = _index.default.clearOutUncompletedRoutes(false, form, submissionData);
179
+ expect(result).toEqual(_copVarianceBreachWithUploadFiles.default);
180
+ });
157
181
  it('should remove hidden component.', () => {
158
182
  const submissionData = JSON.parse(JSON.stringify(_dataHiddenComponent.default));
159
183
  const form = JSON.parse(JSON.stringify(_formHiddenComponent.default));
160
- const result = _index.default.clearOutUncompletedRoutes(form, submissionData);
184
+ const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
161
185
  expect(result).toEqual(_dataHiddenComponentRemoved.default);
162
186
  });
163
187
  it('should remove hidden component with show_when in page and component.', () => {
164
188
  const submissionData = JSON.parse(JSON.stringify(_dataHiddenComponentShowWhenInComponentAndPage.default));
165
189
  const form = JSON.parse(JSON.stringify(_formHiddenComponentShowWhenInComponentAndPage.default));
166
- const result = _index.default.clearOutUncompletedRoutes(form, submissionData);
190
+ const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
167
191
  expect(result).toEqual(_dataHiddenComponentShowWhenInComponentAndPageRemoved.default);
168
192
  });
169
193
  it('should remove hidden component embedded in page.', () => {
170
194
  const submissionData = JSON.parse(JSON.stringify(_dataHiddenEmbeddedComponent.default));
171
195
  const form = JSON.parse(JSON.stringify(_formHiddenEmbeddedComponent.default));
172
- const result = _index.default.clearOutUncompletedRoutes(form, submissionData);
196
+ const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
173
197
  expect(result).toEqual(_dataHiddenEmbeddedComponentRemoved.default);
174
198
  });
175
199
  it('should remove hidden collection component.', () => {
176
200
  const submissionData = JSON.parse(JSON.stringify(_dataHiddenCollectionComponent.default));
177
201
  const form = JSON.parse(JSON.stringify(_formHiddenCollectionComponent.default));
178
- const result = _index.default.clearOutUncompletedRoutes(form, submissionData);
202
+ const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
179
203
  expect(result).toEqual(_dataHiddenCollectionComponentRemoved.default);
180
204
  });
181
205
  it('should remove hidden embedded collection component.', () => {
182
206
  const submissionData = JSON.parse(JSON.stringify(_dataHiddenEmbeddedCollectionComponent.default));
183
207
  const form = JSON.parse(JSON.stringify(_formHiddenEmbeddedCollectionComponent.default));
184
- const result = _index.default.clearOutUncompletedRoutes(form, submissionData);
208
+ const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
185
209
  expect(result).toEqual(_dataHiddenEmbeddedCollectionComponentRemoved.default);
186
210
  });
187
211
  it('should remove hidden containerised component.', () => {
188
212
  const submissionData = JSON.parse(JSON.stringify(_dataHiddenContainerisedComponent.default));
189
213
  const form = JSON.parse(JSON.stringify(_formHiddenContainerisedComponent.default));
190
- const result = _index.default.clearOutUncompletedRoutes(form, submissionData);
214
+ const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
191
215
  expect(result).toEqual(_dataHiddenContainerisedComponentRemoved.default);
192
216
  });
193
217
  it('should remove hidden multi-level containerised components.', () => {
194
218
  const submissionData = JSON.parse(JSON.stringify(_dataHiddenMultilevelContainerisedComponent.default));
195
219
  const form = JSON.parse(JSON.stringify(_formHiddenMultilevelContainerisedComponent.default));
196
- const result = _index.default.clearOutUncompletedRoutes(form, submissionData);
220
+ const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
197
221
  expect(result).toEqual(_dataHiddenMultilevelContainerisedComponentRemoved.default);
198
222
  });
199
223
  it('should remove hidden leaf-level in a multi-level containerised component.', () => {
200
224
  const submissionData = JSON.parse(JSON.stringify(_dataHiddenMultilevelContainerisedComponentLeafHidden.default));
201
225
  const form = JSON.parse(JSON.stringify(_formHiddenMultilevelContainerisedComponentLeafHidden.default));
202
- const result = _index.default.clearOutUncompletedRoutes(form, submissionData);
226
+ const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
203
227
  expect(result).toEqual(_dataHiddenMultilevelContainerisedComponentLeafHiddenRemoved.default);
204
228
  });
205
229
  it('should remove hidden component with options.', () => {
206
230
  const submissionData = JSON.parse(JSON.stringify(_dataHiddenOptions.default));
207
231
  const form = JSON.parse(JSON.stringify(_formHiddenOptions.default));
208
- const result = _index.default.clearOutUncompletedRoutes(form, submissionData);
232
+ const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
209
233
  expect(result).toEqual(_dataHiddenOptionsRemoved.default);
210
234
  });
211
235
  it('should remove hidden component with nested questions in options.', () => {
212
236
  const submissionData = JSON.parse(JSON.stringify(_dataHiddenComponentWithNestedQuestions.default));
213
237
  const form = JSON.parse(JSON.stringify(_formHiddenComponentWithNestedQuestions.default));
214
- const result = _index.default.clearOutUncompletedRoutes(form, submissionData);
238
+ const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
215
239
  expect(result).toEqual(_dataHiddenComponentWithNestedQuestionsRemoved.default);
216
240
  });
217
241
  it('should remove answers associated with unselected options in a containerised component.', () => {
218
242
  const submissionData = JSON.parse(JSON.stringify(_dataNestedAnswersHiddenByOption.default));
219
243
  const form = JSON.parse(JSON.stringify(_formNestedAnswersHiddenByOption.default));
220
- const result = _index.default.clearOutUncompletedRoutes(form, submissionData);
244
+ const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
221
245
  expect(result).toEqual(_dataNestedAnswersHiddenByOptionRemoved.default);
222
246
  });
223
247
  it('should remove hidden page.', () => {
224
248
  const submissionData = JSON.parse(JSON.stringify(_dataHiddenPage.default));
225
249
  const form = JSON.parse(JSON.stringify(_formHiddenPage.default));
226
- const result = _index.default.clearOutUncompletedRoutes(form, submissionData);
250
+ const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
227
251
  expect(result).toEqual(_dataHiddenPageRemoved.default);
228
252
  });
229
253
  it('should remove hidden page with same component reused.', () => {
230
254
  const submissionData = JSON.parse(JSON.stringify(_dataHiddenPageSameComponentReused.default));
231
255
  const form = JSON.parse(JSON.stringify(_formHiddenPageSameComponentReused.default));
232
- const result = _index.default.clearOutUncompletedRoutes(form, submissionData);
256
+ const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
233
257
  expect(result).toEqual(_dataHiddenPageSameComponentReusedRemoved.default);
234
258
  });
235
259
  it('should show component when reused but only one show_when true.', () => {
236
260
  const submissionData = JSON.parse(JSON.stringify(_dataPageSameComponentReusedOneShown.default));
237
261
  const form = JSON.parse(JSON.stringify(_formPageSameComponentReusedOneShown.default));
238
- const result = _index.default.clearOutUncompletedRoutes(form, submissionData);
262
+ const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
239
263
  expect(result).toEqual(_dataPageSameComponentReusedOneShownRemoved.default);
240
264
  });
241
265
  it('should remove a hidden collection on a page.', () => {
242
266
  const submissionData = JSON.parse(JSON.stringify(_dataHiddenPageCollection.default));
243
267
  const form = JSON.parse(JSON.stringify(_formHiddenPageCollection.default));
244
- const result = _index.default.clearOutUncompletedRoutes(form, submissionData);
268
+ const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
245
269
  expect(result).toEqual(_dataHiddenPageCollectionRemoved.default);
246
270
  });
247
271
  it('hidden component with show_when rule referring to a collection.', () => {
248
272
  const submissionData = JSON.parse(JSON.stringify(_dataHiddenComponentReferringToCollection.default));
249
273
  const form = JSON.parse(JSON.stringify(_formHiddenComponentReferringToCollection.default));
250
- const result = _index.default.clearOutUncompletedRoutes(form, submissionData);
274
+ const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
251
275
  expect(result).toEqual(_dataHiddenComponentReferringToCollectionRemoved.default);
252
276
  });
253
277
  it('hidden component with show_when rule referring to a hidden collection.', () => {
254
278
  const submissionData = JSON.parse(JSON.stringify(_dataHiddenComponentReferringToHiddenCollection.default));
255
279
  const form = JSON.parse(JSON.stringify(_formHiddenComponentReferringToHiddenCollection.default));
256
280
  try {
257
- _index.default.clearOutUncompletedRoutes(form, submissionData);
281
+ _index.default.clearOutUncompletedRoutes(true, form, submissionData);
258
282
  throw new Error('Expected myFunction to throw an error, but it did not');
259
283
  } catch (error) {
260
284
  expect(error.message).toContain('It is not possible to reliably clean hidden data when a component is dependent');
@@ -263,87 +287,105 @@ describe('FormRenderer', () => {
263
287
  it('should remove hidden collection components whether they are dependent on data inside or outside the collection.', () => {
264
288
  const submissionData = JSON.parse(JSON.stringify(_dataHiddenCollectionComponentDependentOnExternalData.default));
265
289
  const form = JSON.parse(JSON.stringify(_formHiddenCollectionComponentDependentOnExternalData.default));
266
- const result = _index.default.clearOutUncompletedRoutes(form, submissionData);
290
+ const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
267
291
  expect(result).toEqual(_dataHiddenCollectionComponentDependentOnExternalDataRemoved.default);
268
292
  });
269
293
  it('should not remove component on hidden page if component used elsewhere.', () => {
270
294
  const submissionData = JSON.parse(JSON.stringify(_dataHiddenPageComponentUsedElsewhere.default));
271
295
  const form = JSON.parse(JSON.stringify(_formHiddenPageComponentUsedElsewhere.default));
272
- const result = _index.default.clearOutUncompletedRoutes(form, submissionData);
296
+ const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
273
297
  expect(result).toEqual(_dataHiddenPageComponentUsedElsewhereRemoved.default);
274
298
  });
275
299
  it('chained show_whens should be resolved from the end of the chain backup to the start.', () => {
276
300
  const submissionData = JSON.parse(JSON.stringify(_dataChainedComponentShowWhens.default));
277
301
  const form = JSON.parse(JSON.stringify(_formChainedComponentShowWhens.default));
278
- const result = _index.default.clearOutUncompletedRoutes(form, submissionData);
302
+ const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
279
303
  expect(result).toEqual(_dataChainedComponentShowWhensRemoved.default);
280
304
  });
281
305
  it('chained show_whens when top level dependency is field within refdata object.', () => {
282
306
  const submissionData = JSON.parse(JSON.stringify(_dataChainedComponentShowWhensRefdata.default));
283
307
  const form = JSON.parse(JSON.stringify(_formChainedComponentShowWhensRefdata.default));
284
- const result = _index.default.clearOutUncompletedRoutes(form, submissionData);
308
+ const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
285
309
  expect(result).toEqual(_dataChainedComponentShowWhensRefdataRemoved.default);
286
310
  });
287
311
  it('chained show_whens should be resolved from the end of the chain backup to the start, even if the target and dependent components are in containers thus having segmented paths.', () => {
288
312
  const submissionData = JSON.parse(JSON.stringify(_dataChainedComponentShowWhensContainerised.default));
289
313
  const form = JSON.parse(JSON.stringify(_formChainedComponentShowWhensContainerised.default));
290
- const result = _index.default.clearOutUncompletedRoutes(form, submissionData);
314
+ const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
291
315
  expect(result).toEqual(_dataChainedComponentShowWhensContainerisedRemoved.default);
292
316
  });
293
317
  it('chained show_whens when the component at the end of the chain is hidden indirectly via page show_when.', () => {
294
318
  const submissionData = JSON.parse(JSON.stringify(_dataChainedShowWhensPageHidden.default));
295
319
  const form = JSON.parse(JSON.stringify(_formChainedShowWhensPageHidden.default));
296
- const result = _index.default.clearOutUncompletedRoutes(form, submissionData);
320
+ const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
297
321
  expect(result).toEqual(_dataChainedShowWhensPageHiddenRemoved.default);
298
322
  });
299
323
  it('chained show_whens when the dependent component is nested single question.', () => {
300
324
  const submissionData = JSON.parse(JSON.stringify(_dataChainedComponentShowWhensDependentComponentNested.default));
301
325
  const form = JSON.parse(JSON.stringify(_formChainedComponentShowWhensDependentComponentNested.default));
302
- const result = _index.default.clearOutUncompletedRoutes(form, submissionData);
326
+ const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
303
327
  expect(result).toEqual(_dataChainedComponentShowWhensDependentComponentNestedRemoved.default);
304
328
  });
305
329
  it('chained show_whens when the target component is nested.', () => {
306
330
  const submissionData = JSON.parse(JSON.stringify(_dataChainedComponentShowWhensTargetComponentNested.default));
307
331
  const form = JSON.parse(JSON.stringify(_formChainedComponentShowWhensTargetComponentNested.default));
308
- const result = _index.default.clearOutUncompletedRoutes(form, submissionData);
332
+ const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
309
333
  expect(result).toEqual(_dataChainedComponentShowWhensTargetComponentNestedRemoved.default);
310
334
  });
311
335
  it('chained show_whens when the dependent component is nested entire block.', () => {
312
336
  const submissionData = JSON.parse(JSON.stringify(_dataChainedComponentShowWhensDependentComponentNestedBlock.default));
313
337
  const form = JSON.parse(JSON.stringify(_formChainedComponentShowWhensDependentComponentNestedBlock.default));
314
- const result = _index.default.clearOutUncompletedRoutes(form, submissionData);
338
+ const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
315
339
  expect(result).toEqual(_dataChainedComponentShowWhensDependentComponentNestedBlockRemoved.default);
316
340
  });
317
341
  it('business interests removed from mandec.', () => {
318
342
  const submissionData = JSON.parse(JSON.stringify(_copMandecRemoveBusinessInterestsBefore.default));
319
343
  const form = JSON.parse(JSON.stringify(_formCopMandec.default));
320
- const result = _index.default.clearOutUncompletedRoutes(form, submissionData);
344
+ const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
321
345
  expect(result).toEqual(_copMandecRemoveBusinessInterestsAfter.default);
322
346
  });
323
347
  it('criminality removed from mandec.', () => {
324
348
  const submissionData = JSON.parse(JSON.stringify(_copMandecRemoveCriminalityBefore.default));
325
349
  const form = JSON.parse(JSON.stringify(_formCopMandec.default));
326
- const result = _index.default.clearOutUncompletedRoutes(form, submissionData);
350
+ const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
327
351
  expect(result).toEqual(_copMandecRemoveCriminalityAfter.default);
328
352
  });
329
353
  it('Unspent convictions removed from mandec.', () => {
330
354
  const submissionData = JSON.parse(JSON.stringify(_copMandecRemoveUnspentConvictionsBefore.default));
331
355
  const form = JSON.parse(JSON.stringify(_formCopMandec.default));
332
- const result = _index.default.clearOutUncompletedRoutes(form, submissionData);
356
+ const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
333
357
  expect(result).toEqual(_copMandecRemoveUnspentConvictionsAfter.default);
334
358
  });
359
+ it('Reassign to RCC form, preserved fields not cleansed.', () => {
360
+ const submissionData = JSON.parse(JSON.stringify(_reassignToRcc.default));
361
+ const form = JSON.parse(JSON.stringify(_copReassignTaskToRcc.default));
362
+ const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
363
+ expect(result).toEqual(_reassignToRcc.default);
364
+ });
335
365
  it('photos removed from airpax.', () => {
336
366
  const submissionData = JSON.parse(JSON.stringify(_copAirpaxRemovePhotosBefore.default));
337
367
  const form = JSON.parse(JSON.stringify(_formCopAirpax.default));
338
- const result = _index.default.clearOutUncompletedRoutes(form, submissionData);
368
+ const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
339
369
  expect(result).toEqual(_copAirpaxRemovePhotosAfter.default);
340
370
  });
371
+ it('carrier not removed from airpax.', () => {
372
+ const submissionData = JSON.parse(JSON.stringify(_copAirpaxCarrier.default));
373
+ const form = JSON.parse(JSON.stringify(_formCopAirpax.default));
374
+ const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
375
+ expect(result).toEqual(_copAirpaxCarrier.default);
376
+ });
341
377
  it('airpax change whatHappened to hide whoDecidedSelection.', () => {
342
378
  const submissionData = JSON.parse(JSON.stringify(_copAirpaxChangeWhatHappenedBefore.default));
343
379
  const form = JSON.parse(JSON.stringify(_formCopAirpax.default));
344
- const result = _index.default.clearOutUncompletedRoutes(form, submissionData);
380
+ const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
345
381
  expect(result).toEqual(_copAirpaxChangeWhatHappenedAfter.default);
346
382
  });
383
+ it('should handle nested option in container componet defined in the page.', () => {
384
+ const submissionData = JSON.parse(JSON.stringify(_dataPageNestedRadioComponent.default));
385
+ const form = JSON.parse(JSON.stringify(_formPageNestedRadioComponent.default));
386
+ const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
387
+ expect(result).toEqual(_dataPageNestedRadioComponentRemoved.default);
388
+ });
347
389
  });
348
390
  });
349
391
  });