@ukhomeoffice/cop-react-form-renderer 4.28.0 → 4.29.0-beta
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 +23 -5
- package/dist/components/CollectionPage/CollectionPage.test.js +9 -9
- package/dist/components/FormComponent/Collection.test.js +7 -7
- package/dist/components/FormComponent/Container.test.js +14 -14
- package/dist/components/FormComponent/FormComponent.test.js +6 -6
- package/dist/components/FormPage/FormPage.js +6 -1
- package/dist/components/FormPage/FormPage.test.js +8 -8
- package/dist/components/FormRenderer/FormRenderer.js +64 -7
- package/dist/components/FormRenderer/FormRenderer.test.js +71 -13
- package/dist/components/FormRenderer/handlers/navigate.js +2 -2
- package/dist/json/multiQuestionTaskList.json +275 -0
- package/dist/json/multiQuestionTaskListData.json +39 -0
- package/dist/models/PageAction.js +7 -1
- package/dist/utils/Component/getComponentTests/getComponent.autocomplete.test.js +4 -3
- package/dist/utils/Component/getComponentTests/getComponent.calculation.test.js +2 -2
- package/dist/utils/Component/getComponentTests/getComponent.checkboxes.test.js +4 -3
- package/dist/utils/Component/getComponentTests/getComponent.date.test.js +7 -7
- package/dist/utils/Component/getComponentTests/getComponent.email.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.file.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +11 -11
- package/dist/utils/Component/getComponentTests/getComponent.phoneNumber.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.radios.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.select.test.js +1 -7
- package/dist/utils/Component/getComponentTests/getComponent.text.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.textarea.test.js +1 -1
- package/dist/utils/Component/getComponentTests/getComponent.time.test.js +4 -4
- package/dist/utils/Validate/validateComponent.js +3 -2
- package/dist/utils/Validate/validateEmail.js +9 -1
- package/dist/utils/Validate/validateEmail.test.js +8 -0
- package/package.json +2 -2
|
@@ -47,29 +47,29 @@ describe('utils.Component.get', function () {
|
|
|
47
47
|
}];
|
|
48
48
|
_renderWithValidation = (0, _setupTests.renderWithValidation)((0, _getComponent.getChildrenJsx)(PARENT_CONFIG, NESTED_CONFIG)), container = _renderWithValidation.container;
|
|
49
49
|
child = container.childNodes[0];
|
|
50
|
-
expect(child.childNodes.length).toEqual(3);
|
|
50
|
+
expect(child.childNodes[0].childNodes.length).toEqual(3);
|
|
51
51
|
expect(child.classList).toContain('govuk-form-group');
|
|
52
52
|
label = child.childNodes[0];
|
|
53
53
|
expect(label).toBeDefined();
|
|
54
54
|
expect(label.innerHTML).toContain(LABEL);
|
|
55
|
-
input = child.childNodes[2];
|
|
55
|
+
input = child.childNodes[0].childNodes[2];
|
|
56
56
|
expect(input.tagName).toEqual('INPUT');
|
|
57
57
|
expect(input.classList).toContain('govuk-input');
|
|
58
58
|
expect(input.id).toEqual(ID);
|
|
59
59
|
expect(input.value).toEqual(VALUE);
|
|
60
60
|
child2 = container.childNodes[1];
|
|
61
|
-
expect(child2.childNodes.length).toEqual(3);
|
|
61
|
+
expect(child2.childNodes[0].childNodes.length).toEqual(3);
|
|
62
62
|
expect(child2.classList).toContain('govuk-form-group');
|
|
63
63
|
label2 = child2.childNodes[0];
|
|
64
64
|
expect(label2).toBeDefined();
|
|
65
65
|
expect(label2.innerHTML).toContain(LABEL2);
|
|
66
|
-
input2 = child2.childNodes[2];
|
|
66
|
+
input2 = child2.childNodes[0].childNodes[2];
|
|
67
67
|
expect(input2.tagName).toEqual('DIV');
|
|
68
68
|
expect(input2.classList).toContain('govuk-date-input');
|
|
69
69
|
expect(input2.id).toEqual(ID2);
|
|
70
|
-
expect(input2.childNodes[0].childNodes[1].value).toEqual('1');
|
|
71
|
-
expect(input2.childNodes[1].childNodes[1].value).toEqual('2');
|
|
72
|
-
expect(input2.childNodes[2].childNodes[1].value).toEqual('2022');
|
|
70
|
+
expect(input2.childNodes[0].childNodes[0].childNodes[1].value).toEqual('1');
|
|
71
|
+
expect(input2.childNodes[1].childNodes[0].childNodes[1].value).toEqual('2');
|
|
72
|
+
expect(input2.childNodes[2].childNodes[0].childNodes[1].value).toEqual('2022');
|
|
73
73
|
|
|
74
74
|
case 35:
|
|
75
75
|
case "end":
|
|
@@ -137,12 +137,12 @@ describe('utils.Component.get', function () {
|
|
|
137
137
|
}];
|
|
138
138
|
_renderWithValidation2 = (0, _setupTests.renderWithValidation)((0, _getComponent.getChildrenJsx)(PARENT_CONFIG, NESTED_CONFIG)), container = _renderWithValidation2.container;
|
|
139
139
|
child = container.childNodes[0];
|
|
140
|
-
expect(child.childNodes.length).toEqual(3);
|
|
140
|
+
expect(child.childNodes[0].childNodes.length).toEqual(3);
|
|
141
141
|
expect(child.classList).toContain('govuk-form-group');
|
|
142
142
|
label = child.childNodes[0];
|
|
143
143
|
expect(label).toBeDefined();
|
|
144
144
|
expect(label.innerHTML).toContain(LABEL);
|
|
145
|
-
input = child.childNodes[2];
|
|
145
|
+
input = child.childNodes[0].childNodes[2];
|
|
146
146
|
expect(input.tagName).toEqual('INPUT');
|
|
147
147
|
expect(input.classList).toContain('govuk-input');
|
|
148
148
|
expect(input.id).toEqual("".concat(CONTAINER_ID, ".").concat(FIELD_ID));
|
|
@@ -180,12 +180,12 @@ describe('utils.Component.get', function () {
|
|
|
180
180
|
}];
|
|
181
181
|
_renderWithValidation3 = (0, _setupTests.renderWithValidation)((0, _getComponent.getChildrenJsx)(PARENT_CONFIG, NESTED_CONFIG)), container = _renderWithValidation3.container;
|
|
182
182
|
child = container.childNodes[0];
|
|
183
|
-
expect(child.childNodes.length).toEqual(3);
|
|
183
|
+
expect(child.childNodes[0].childNodes.length).toEqual(3);
|
|
184
184
|
expect(child.classList).toContain('govuk-form-group');
|
|
185
185
|
label = child.childNodes[0];
|
|
186
186
|
expect(label).toBeDefined();
|
|
187
187
|
expect(label.innerHTML).toContain(LABEL);
|
|
188
|
-
input = child.childNodes[2];
|
|
188
|
+
input = child.childNodes[0].childNodes[2];
|
|
189
189
|
expect(input.tagName).toEqual('INPUT');
|
|
190
190
|
expect(input.classList).toContain('govuk-input');
|
|
191
191
|
expect(input.id).toEqual("".concat(COLLECTION_ID, "[0].").concat(FIELD_ID));
|
|
@@ -51,10 +51,10 @@ describe('utils.Component.get', function () {
|
|
|
51
51
|
expect(formGroup.tagName).toEqual('DIV');
|
|
52
52
|
expect(formGroup.classList).toContain('govuk-form-group');
|
|
53
53
|
var label = undefined;
|
|
54
|
-
formGroup.childNodes.forEach(function (node) {
|
|
54
|
+
formGroup.childNodes[0].childNodes.forEach(function (node) {
|
|
55
55
|
// Check if it's an element.
|
|
56
|
-
if (node instanceof Element && node.tagName === '
|
|
57
|
-
label = node;
|
|
56
|
+
if (node instanceof Element && node.tagName === 'LEGEND') {
|
|
57
|
+
label = node.childNodes[0];
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
60
|
expect(label).toBeDefined();
|
|
@@ -61,11 +61,11 @@ describe('utils.Component.get', function () {
|
|
|
61
61
|
expect(formGroup.tagName).toEqual('DIV');
|
|
62
62
|
expect(formGroup.classList).toContain('govuk-form-group');
|
|
63
63
|
var label = undefined;
|
|
64
|
-
formGroup.childNodes.forEach(function (node) {
|
|
64
|
+
formGroup.childNodes[0].childNodes.forEach(function (node) {
|
|
65
65
|
// Check if it's an element.
|
|
66
66
|
if (node instanceof Element) {
|
|
67
|
-
if (node.tagName === '
|
|
68
|
-
label = node;
|
|
67
|
+
if (node.tagName === 'LEGEND') {
|
|
68
|
+
label = node.childNodes[0];
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
});
|
|
@@ -58,13 +58,7 @@ describe('utils.Component.get', function () {
|
|
|
58
58
|
|
|
59
59
|
expect(formGroup.tagName).toEqual('DIV');
|
|
60
60
|
expect(formGroup.classList).toContain('govuk-form-group');
|
|
61
|
-
var label =
|
|
62
|
-
formGroup.childNodes.forEach(function (node) {
|
|
63
|
-
// Check if it's an element.
|
|
64
|
-
if (node instanceof Element && node.tagName === 'LABEL') {
|
|
65
|
-
label = node;
|
|
66
|
-
}
|
|
67
|
-
});
|
|
61
|
+
var label = formGroup.childNodes[0].childNodes[0].childNodes[0];
|
|
68
62
|
expect(label).toBeDefined();
|
|
69
63
|
expect(label.innerHTML).toContain(LABEL);
|
|
70
64
|
expect(label.getAttribute('for')).toEqual(ID);
|
|
@@ -51,10 +51,10 @@ describe('utils.Component.get', function () {
|
|
|
51
51
|
expect(formGroup.tagName).toEqual('DIV');
|
|
52
52
|
expect(formGroup.classList).toContain('govuk-form-group');
|
|
53
53
|
var label = undefined;
|
|
54
|
-
formGroup.childNodes.forEach(function (node) {
|
|
54
|
+
formGroup.childNodes[0].childNodes.forEach(function (node) {
|
|
55
55
|
// Check if it's an element.
|
|
56
|
-
if (node instanceof Element && node.tagName === '
|
|
57
|
-
label = node;
|
|
56
|
+
if (node instanceof Element && node.tagName === 'LEGEND') {
|
|
57
|
+
label = node.childNodes[0];
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
60
|
expect(label).toBeDefined();
|
|
@@ -52,7 +52,7 @@ describe('utils.Component.get', function () {
|
|
|
52
52
|
|
|
53
53
|
expect(formGroup.tagName).toEqual('DIV');
|
|
54
54
|
expect(formGroup.classList).toContain('govuk-form-group');
|
|
55
|
-
var label = formGroup.childNodes[0];
|
|
55
|
+
var label = formGroup.childNodes[0].childNodes[0].childNodes[0];
|
|
56
56
|
expect(label.innerHTML).toContain(LABEL);
|
|
57
57
|
expect(label.getAttribute('for')).toEqual(ID);
|
|
58
58
|
expect(textarea.tagName).toEqual('TEXTAREA');
|
|
@@ -50,7 +50,7 @@ describe('utils.Component.get', function () {
|
|
|
50
50
|
|
|
51
51
|
expect(formGroup.tagName).toEqual('DIV');
|
|
52
52
|
expect(formGroup.classList).toContain('govuk-form-group');
|
|
53
|
-
var label = formGroup.childNodes[0];
|
|
53
|
+
var label = formGroup.childNodes[0].childNodes[0].childNodes[0];
|
|
54
54
|
expect(label.innerHTML).toContain(LABEL);
|
|
55
55
|
expect(label.getAttribute('for')).toEqual(ID);
|
|
56
56
|
expect(timeInput.tagName).toEqual('DIV');
|
|
@@ -78,12 +78,12 @@ describe('utils.Component.get', function () {
|
|
|
78
78
|
expect(part.item.tagName).toEqual('DIV');
|
|
79
79
|
expect(part.item.classList).toContain('govuk-date-input__item');
|
|
80
80
|
|
|
81
|
-
var _part$item$childNodes = _slicedToArray(part.item.childNodes, 2),
|
|
81
|
+
var _part$item$childNodes = _slicedToArray(part.item.childNodes[0].childNodes, 2),
|
|
82
82
|
label = _part$item$childNodes[0],
|
|
83
83
|
input = _part$item$childNodes[1];
|
|
84
84
|
|
|
85
|
-
expect(label.tagName).toEqual('LABEL');
|
|
86
|
-
expect(label.classList).toContain('govuk-label');
|
|
85
|
+
expect(label.childNodes[0].tagName).toEqual('LABEL');
|
|
86
|
+
expect(label.childNodes[0].classList).toContain('govuk-label');
|
|
87
87
|
expect(label.textContent).toEqual(part.label);
|
|
88
88
|
expect(input.tagName).toEqual('INPUT');
|
|
89
89
|
expect(input.id).toEqual("".concat(ID, "-").concat(part.id)); // Put something in the input and make sure it fires.
|
|
@@ -37,7 +37,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
37
37
|
* @returns The first encountered error with the component.
|
|
38
38
|
*/
|
|
39
39
|
var validateComponent = function validateComponent(component, outerData, formData) {
|
|
40
|
-
var _component$data$optio;
|
|
40
|
+
var _fd$keycloakContext, _component$data$optio;
|
|
41
41
|
|
|
42
42
|
var fd = formData || outerData;
|
|
43
43
|
|
|
@@ -64,7 +64,8 @@ var validateComponent = function validateComponent(component, outerData, formDat
|
|
|
64
64
|
return (0, _validateCollection.default)(component, value, fd);
|
|
65
65
|
|
|
66
66
|
case _models.ComponentTypes.EMAIL:
|
|
67
|
-
|
|
67
|
+
var userEmail = fd === null ? '' : (_fd$keycloakContext = fd.keycloakContext) === null || _fd$keycloakContext === void 0 ? void 0 : _fd$keycloakContext.email;
|
|
68
|
+
error = (0, _validateEmail.default)(value, component.label, userEmail);
|
|
68
69
|
break;
|
|
69
70
|
|
|
70
71
|
case _models.ComponentTypes.DATE:
|
|
@@ -15,20 +15,28 @@ var HODS_EMAIL_REGEX = /^[a-z0-9._-]+@(digital\.)?homeoffice.gov.uk$/i;
|
|
|
15
15
|
* validateRequired (Validate.required) for that sort of validation.
|
|
16
16
|
* @param {*} value The value to validate.
|
|
17
17
|
* @param {string} label The label to use in any error message.
|
|
18
|
+
* @param {string} userEmail The user email to use for validation.
|
|
18
19
|
* @returns An error if the email address is invalid.
|
|
19
20
|
*/
|
|
20
21
|
|
|
21
22
|
var validateEmail = function validateEmail(value) {
|
|
22
23
|
var label = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
24
|
+
var userEmail = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
23
25
|
|
|
24
26
|
if (!!value) {
|
|
27
|
+
var name = label ? label.toLowerCase() : 'email address';
|
|
28
|
+
|
|
25
29
|
if (typeof value === 'string') {
|
|
30
|
+
// The following is an interim fix pending a mechanism for validating against specific values
|
|
31
|
+
if (['Line manager email', 'Delegate email address'].includes(label) && value.toLowerCase() === userEmail) {
|
|
32
|
+
return "".concat(label, " cannot be the same as the user email address");
|
|
33
|
+
}
|
|
34
|
+
|
|
26
35
|
if (HODS_EMAIL_REGEX.test(value)) {
|
|
27
36
|
return undefined;
|
|
28
37
|
}
|
|
29
38
|
}
|
|
30
39
|
|
|
31
|
-
var name = label ? label.toLowerCase() : 'email address';
|
|
32
40
|
return "Enter ".concat(name, " in the correct format, like jane.doe@homeoffice.gov.uk");
|
|
33
41
|
}
|
|
34
42
|
|
|
@@ -52,6 +52,14 @@ describe('utils', function () {
|
|
|
52
52
|
var DEFAULT_ERROR = 'Enter email address in the correct format, like jane.doe@homeoffice.gov.uk';
|
|
53
53
|
expect((0, _validateEmail.default)(['bob'], undefined)).toEqual(DEFAULT_ERROR);
|
|
54
54
|
});
|
|
55
|
+
it('should return an error when line manager email is same as user email', function () {
|
|
56
|
+
var USER_EMAIL_ERROR = 'Line manager email cannot be the same as the user email address';
|
|
57
|
+
expect((0, _validateEmail.default)('joe.bloggs@digital.homeoffice.gov.uk', 'Line manager email', 'joe.bloggs@digital.homeoffice.gov.uk')).toEqual(USER_EMAIL_ERROR);
|
|
58
|
+
});
|
|
59
|
+
it('should return an error when delegate email is same as user email', function () {
|
|
60
|
+
var USER_EMAIL_ERROR = 'Delegate email address cannot be the same as the user email address';
|
|
61
|
+
expect((0, _validateEmail.default)('joe.bloggs@digital.homeoffice.gov.uk', 'Delegate email address', 'joe.bloggs@digital.homeoffice.gov.uk')).toEqual(USER_EMAIL_ERROR);
|
|
62
|
+
});
|
|
55
63
|
});
|
|
56
64
|
});
|
|
57
65
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ukhomeoffice/cop-react-form-renderer",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.29.0-beta",
|
|
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": "2.
|
|
19
|
+
"@ukhomeoffice/cop-react-components": "2.5.0",
|
|
20
20
|
"axios": "^0.23.0",
|
|
21
21
|
"dayjs": "^1.11.0",
|
|
22
22
|
"govuk-frontend": "^4.3.1",
|