@ukhomeoffice/cop-react-form-renderer 2.6.1 → 2.7.1
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/Answer.js +3 -1
- package/dist/components/CheckYourAnswers/Answer.test.js +3 -2
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +45 -5
- package/dist/components/CheckYourAnswers/CheckYourAnswers.scss +10 -0
- package/dist/components/CheckYourAnswers/CheckYourAnswers.stories.mdx +331 -269
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +74 -12
- package/dist/components/FormComponent/Container.test.js +89 -10
- package/dist/components/FormComponent/FormComponent.js +63 -14
- package/dist/components/FormRenderer/FormRenderer.test.js +1 -1
- package/dist/components/FormRenderer/helpers/canActionProceed.js +1 -1
- package/dist/components/FormRenderer/helpers/canCYASubmit.js +1 -1
- package/dist/components/SummaryList/GroupAction.js +68 -0
- package/dist/components/SummaryList/GroupAction.test.js +94 -0
- package/dist/components/SummaryList/SummaryList.js +15 -4
- package/dist/components/SummaryList/SummaryList.scss +29 -5
- package/dist/components/SummaryList/SummaryList.test.js +47 -4
- package/dist/components/SummaryList/helpers/getGroupActionAttributes.js +27 -0
- package/dist/components/SummaryList/helpers/getGroupActionAttributes.test.js +77 -0
- package/dist/json/groupOfRow.json +158 -0
- package/dist/json/groupOfRowData.json +15 -0
- package/dist/models/ComponentTypes.js +2 -0
- package/dist/utils/Component/getComponent.js +13 -5
- package/dist/utils/Component/getComponentTests/getComponent.file.test.js +81 -0
- package/dist/utils/Component/isEditable.js +1 -1
- package/dist/utils/Data/index.js +3 -0
- package/dist/utils/Data/setDataItem.js +29 -0
- package/dist/utils/Data/setDataItem.test.js +112 -0
- package/dist/utils/Validate/validatePage.js +7 -6
- package/dist/utils/Validate/validatePage.test.js +60 -12
- package/package.json +2 -2
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _setDataItem = _interopRequireDefault(require("./setDataItem"));
|
|
4
|
+
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
+
|
|
7
|
+
describe('utils.Data.setDataItem', function () {
|
|
8
|
+
it('should handle a null data object', function () {
|
|
9
|
+
var DATA = null;
|
|
10
|
+
var FIELD_ID = 'alpha.bravo.charlie';
|
|
11
|
+
var VALUE = 'delta';
|
|
12
|
+
expect((0, _setDataItem.default)(DATA, FIELD_ID, VALUE)).toBeNull();
|
|
13
|
+
expect(DATA).toBeNull();
|
|
14
|
+
});
|
|
15
|
+
it('should handle an undefined data object', function () {
|
|
16
|
+
var DATA = undefined;
|
|
17
|
+
var FIELD_ID = 'alpha.bravo.charlie';
|
|
18
|
+
var VALUE = 'delta';
|
|
19
|
+
expect((0, _setDataItem.default)(DATA, FIELD_ID, VALUE)).toBeUndefined();
|
|
20
|
+
expect(DATA).toBeUndefined();
|
|
21
|
+
});
|
|
22
|
+
it('should handle a null fieldId', function () {
|
|
23
|
+
var DATA = {};
|
|
24
|
+
var FIELD_ID = null;
|
|
25
|
+
var VALUE = 'delta';
|
|
26
|
+
expect((0, _setDataItem.default)(DATA, FIELD_ID, VALUE)).toMatchObject({});
|
|
27
|
+
expect(DATA).toMatchObject({});
|
|
28
|
+
});
|
|
29
|
+
it('should handle an undefined fieldId', function () {
|
|
30
|
+
var DATA = {};
|
|
31
|
+
var FIELD_ID = undefined;
|
|
32
|
+
var VALUE = 'delta';
|
|
33
|
+
expect((0, _setDataItem.default)(DATA, FIELD_ID, VALUE)).toMatchObject({});
|
|
34
|
+
expect(DATA).toMatchObject({});
|
|
35
|
+
});
|
|
36
|
+
it('should handle an empty fieldId', function () {
|
|
37
|
+
var DATA = {};
|
|
38
|
+
var FIELD_ID = '';
|
|
39
|
+
var VALUE = 'delta';
|
|
40
|
+
expect((0, _setDataItem.default)(DATA, FIELD_ID, VALUE)).toMatchObject({});
|
|
41
|
+
expect(DATA).toMatchObject({});
|
|
42
|
+
});
|
|
43
|
+
it('should appropriately set a nested value', function () {
|
|
44
|
+
var DATA = {
|
|
45
|
+
alpha: {}
|
|
46
|
+
};
|
|
47
|
+
var FIELD_ID = 'alpha.bravo.charlie';
|
|
48
|
+
var VALUE = 'delta';
|
|
49
|
+
expect((0, _setDataItem.default)(DATA, FIELD_ID, VALUE)).toMatchObject({
|
|
50
|
+
alpha: {
|
|
51
|
+
bravo: {
|
|
52
|
+
charlie: VALUE
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
expect(DATA).toMatchObject({
|
|
57
|
+
alpha: {
|
|
58
|
+
bravo: {
|
|
59
|
+
charlie: VALUE
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
it('should appropriately change a nested value', function () {
|
|
65
|
+
var DATA = {
|
|
66
|
+
alpha: {
|
|
67
|
+
bravo: {
|
|
68
|
+
charlie: 'echo'
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var FIELD_ID = 'alpha.bravo.charlie';
|
|
73
|
+
var VALUE = 'delta';
|
|
74
|
+
expect((0, _setDataItem.default)(DATA, FIELD_ID, VALUE)).toMatchObject({
|
|
75
|
+
alpha: {
|
|
76
|
+
bravo: {
|
|
77
|
+
charlie: VALUE
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
expect(DATA).toMatchObject({
|
|
82
|
+
alpha: {
|
|
83
|
+
bravo: {
|
|
84
|
+
charlie: VALUE
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
it('should handle a parent node that is not an object and convert it appropriately', function () {
|
|
90
|
+
var DATA = {
|
|
91
|
+
alpha: {
|
|
92
|
+
bravo: 'echo'
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
var FIELD_ID = 'alpha.bravo.charlie';
|
|
96
|
+
var VALUE = 'delta';
|
|
97
|
+
expect((0, _setDataItem.default)(DATA, FIELD_ID, VALUE)).toMatchObject({
|
|
98
|
+
alpha: {
|
|
99
|
+
bravo: {
|
|
100
|
+
charlie: VALUE
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
expect(DATA).toMatchObject({
|
|
105
|
+
alpha: {
|
|
106
|
+
bravo: {
|
|
107
|
+
charlie: VALUE
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
});
|
|
@@ -7,20 +7,21 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _validateComponent = _interopRequireDefault(require("./validateComponent"));
|
|
9
9
|
|
|
10
|
+
var _showFormPage = _interopRequireDefault(require("../FormPage/showFormPage"));
|
|
11
|
+
|
|
10
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
13
|
|
|
12
14
|
// Local imports
|
|
13
15
|
|
|
14
16
|
/**
|
|
15
17
|
* Validate all of the components on a page.
|
|
16
|
-
* @param {
|
|
17
|
-
* @param {object} formData The data to use that holds this components' values.
|
|
18
|
+
* @param {object} page The page to validate
|
|
18
19
|
* @returns An array containing all of the errors.
|
|
19
20
|
*/
|
|
20
|
-
var validatePage = function validatePage(
|
|
21
|
-
if (Array.isArray(components)) {
|
|
22
|
-
return components.reduce(function (errors, component) {
|
|
23
|
-
return errors.concat((0, _validateComponent.default)(component, formData));
|
|
21
|
+
var validatePage = function validatePage(page) {
|
|
22
|
+
if ((0, _showFormPage.default)(page, page.formData) && Array.isArray(page.components)) {
|
|
23
|
+
return page.components.reduce(function (errors, component) {
|
|
24
|
+
return errors.concat((0, _validateComponent.default)(component, page.formData));
|
|
24
25
|
}, []).filter(function (e) {
|
|
25
26
|
return !!e;
|
|
26
27
|
}).flat();
|
|
@@ -21,20 +21,36 @@ describe('utils', function () {
|
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
it('should return no error when the components array is null', function () {
|
|
24
|
-
|
|
24
|
+
var PAGE = {
|
|
25
|
+
components: null,
|
|
26
|
+
formData: null
|
|
27
|
+
};
|
|
28
|
+
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
25
29
|
});
|
|
26
30
|
it('should return no error when the components array is empty', function () {
|
|
27
|
-
|
|
31
|
+
var PAGE = {
|
|
32
|
+
components: [],
|
|
33
|
+
formData: null
|
|
34
|
+
};
|
|
35
|
+
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
28
36
|
});
|
|
29
37
|
describe('when there is no form data', function () {
|
|
30
38
|
it('should return no errors when no components are required', function () {
|
|
31
39
|
var COMPONENTS = [setup('a', _models.ComponentTypes.TEXT, 'Alpha', false), setup('b', _models.ComponentTypes.TEXT, 'Bravo', false)];
|
|
32
|
-
|
|
40
|
+
var PAGE = {
|
|
41
|
+
components: COMPONENTS,
|
|
42
|
+
formData: null
|
|
43
|
+
};
|
|
44
|
+
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
33
45
|
});
|
|
34
46
|
it('should return an error for each required component', function () {
|
|
35
47
|
var COMPONENTS = [setup('a', _models.ComponentTypes.TEXT, 'Alpha', true), setup('b', _models.ComponentTypes.TEXT, 'Bravo', true), setup('c', _models.ComponentTypes.TEXT, 'Charlie', false), // The only unrequired one
|
|
36
48
|
setup('d', _models.ComponentTypes.TEXT, 'Delta', true), setup('e', _models.ComponentTypes.TEXT, 'Echo', true)];
|
|
37
|
-
var
|
|
49
|
+
var PAGE = {
|
|
50
|
+
components: COMPONENTS,
|
|
51
|
+
formData: null
|
|
52
|
+
};
|
|
53
|
+
var RESULT = (0, _validatePage.default)(PAGE);
|
|
38
54
|
expect(RESULT.length).toEqual(4);
|
|
39
55
|
expect(RESULT[0]).toEqual({
|
|
40
56
|
id: 'a',
|
|
@@ -61,19 +77,35 @@ describe('utils', function () {
|
|
|
61
77
|
};
|
|
62
78
|
it('should return no errors when none of the components are required or email types', function () {
|
|
63
79
|
var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', false), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', false)];
|
|
64
|
-
|
|
80
|
+
var PAGE = {
|
|
81
|
+
components: COMPONENTS,
|
|
82
|
+
formData: DATA
|
|
83
|
+
};
|
|
84
|
+
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
65
85
|
});
|
|
66
86
|
it('should return no errors when all of the components are required but not email types', function () {
|
|
67
87
|
var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', true), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', true)];
|
|
68
|
-
|
|
88
|
+
var PAGE = {
|
|
89
|
+
components: COMPONENTS,
|
|
90
|
+
formData: DATA
|
|
91
|
+
};
|
|
92
|
+
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
69
93
|
});
|
|
70
94
|
it('should return no errors when none of the components are required but are all email types', function () {
|
|
71
95
|
var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', false), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', false)];
|
|
72
|
-
|
|
96
|
+
var PAGE = {
|
|
97
|
+
components: COMPONENTS,
|
|
98
|
+
formData: DATA
|
|
99
|
+
};
|
|
100
|
+
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
73
101
|
});
|
|
74
102
|
it('should return no errors when all of the components are required and email types', function () {
|
|
75
103
|
var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', true)];
|
|
76
|
-
|
|
104
|
+
var PAGE = {
|
|
105
|
+
components: COMPONENTS,
|
|
106
|
+
formData: DATA
|
|
107
|
+
};
|
|
108
|
+
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
77
109
|
});
|
|
78
110
|
});
|
|
79
111
|
describe('when the form data has one field missing and includes an invalid email', function () {
|
|
@@ -83,11 +115,19 @@ describe('utils', function () {
|
|
|
83
115
|
};
|
|
84
116
|
it('should return no errors when none of the components are required or email types', function () {
|
|
85
117
|
var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', false), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', false), setup('charlie', _models.ComponentTypes.TEXT, 'Charlie', false)];
|
|
86
|
-
|
|
118
|
+
var PAGE = {
|
|
119
|
+
components: COMPONENTS,
|
|
120
|
+
formData: null
|
|
121
|
+
};
|
|
122
|
+
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
87
123
|
});
|
|
88
124
|
it('should return an error for the missing field when all are required but not email types', function () {
|
|
89
125
|
var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', true), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', true), setup('charlie', _models.ComponentTypes.TEXT, 'Charlie', true)];
|
|
90
|
-
var
|
|
126
|
+
var PAGE = {
|
|
127
|
+
components: COMPONENTS,
|
|
128
|
+
formData: DATA
|
|
129
|
+
};
|
|
130
|
+
var RESULT = (0, _validatePage.default)(PAGE);
|
|
91
131
|
expect(RESULT.length).toEqual(1);
|
|
92
132
|
expect(RESULT[0]).toEqual({
|
|
93
133
|
id: 'charlie',
|
|
@@ -96,7 +136,11 @@ describe('utils', function () {
|
|
|
96
136
|
});
|
|
97
137
|
it('should return an error for the invalid email field when none are required but all email types', function () {
|
|
98
138
|
var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', false), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', false), setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie', false)];
|
|
99
|
-
var
|
|
139
|
+
var PAGE = {
|
|
140
|
+
components: COMPONENTS,
|
|
141
|
+
formData: DATA
|
|
142
|
+
};
|
|
143
|
+
var RESULT = (0, _validatePage.default)(PAGE);
|
|
100
144
|
expect(RESULT.length).toEqual(1);
|
|
101
145
|
expect(RESULT[0]).toEqual({
|
|
102
146
|
id: 'bravo',
|
|
@@ -105,7 +149,11 @@ describe('utils', function () {
|
|
|
105
149
|
});
|
|
106
150
|
it('should return an error for both invalid fields when all are required and email types', function () {
|
|
107
151
|
var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', true), setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie', true)];
|
|
108
|
-
var
|
|
152
|
+
var PAGE = {
|
|
153
|
+
components: COMPONENTS,
|
|
154
|
+
formData: DATA
|
|
155
|
+
};
|
|
156
|
+
var RESULT = (0, _validatePage.default)(PAGE);
|
|
109
157
|
expect(RESULT.length).toEqual(2);
|
|
110
158
|
expect(RESULT[0]).toEqual({
|
|
111
159
|
id: 'bravo',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ukhomeoffice/cop-react-form-renderer",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"clean": "rimraf dist",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"post-compile": "rimraf dist/*.test.* dist/**/*.test.* dist/**/*.stories.* dist/docs dist/assets"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@ukhomeoffice/cop-react-components": "1.
|
|
19
|
+
"@ukhomeoffice/cop-react-components": "1.3.0",
|
|
20
20
|
"axios": "^0.21.1",
|
|
21
21
|
"dayjs": "^1.11.0",
|
|
22
22
|
"govuk-frontend": "^3.13.0",
|