@ukhomeoffice/cop-react-form-renderer 3.28.0 → 3.31.0
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.
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +5 -2
- package/dist/components/CollectionPage/CollectionPage.js +149 -0
- package/dist/components/CollectionPage/CollectionPage.test.js +428 -0
- package/dist/components/CollectionPage/index.js +13 -0
- package/dist/components/FormPage/FormPage.js +6 -1
- package/dist/components/FormRenderer/FormRenderer.js +61 -17
- package/dist/components/PageActions/ActionButton.js +1 -1
- package/dist/models/PageAction.js +5 -1
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +85 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +107 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +6 -0
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.js +45 -0
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.test.js +41 -0
- package/dist/utils/CollectionPage/getCollectionPageActiveIndex.js +34 -0
- package/dist/utils/CollectionPage/getCollectionPageActiveIndex.test.js +54 -0
- package/dist/utils/CollectionPage/index.js +23 -0
- package/dist/utils/CollectionPage/mergeCollectionPages.js +69 -0
- package/dist/utils/CollectionPage/mergeCollectionPages.test.js +131 -0
- package/dist/utils/Validate/validatePage.js +16 -2
- package/dist/utils/Validate/validatePage.test.js +352 -206
- package/dist/utils/index.js +3 -0
- package/package.json +2 -2
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _mergeCollectionPages = _interopRequireDefault(require("./mergeCollectionPages"));
|
|
4
|
+
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
+
|
|
7
|
+
// Local imports
|
|
8
|
+
describe('utils.CollectionPage.mergeCollectionPages', function () {
|
|
9
|
+
var TEXT_COMP = {
|
|
10
|
+
id: 'testText',
|
|
11
|
+
fieldId: 'testText',
|
|
12
|
+
type: 'text'
|
|
13
|
+
};
|
|
14
|
+
var DATE_COMP = {
|
|
15
|
+
id: 'testDate',
|
|
16
|
+
fieldId: 'testDate',
|
|
17
|
+
type: 'date'
|
|
18
|
+
};
|
|
19
|
+
it('should return the same array if no pages belong to collections', function () {
|
|
20
|
+
var PAGES = [{
|
|
21
|
+
id: 'page1'
|
|
22
|
+
}, {
|
|
23
|
+
id: 'page2'
|
|
24
|
+
}];
|
|
25
|
+
expect((0, _mergeCollectionPages.default)(PAGES)).toEqual(PAGES);
|
|
26
|
+
});
|
|
27
|
+
it('should merge pages from the same collection into a single page', function () {
|
|
28
|
+
var PAGES = [{
|
|
29
|
+
id: 'page1',
|
|
30
|
+
collection: {
|
|
31
|
+
name: 'collection'
|
|
32
|
+
},
|
|
33
|
+
components: [TEXT_COMP]
|
|
34
|
+
}, {
|
|
35
|
+
id: 'page2',
|
|
36
|
+
collection: {
|
|
37
|
+
name: 'collection'
|
|
38
|
+
},
|
|
39
|
+
components: [DATE_COMP]
|
|
40
|
+
}];
|
|
41
|
+
var RESULT = (0, _mergeCollectionPages.default)(PAGES);
|
|
42
|
+
expect(RESULT.length).toEqual(1);
|
|
43
|
+
expect(RESULT[0]).toEqual({
|
|
44
|
+
id: 'page1',
|
|
45
|
+
title: 'Collection',
|
|
46
|
+
collection: {
|
|
47
|
+
name: 'collection'
|
|
48
|
+
},
|
|
49
|
+
components: [TEXT_COMP, DATE_COMP],
|
|
50
|
+
formData: {}
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
it('should leave non-collection pages unaffected', function () {
|
|
54
|
+
var PAGES = [{
|
|
55
|
+
id: 'page1',
|
|
56
|
+
collection: {
|
|
57
|
+
name: 'collection'
|
|
58
|
+
},
|
|
59
|
+
components: [TEXT_COMP]
|
|
60
|
+
}, {
|
|
61
|
+
id: 'page2',
|
|
62
|
+
collection: {
|
|
63
|
+
name: 'collection'
|
|
64
|
+
},
|
|
65
|
+
components: [DATE_COMP]
|
|
66
|
+
}, {
|
|
67
|
+
id: 'page3'
|
|
68
|
+
}];
|
|
69
|
+
var RESULT = (0, _mergeCollectionPages.default)(PAGES);
|
|
70
|
+
expect(RESULT.length).toEqual(2);
|
|
71
|
+
expect(RESULT[0]).toEqual({
|
|
72
|
+
id: 'page1',
|
|
73
|
+
title: 'Collection',
|
|
74
|
+
collection: {
|
|
75
|
+
name: 'collection'
|
|
76
|
+
},
|
|
77
|
+
components: [TEXT_COMP, DATE_COMP],
|
|
78
|
+
formData: {}
|
|
79
|
+
});
|
|
80
|
+
expect(RESULT[1]).toEqual({
|
|
81
|
+
id: 'page3'
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
it('should handle multiple collections', function () {
|
|
85
|
+
var PAGES = [{
|
|
86
|
+
id: 'page1',
|
|
87
|
+
collection: {
|
|
88
|
+
name: 'collection1'
|
|
89
|
+
},
|
|
90
|
+
components: []
|
|
91
|
+
}, {
|
|
92
|
+
id: 'page2',
|
|
93
|
+
collection: {
|
|
94
|
+
name: 'collection1'
|
|
95
|
+
},
|
|
96
|
+
components: []
|
|
97
|
+
}, {
|
|
98
|
+
id: 'page3',
|
|
99
|
+
collection: {
|
|
100
|
+
name: 'collection2'
|
|
101
|
+
},
|
|
102
|
+
components: []
|
|
103
|
+
}, {
|
|
104
|
+
id: 'page4',
|
|
105
|
+
collection: {
|
|
106
|
+
name: 'collection2'
|
|
107
|
+
},
|
|
108
|
+
components: []
|
|
109
|
+
}];
|
|
110
|
+
var RESULT = (0, _mergeCollectionPages.default)(PAGES);
|
|
111
|
+
expect(RESULT.length).toEqual(2);
|
|
112
|
+
expect(RESULT[0]).toEqual({
|
|
113
|
+
id: 'page1',
|
|
114
|
+
collection: {
|
|
115
|
+
name: 'collection1'
|
|
116
|
+
},
|
|
117
|
+
title: 'Collection1',
|
|
118
|
+
components: [],
|
|
119
|
+
formData: {}
|
|
120
|
+
});
|
|
121
|
+
expect(RESULT[1]).toEqual({
|
|
122
|
+
id: 'page3',
|
|
123
|
+
collection: {
|
|
124
|
+
name: 'collection2'
|
|
125
|
+
},
|
|
126
|
+
title: 'Collection2',
|
|
127
|
+
components: [],
|
|
128
|
+
formData: {}
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
});
|
|
@@ -9,6 +9,8 @@ var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
|
9
9
|
|
|
10
10
|
var _validateComponent = _interopRequireDefault(require("./validateComponent"));
|
|
11
11
|
|
|
12
|
+
var _CollectionPage = _interopRequireDefault(require("../CollectionPage"));
|
|
13
|
+
|
|
12
14
|
var _showFormPage = _interopRequireDefault(require("../FormPage/showFormPage"));
|
|
13
15
|
|
|
14
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -25,12 +27,24 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
25
27
|
* @returns An array containing all of the errors.
|
|
26
28
|
*/
|
|
27
29
|
var validatePage = function validatePage(page) {
|
|
30
|
+
var data = page.formData;
|
|
31
|
+
|
|
32
|
+
if (page.collection) {
|
|
33
|
+
var activeIndex = _CollectionPage.default.getActiveIndex(page.collection.name, page.formData);
|
|
34
|
+
|
|
35
|
+
if (activeIndex !== null) {
|
|
36
|
+
var _page$formData$page$c;
|
|
37
|
+
|
|
38
|
+
data = (_page$formData$page$c = page.formData[page.collection.name]) === null || _page$formData$page$c === void 0 ? void 0 : _page$formData$page$c[activeIndex];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
28
42
|
if ((0, _showFormPage.default)(page, page.formData) && Array.isArray(page.components)) {
|
|
29
43
|
var errs = page.components.reduce(function (errors, component) {
|
|
30
|
-
var componentErrors = (0, _validateComponent.default)(component,
|
|
44
|
+
var componentErrors = (0, _validateComponent.default)(component, data, data);
|
|
31
45
|
return errors.concat(componentErrors).flat().map(function (err) {
|
|
32
46
|
return !!err ? _objectSpread(_objectSpread({}, err), {}, {
|
|
33
|
-
error: _copReactComponents.Utils.interpolateString(err.error,
|
|
47
|
+
error: _copReactComponents.Utils.interpolateString(err.error, data)
|
|
34
48
|
}) : err;
|
|
35
49
|
});
|
|
36
50
|
}, []).filter(function (e) {
|