@ukhomeoffice/cop-react-form-renderer 2.8.4 → 2.10.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 +8 -12
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +11 -9
- package/dist/components/FormComponent/Collection.js +244 -0
- package/dist/components/FormComponent/Collection.scss +23 -0
- package/dist/components/FormComponent/Container.js +110 -0
- package/dist/components/FormComponent/Container.test.js +26 -26
- package/dist/components/FormComponent/FormComponent.js +65 -128
- package/dist/components/FormComponent/FormComponent.test.js +19 -19
- package/dist/components/FormComponent/helpers/getComponentError.js +31 -0
- package/dist/components/FormComponent/helpers/getComponentError.test.js +52 -0
- package/dist/components/FormComponent/helpers/index.js +15 -0
- package/dist/components/FormPage/FormPage.js +7 -11
- package/dist/components/FormPage/FormPage.test.js +12 -76
- package/dist/components/FormRenderer/FormRenderer.js +103 -44
- package/dist/components/FormRenderer/helpers/canActionProceed.js +3 -12
- package/dist/components/FormRenderer/helpers/canActionProceed.test.js +41 -65
- package/dist/components/FormRenderer/helpers/canCYASubmit.js +3 -24
- package/dist/components/FormRenderer/helpers/canCYASubmit.test.js +72 -145
- package/dist/components/SummaryList/GroupAction.js +6 -2
- package/dist/components/SummaryList/SummaryList.js +33 -18
- package/dist/components/SummaryList/SummaryList.scss +12 -8
- package/dist/components/SummaryList/SummaryList.test.js +94 -27
- package/dist/components/SummaryList/SummaryListRow.js +51 -0
- package/dist/components/SummaryList/SummaryListTitleRow.js +30 -0
- package/dist/context/ValidationContext/ValidationContext.js +122 -0
- package/dist/context/ValidationContext/ValidationContext.test.js +98 -0
- package/dist/context/ValidationContext/index.js +23 -0
- package/dist/context/index.js +15 -0
- package/dist/hooks/index.js +8 -0
- package/dist/hooks/useValidation.js +19 -0
- package/dist/index.js +11 -5
- package/dist/json/group.json +1 -17
- package/dist/json/port.json +346 -0
- package/dist/json/sublocation.json +859 -0
- package/dist/json/terminal.json +81 -0
- package/dist/models/CollectionLabels.js +14 -0
- package/dist/models/ComponentTypes.js +2 -0
- package/dist/models/index.js +8 -0
- package/dist/setupTests.js +32 -0
- package/dist/utils/CheckYourAnswers/getCYARow.js +14 -0
- package/dist/utils/CheckYourAnswers/getCYARow.test.js +34 -11
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.js +1 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.js +89 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.test.js +194 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.test.js +9 -13
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +11 -4
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +58 -14
- package/dist/utils/Component/cleanAttributes.js +1 -1
- package/dist/utils/Component/getComponent.js +36 -3
- package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +92 -0
- package/dist/utils/Component/getDefaultValue.js +25 -0
- package/dist/utils/Component/getDefaultValue.test.js +53 -0
- package/dist/utils/Component/index.js +4 -1
- package/dist/utils/Meta/constants.js +10 -0
- package/dist/utils/Meta/documents/getDocuments.js +18 -0
- package/dist/utils/Meta/documents/getDocuments.test.js +43 -0
- package/dist/utils/Meta/documents/index.js +23 -0
- package/dist/utils/Meta/documents/setDocumentForField.js +36 -0
- package/dist/utils/Meta/documents/setDocumentForField.test.js +49 -0
- package/dist/utils/Meta/index.js +21 -0
- package/dist/utils/Validate/validateCollection.js +42 -0
- package/dist/utils/Validate/validateCollection.test.js +74 -0
- package/dist/utils/Validate/validateComponent.js +67 -48
- package/dist/utils/Validate/validateComponent.test.js +247 -188
- package/dist/utils/Validate/validateContainer.js +29 -0
- package/dist/utils/Validate/validateContainer.test.js +68 -0
- package/dist/utils/index.js +4 -1
- package/package.json +2 -2
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _validateContainer = _interopRequireDefault(require("./validateContainer"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
13
|
+
|
|
14
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
15
|
+
|
|
16
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
17
|
+
|
|
18
|
+
var validateCollection = function validateCollection(collection, items) {
|
|
19
|
+
var errors = [];
|
|
20
|
+
|
|
21
|
+
if (collection && Array.isArray(collection.item) && Array.isArray(items)) {
|
|
22
|
+
items.forEach(function (item, index) {
|
|
23
|
+
var full_path = "".concat(collection.full_path || collection.fieldId, "[").concat(index, "]");
|
|
24
|
+
var container = {
|
|
25
|
+
full_path: full_path,
|
|
26
|
+
components: collection.item.map(function (component) {
|
|
27
|
+
return _objectSpread(_objectSpread({}, component), {}, {
|
|
28
|
+
full_path: "".concat(full_path, ".").concat(component.fieldId)
|
|
29
|
+
});
|
|
30
|
+
})
|
|
31
|
+
};
|
|
32
|
+
errors.push((0, _validateContainer.default)(container, item));
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return errors.filter(function (e) {
|
|
37
|
+
return !!e;
|
|
38
|
+
}).flat();
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
var _default = validateCollection;
|
|
42
|
+
exports.default = _default;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _models = require("../../models");
|
|
4
|
+
|
|
5
|
+
var _validateCollection = _interopRequireDefault(require("./validateCollection"));
|
|
6
|
+
|
|
7
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
|
+
|
|
9
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
10
|
+
|
|
11
|
+
describe('utils.Validate.Collection', function () {
|
|
12
|
+
var setup = function setup(id, type, label, required, item) {
|
|
13
|
+
return {
|
|
14
|
+
id: id,
|
|
15
|
+
fieldId: id,
|
|
16
|
+
type: type,
|
|
17
|
+
label: label,
|
|
18
|
+
required: required,
|
|
19
|
+
item: item
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
it('should return an empty array when the component is null', function () {
|
|
24
|
+
expect((0, _validateCollection.default)(null, [])).toEqual([]);
|
|
25
|
+
});
|
|
26
|
+
it('should return an empty array when the collection has an undefined item array', function () {
|
|
27
|
+
var ID = 'collection';
|
|
28
|
+
var LABEL = 'field';
|
|
29
|
+
var COLLECTION = setup(ID, _models.ComponentTypes.COLLECTION, LABEL, false, undefined);
|
|
30
|
+
expect((0, _validateCollection.default)(COLLECTION, [])).toEqual([]);
|
|
31
|
+
});
|
|
32
|
+
it('should return an empty array when the collection has an empty item array', function () {
|
|
33
|
+
var ID = 'collection';
|
|
34
|
+
var LABEL = 'field';
|
|
35
|
+
var COLLECTION = setup(ID, _models.ComponentTypes.COLLECTION, LABEL, false, []);
|
|
36
|
+
expect((0, _validateCollection.default)(COLLECTION, [])).toEqual([]);
|
|
37
|
+
});
|
|
38
|
+
it('should return an empty array when the collection has only valid items', function () {
|
|
39
|
+
var EMAIL_ID = 'email';
|
|
40
|
+
var EMAIL_LABEL = 'Email';
|
|
41
|
+
var EMAIL = setup(EMAIL_ID, _models.ComponentTypes.EMAIL, EMAIL_LABEL, false);
|
|
42
|
+
var ID = 'collection';
|
|
43
|
+
var LABEL = 'field';
|
|
44
|
+
var COLLECTION = setup(ID, _models.ComponentTypes.COLLECTION, LABEL, false, [EMAIL]);
|
|
45
|
+
var ITEMS = [_defineProperty({}, EMAIL_ID, 'alpha.bravo@homeoffice.gov.uk'), _defineProperty({}, EMAIL_ID, 'charlie.delta@homeoffice.gov.uk')];
|
|
46
|
+
expect((0, _validateCollection.default)(COLLECTION, ITEMS)).toEqual([]);
|
|
47
|
+
});
|
|
48
|
+
it('should return an array containing an error when the collection has an invalid first item', function () {
|
|
49
|
+
var EMAIL_ID = 'email';
|
|
50
|
+
var EMAIL_LABEL = 'Email';
|
|
51
|
+
var EMAIL = setup(EMAIL_ID, _models.ComponentTypes.EMAIL, EMAIL_LABEL, false);
|
|
52
|
+
var ID = 'container';
|
|
53
|
+
var LABEL = 'field';
|
|
54
|
+
var COLLECTION = setup(ID, _models.ComponentTypes.CONTAINER, LABEL, false, [EMAIL]);
|
|
55
|
+
var ITEMS = [_defineProperty({}, EMAIL_ID, 'alpha.bravo@digital.homeoffice.com'), _defineProperty({}, EMAIL_ID, 'alpha.bravo@digital.homeoffice.gov.uk')];
|
|
56
|
+
expect((0, _validateCollection.default)(COLLECTION, ITEMS)).toEqual([{
|
|
57
|
+
id: "".concat(ID, "[0].").concat(EMAIL_ID),
|
|
58
|
+
error: "Enter ".concat(EMAIL_LABEL.toLowerCase(), " in the correct format, like jane.doe@homeoffice.gov.uk")
|
|
59
|
+
}]);
|
|
60
|
+
});
|
|
61
|
+
it('should return an array containing an error when the collection has an invalid second item', function () {
|
|
62
|
+
var EMAIL_ID = 'email';
|
|
63
|
+
var EMAIL_LABEL = 'Email';
|
|
64
|
+
var EMAIL = setup(EMAIL_ID, _models.ComponentTypes.EMAIL, EMAIL_LABEL, false);
|
|
65
|
+
var ID = 'container';
|
|
66
|
+
var LABEL = 'field';
|
|
67
|
+
var COLLECTION = setup(ID, _models.ComponentTypes.CONTAINER, LABEL, false, [EMAIL]);
|
|
68
|
+
var ITEMS = [_defineProperty({}, EMAIL_ID, 'alpha.bravo@digital.homeoffice.gov.uk'), _defineProperty({}, EMAIL_ID, 'alpha.bravo@digital.homeoffice.com')];
|
|
69
|
+
expect((0, _validateCollection.default)(COLLECTION, ITEMS)).toEqual([{
|
|
70
|
+
id: "".concat(ID, "[1].").concat(EMAIL_ID),
|
|
71
|
+
error: "Enter ".concat(EMAIL_LABEL.toLowerCase(), " in the correct format, like jane.doe@homeoffice.gov.uk")
|
|
72
|
+
}]);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -11,97 +11,116 @@ var _showComponent = _interopRequireDefault(require("../Component/showComponent"
|
|
|
11
11
|
|
|
12
12
|
var _additional = _interopRequireDefault(require("./additional"));
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var _validateCollection = _interopRequireDefault(require("./validateCollection"));
|
|
15
|
+
|
|
16
|
+
var _validateContainer = _interopRequireDefault(require("./validateContainer"));
|
|
17
|
+
|
|
18
|
+
var _validateDate = _interopRequireDefault(require("./validateDate"));
|
|
15
19
|
|
|
16
20
|
var _validateEmail = _interopRequireDefault(require("./validateEmail"));
|
|
17
21
|
|
|
18
22
|
var _validateRequired = _interopRequireDefault(require("./validateRequired"));
|
|
19
23
|
|
|
20
|
-
var
|
|
24
|
+
var _validateTime = _interopRequireDefault(require("./validateTime"));
|
|
21
25
|
|
|
22
26
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
27
|
|
|
24
28
|
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
25
29
|
|
|
26
|
-
var validateContainer = function validateContainer(container, formData) {
|
|
27
|
-
var errors = [];
|
|
28
|
-
|
|
29
|
-
if (Array.isArray(container.components)) {
|
|
30
|
-
var fd = formData && container.fieldId ? formData[container.fieldId] : formData;
|
|
31
|
-
container.components.forEach(function (component) {
|
|
32
|
-
errors.push(validateComponent(component, fd));
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return errors.filter(function (e) {
|
|
37
|
-
return !!e;
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
30
|
/**
|
|
41
31
|
* Validates a single component.
|
|
42
32
|
* @param {object} component The component to validate.
|
|
43
33
|
* @param {object} formData The data to use that holds this component's value.
|
|
44
34
|
* @returns The first encountered error with the component.
|
|
45
35
|
*/
|
|
36
|
+
var validateComponent = function validateComponent(component, formData) {
|
|
37
|
+
var _component$data$optio;
|
|
46
38
|
|
|
39
|
+
if (!(0, _showComponent.default)(component, formData)) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
47
42
|
|
|
48
|
-
var validateComponent = function validateComponent(component, formData) {
|
|
49
43
|
var error = undefined;
|
|
44
|
+
var nestedId = undefined;
|
|
45
|
+
var propertiesInError = undefined;
|
|
50
46
|
var data = formData && _typeof(formData) === 'object' ? formData : {};
|
|
51
47
|
|
|
52
|
-
if (component
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
48
|
+
if (component.type === _models.ComponentTypes.CONTAINER) {
|
|
49
|
+
return (0, _validateContainer.default)(component, formData);
|
|
50
|
+
}
|
|
56
51
|
|
|
57
|
-
|
|
58
|
-
delete component.propsInError;
|
|
52
|
+
var value = data[component.fieldId];
|
|
59
53
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
54
|
+
if (component.required) {
|
|
55
|
+
error = (0, _validateRequired.default)(value, component.label, component.custom_errors);
|
|
56
|
+
}
|
|
63
57
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
58
|
+
if (!error) {
|
|
59
|
+
switch (component.type) {
|
|
60
|
+
case _models.ComponentTypes.COLLECTION:
|
|
61
|
+
return (0, _validateCollection.default)(component, value);
|
|
67
62
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
propsInError = _validateDate.propsInError;
|
|
63
|
+
case _models.ComponentTypes.EMAIL:
|
|
64
|
+
error = (0, _validateEmail.default)(value, component.label);
|
|
65
|
+
break;
|
|
72
66
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
67
|
+
case _models.ComponentTypes.DATE:
|
|
68
|
+
case _models.ComponentTypes.TIME:
|
|
69
|
+
var validator = component.type === _models.ComponentTypes.DATE ? _validateDate.default : _validateTime.default;
|
|
70
|
+
|
|
71
|
+
var _validator = validator(value),
|
|
72
|
+
message = _validator.message,
|
|
73
|
+
propsInError = _validator.propsInError;
|
|
74
|
+
|
|
75
|
+
propertiesInError = propsInError;
|
|
76
|
+
error = message;
|
|
77
|
+
break;
|
|
76
78
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
_propsInError = _validateTime.propsInError;
|
|
79
|
+
case _models.ComponentTypes.RADIOS:
|
|
80
|
+
(_component$data$optio = component.data.options) === null || _component$data$optio === void 0 ? void 0 : _component$data$optio.some(function (option) {
|
|
81
|
+
var nestedError;
|
|
81
82
|
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
if (option.nested && option.nested.shown) {
|
|
84
|
+
var _nestedError;
|
|
85
|
+
|
|
86
|
+
nestedError = validateComponent(option.nested, formData);
|
|
87
|
+
error = (_nestedError = nestedError) === null || _nestedError === void 0 ? void 0 : _nestedError.error;
|
|
88
|
+
|
|
89
|
+
if (nestedError) {
|
|
90
|
+
nestedId = nestedError.id;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return nestedError;
|
|
95
|
+
});
|
|
96
|
+
break;
|
|
97
|
+
|
|
98
|
+
default:
|
|
99
|
+
break;
|
|
84
100
|
}
|
|
85
101
|
|
|
86
102
|
if (!error && component.additionalValidation) {
|
|
87
103
|
error = (0, _additional.default)(component, value);
|
|
88
104
|
|
|
89
105
|
if (component.type === _models.ComponentTypes.DATE && error) {
|
|
90
|
-
|
|
106
|
+
propertiesInError = {
|
|
91
107
|
day: true,
|
|
92
108
|
month: true,
|
|
93
109
|
year: true
|
|
94
110
|
};
|
|
95
111
|
}
|
|
96
112
|
}
|
|
113
|
+
}
|
|
97
114
|
|
|
98
|
-
|
|
115
|
+
if (error) {
|
|
116
|
+
return {
|
|
117
|
+
id: nestedId || component.full_path || component.id,
|
|
118
|
+
error: error,
|
|
119
|
+
properties: propertiesInError
|
|
120
|
+
};
|
|
99
121
|
}
|
|
100
122
|
|
|
101
|
-
return
|
|
102
|
-
id: component.id,
|
|
103
|
-
error: error
|
|
104
|
-
} : undefined;
|
|
123
|
+
return undefined;
|
|
105
124
|
};
|
|
106
125
|
|
|
107
126
|
var _default = validateComponent;
|