@ukhomeoffice/cop-react-form-renderer 4.39.0 → 4.41.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/FormComponent/FormComponent.js +4 -0
- package/dist/utils/Component/getComponentTests/getComponent.multifile.test.js +7 -7
- package/dist/utils/Validate/validateComponent.js +1 -1
- package/dist/utils/Validate/validateEmail.js +12 -1
- package/dist/utils/Validate/validateEmail.test.js +10 -2
- package/package.json +2 -2
|
@@ -90,6 +90,10 @@ var FormComponent = function FormComponent(_ref) {
|
|
|
90
90
|
var target = _ref2.target;
|
|
91
91
|
|
|
92
92
|
if (typeof onChange === 'function') {
|
|
93
|
+
if (component.type === _models.ComponentTypes.EMAIL) {
|
|
94
|
+
target['value'] = target.value.trim();
|
|
95
|
+
}
|
|
96
|
+
|
|
93
97
|
target = (0, _helpers.addLabel)(target, component, data);
|
|
94
98
|
onChange({
|
|
95
99
|
target: target
|
|
@@ -44,13 +44,16 @@ describe('utils.Component.get', function () {
|
|
|
44
44
|
container = _render.container;
|
|
45
45
|
|
|
46
46
|
var _getAllByTestId = (0, _react.getAllByTestId)(container, ID),
|
|
47
|
-
_getAllByTestId2 = _slicedToArray(_getAllByTestId,
|
|
48
|
-
formGroup = _getAllByTestId2[0]
|
|
49
|
-
wrapper = _getAllByTestId2[1];
|
|
47
|
+
_getAllByTestId2 = _slicedToArray(_getAllByTestId, 1),
|
|
48
|
+
formGroup = _getAllByTestId2[0];
|
|
50
49
|
|
|
51
|
-
var input = wrapper.querySelector('#dropzone').children[0];
|
|
52
50
|
expect(formGroup.tagName).toEqual('DIV');
|
|
53
51
|
expect(formGroup.classList).toContain('govuk-form-group');
|
|
52
|
+
var wrapper = container.querySelector("#".concat(ID));
|
|
53
|
+
expect(wrapper.tagName).toEqual('DIV');
|
|
54
|
+
expect(wrapper.classList).toContain('cop-multi-file-upload');
|
|
55
|
+
expect(wrapper.id).toEqual(ID);
|
|
56
|
+
var input = wrapper.children[1].children[0];
|
|
54
57
|
var label = undefined;
|
|
55
58
|
formGroup.childNodes[0].childNodes.forEach(function (node) {
|
|
56
59
|
// Check if it's an element.
|
|
@@ -61,9 +64,6 @@ describe('utils.Component.get', function () {
|
|
|
61
64
|
expect(label).toBeDefined();
|
|
62
65
|
expect(label.innerHTML).toContain(LABEL);
|
|
63
66
|
expect(label.getAttribute('for')).toEqual(ID);
|
|
64
|
-
expect(wrapper.tagName).toEqual('DIV');
|
|
65
|
-
expect(wrapper.classList).toContain('cop-multi-file-upload');
|
|
66
|
-
expect(wrapper.id).toEqual(ID);
|
|
67
67
|
var str = JSON.stringify({
|
|
68
68
|
alpha: 'bravo'
|
|
69
69
|
});
|
|
@@ -67,7 +67,7 @@ var validateComponent = function validateComponent(component, outerData, formDat
|
|
|
67
67
|
|
|
68
68
|
case _models.ComponentTypes.EMAIL:
|
|
69
69
|
var userEmail = fd === null ? '' : (_fd$keycloakContext = fd.keycloakContext) === null || _fd$keycloakContext === void 0 ? void 0 : _fd$keycloakContext.email;
|
|
70
|
-
error = (0, _validateEmail.default)(value, component.label, userEmail);
|
|
70
|
+
error = (0, _validateEmail.default)(value, component.label, userEmail, component.custom_errors);
|
|
71
71
|
break;
|
|
72
72
|
|
|
73
73
|
case _models.ComponentTypes.DATE:
|
|
@@ -22,6 +22,7 @@ var HODS_EMAIL_REGEX = /^[a-z0-9._-]+@(digital\.)?homeoffice.gov.uk$/i;
|
|
|
22
22
|
var validateEmail = function validateEmail(value) {
|
|
23
23
|
var label = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
24
24
|
var userEmail = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
25
|
+
var customErrors = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
25
26
|
|
|
26
27
|
if (!!value) {
|
|
27
28
|
var name = label ? label.toLowerCase() : 'email address';
|
|
@@ -29,7 +30,7 @@ var validateEmail = function validateEmail(value) {
|
|
|
29
30
|
if (typeof value === 'string') {
|
|
30
31
|
// The following is an interim fix pending a mechanism for validating against specific values
|
|
31
32
|
if (['Line manager email', 'Delegate email address'].includes(label) && value.toLowerCase() === userEmail) {
|
|
32
|
-
return "".concat(label, " cannot be
|
|
33
|
+
return "".concat(label, " cannot be your own email");
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
if (HODS_EMAIL_REGEX.test(value)) {
|
|
@@ -37,6 +38,16 @@ var validateEmail = function validateEmail(value) {
|
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
|
|
41
|
+
if (Array.isArray(customErrors)) {
|
|
42
|
+
var result = customErrors.filter(function (error) {
|
|
43
|
+
return error.type === 'format';
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
if (result && result.length > 0 && result[0].message) {
|
|
47
|
+
return result[0].message;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
40
51
|
return "Enter ".concat(name, " in the correct format, like jane.doe@homeoffice.gov.uk");
|
|
41
52
|
}
|
|
42
53
|
|
|
@@ -52,12 +52,20 @@ 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 use a custom format error message when specified', function () {
|
|
56
|
+
var customErrors = [{
|
|
57
|
+
'type': 'format',
|
|
58
|
+
'message': 'Enter email address in the correct format'
|
|
59
|
+
}];
|
|
60
|
+
var CUSTOM_ERROR = 'Enter email address in the correct format';
|
|
61
|
+
expect((0, _validateEmail.default)('bob', '', '', customErrors)).toEqual(CUSTOM_ERROR);
|
|
62
|
+
});
|
|
55
63
|
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
|
|
64
|
+
var USER_EMAIL_ERROR = 'Line manager email cannot be your own email';
|
|
57
65
|
expect((0, _validateEmail.default)('joe.bloggs@digital.homeoffice.gov.uk', 'Line manager email', 'joe.bloggs@digital.homeoffice.gov.uk')).toEqual(USER_EMAIL_ERROR);
|
|
58
66
|
});
|
|
59
67
|
it('should return an error when delegate email is same as user email', function () {
|
|
60
|
-
var USER_EMAIL_ERROR = 'Delegate email address cannot be
|
|
68
|
+
var USER_EMAIL_ERROR = 'Delegate email address cannot be your own email';
|
|
61
69
|
expect((0, _validateEmail.default)('joe.bloggs@digital.homeoffice.gov.uk', 'Delegate email address', 'joe.bloggs@digital.homeoffice.gov.uk')).toEqual(USER_EMAIL_ERROR);
|
|
62
70
|
});
|
|
63
71
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ukhomeoffice/cop-react-form-renderer",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.41.0",
|
|
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.9.0",
|
|
20
20
|
"axios": "^0.23.0",
|
|
21
21
|
"dayjs": "^1.11.0",
|
|
22
22
|
"govuk-frontend": "^4.3.1",
|