@ukhomeoffice/cop-react-form-renderer 2.8.5 → 2.10.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/CheckYourAnswers.js +8 -12
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +10 -8
- 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/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/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/Data/getSourceData.js +38 -0
- package/dist/utils/Data/getSourceData.test.js +16 -0
- 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 +3 -3
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
9
|
+
|
|
10
|
+
var _models = require("../../models");
|
|
11
|
+
|
|
12
|
+
var _getCYARowsForContainer = _interopRequireDefault(require("./getCYARowsForContainer"));
|
|
13
|
+
|
|
14
|
+
var _showComponentCYA = _interopRequireDefault(require("./showComponentCYA"));
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
|
|
18
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
19
|
+
|
|
20
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
21
|
+
|
|
22
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
23
|
+
|
|
24
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
25
|
+
|
|
26
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
27
|
+
|
|
28
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
29
|
+
|
|
30
|
+
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; }
|
|
31
|
+
|
|
32
|
+
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; }
|
|
33
|
+
|
|
34
|
+
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; }
|
|
35
|
+
|
|
36
|
+
var getContainerForItem = function getContainerForItem(collection, item, labelCount, full_path) {
|
|
37
|
+
return {
|
|
38
|
+
id: item.id,
|
|
39
|
+
fieldId: item.id,
|
|
40
|
+
type: _models.ComponentTypes.CONTAINER,
|
|
41
|
+
required: collection.required,
|
|
42
|
+
full_path: full_path,
|
|
43
|
+
components: collection.item.map(function (component) {
|
|
44
|
+
return _objectSpread(_objectSpread({}, component), {}, {
|
|
45
|
+
label: _copReactComponents.Utils.interpolateString(component.label, _objectSpread(_objectSpread({}, item), {}, {
|
|
46
|
+
index: labelCount
|
|
47
|
+
})),
|
|
48
|
+
full_path: "".concat(full_path, ".").concat(component.fieldId)
|
|
49
|
+
});
|
|
50
|
+
})
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
var getTitleRowForItem = function getTitleRowForItem(collection, item, pageId, labelCount, full_path) {
|
|
55
|
+
var labels = _objectSpread(_objectSpread({}, _models.CollectionLabels), collection.labels);
|
|
56
|
+
|
|
57
|
+
if (labels.item) {
|
|
58
|
+
return {
|
|
59
|
+
pageId: pageId,
|
|
60
|
+
fieldId: collection.fieldId,
|
|
61
|
+
full_path: full_path,
|
|
62
|
+
key: _copReactComponents.Utils.interpolateString(labels.item, _objectSpread(_objectSpread({}, item), {}, {
|
|
63
|
+
index: labelCount
|
|
64
|
+
})),
|
|
65
|
+
type: 'title',
|
|
66
|
+
action: null
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return null;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
var getCYARowsForCollection = function getCYARowsForCollection(page, collection, items, onAction) {
|
|
74
|
+
if (Array.isArray(items) && (0, _showComponentCYA.default)(collection, page.formData)) {
|
|
75
|
+
return items.flatMap(function (item, index) {
|
|
76
|
+
var labelCount = (collection.countOffset || 0) + index + 1;
|
|
77
|
+
var full_path = "".concat(collection.full_path || collection.fieldId, "[").concat(index, "]");
|
|
78
|
+
var container = getContainerForItem(collection, item, labelCount, full_path);
|
|
79
|
+
return [getTitleRowForItem(collection, item, page.id, labelCount, full_path)].concat(_toConsumableArray((0, _getCYARowsForContainer.default)(page, container, item, onAction)));
|
|
80
|
+
}).filter(function (r) {
|
|
81
|
+
return !!r;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return [];
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
var _default = getCYARowsForCollection;
|
|
89
|
+
exports.default = _default;
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _models = require("../../models");
|
|
4
|
+
|
|
5
|
+
var _setupTests = require("../../setupTests");
|
|
6
|
+
|
|
7
|
+
var _getCYARowsForCollection = _interopRequireDefault(require("./getCYARowsForCollection"));
|
|
8
|
+
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
|
|
11
|
+
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; }
|
|
12
|
+
|
|
13
|
+
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; }
|
|
14
|
+
|
|
15
|
+
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; }
|
|
16
|
+
|
|
17
|
+
describe('utils.CheckYourAnswers.getCYARowsForCollection', function () {
|
|
18
|
+
it('should get no rows when there are no items', function () {
|
|
19
|
+
var FORM_DATA = undefined;
|
|
20
|
+
var PAGE = {
|
|
21
|
+
id: 'page',
|
|
22
|
+
formData: FORM_DATA,
|
|
23
|
+
cya_link: {}
|
|
24
|
+
};
|
|
25
|
+
var COMPONENT = {
|
|
26
|
+
type: 'text',
|
|
27
|
+
readonly: true,
|
|
28
|
+
id: 'a',
|
|
29
|
+
fieldId: 'a',
|
|
30
|
+
label: 'Alpha'
|
|
31
|
+
};
|
|
32
|
+
var COLLECTION = {
|
|
33
|
+
id: 'collection',
|
|
34
|
+
fieldId: 'collection',
|
|
35
|
+
type: _models.ComponentTypes.COLLECTION,
|
|
36
|
+
item: [COMPONENT]
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
var ON_ACTION = function ON_ACTION() {};
|
|
40
|
+
|
|
41
|
+
var ROWS = (0, _getCYARowsForCollection.default)(PAGE, COLLECTION, undefined, ON_ACTION);
|
|
42
|
+
expect(ROWS.length).toEqual(0);
|
|
43
|
+
});
|
|
44
|
+
it('should get an appropriate row for a collection with a single readonly text component', function () {
|
|
45
|
+
var FORM_DATA = {
|
|
46
|
+
collection: [{
|
|
47
|
+
a: 'Bravo'
|
|
48
|
+
}]
|
|
49
|
+
};
|
|
50
|
+
var PAGE = {
|
|
51
|
+
id: 'page',
|
|
52
|
+
formData: FORM_DATA,
|
|
53
|
+
cya_link: {}
|
|
54
|
+
};
|
|
55
|
+
var COMPONENT = {
|
|
56
|
+
type: 'text',
|
|
57
|
+
readonly: true,
|
|
58
|
+
id: 'a',
|
|
59
|
+
fieldId: 'a',
|
|
60
|
+
label: 'Alpha'
|
|
61
|
+
};
|
|
62
|
+
var COLLECTION = {
|
|
63
|
+
id: 'collection',
|
|
64
|
+
fieldId: 'collection',
|
|
65
|
+
type: _models.ComponentTypes.COLLECTION,
|
|
66
|
+
countOffset: 22,
|
|
67
|
+
item: [COMPONENT],
|
|
68
|
+
value: FORM_DATA.collection,
|
|
69
|
+
formData: FORM_DATA
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
var ON_ACTION = function ON_ACTION() {};
|
|
73
|
+
|
|
74
|
+
var ROWS = (0, _getCYARowsForCollection.default)(PAGE, COLLECTION, FORM_DATA.collection, ON_ACTION);
|
|
75
|
+
expect(ROWS.length).toEqual(2); // Item title row + component row
|
|
76
|
+
|
|
77
|
+
(0, _setupTests.expectObjectLike)(ROWS[0], {
|
|
78
|
+
pageId: PAGE.id,
|
|
79
|
+
fieldId: COLLECTION.fieldId,
|
|
80
|
+
full_path: "".concat(COLLECTION.fieldId, "[0]"),
|
|
81
|
+
key: 'Item 23',
|
|
82
|
+
// includes countOffset
|
|
83
|
+
type: 'title',
|
|
84
|
+
action: null
|
|
85
|
+
});
|
|
86
|
+
(0, _setupTests.expectObjectLike)(ROWS[1], {
|
|
87
|
+
pageId: PAGE.id,
|
|
88
|
+
fieldId: COMPONENT.fieldId,
|
|
89
|
+
full_path: "".concat(COLLECTION.fieldId, "[0].").concat(COMPONENT.fieldId),
|
|
90
|
+
key: COMPONENT.label,
|
|
91
|
+
action: null,
|
|
92
|
+
component: _objectSpread(_objectSpread({}, COMPONENT), {}, {
|
|
93
|
+
full_path: "".concat(COLLECTION.fieldId, "[0].").concat(COMPONENT.fieldId)
|
|
94
|
+
}),
|
|
95
|
+
value: 'Bravo'
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
it('should get an appropriate row for a collection with a single readonly text component where the item label is an empty string', function () {
|
|
99
|
+
var FORM_DATA = {
|
|
100
|
+
collection: [{
|
|
101
|
+
a: 'Bravo'
|
|
102
|
+
}]
|
|
103
|
+
};
|
|
104
|
+
var PAGE = {
|
|
105
|
+
id: 'page',
|
|
106
|
+
formData: FORM_DATA,
|
|
107
|
+
cya_link: {}
|
|
108
|
+
};
|
|
109
|
+
var COMPONENT = {
|
|
110
|
+
type: 'text',
|
|
111
|
+
readonly: true,
|
|
112
|
+
id: 'a',
|
|
113
|
+
fieldId: 'a',
|
|
114
|
+
label: 'Alpha'
|
|
115
|
+
};
|
|
116
|
+
var COLLECTION = {
|
|
117
|
+
id: 'collection',
|
|
118
|
+
fieldId: 'collection',
|
|
119
|
+
type: _models.ComponentTypes.COLLECTION,
|
|
120
|
+
labels: {
|
|
121
|
+
item: ''
|
|
122
|
+
},
|
|
123
|
+
countOffset: 22,
|
|
124
|
+
item: [COMPONENT],
|
|
125
|
+
value: FORM_DATA.collection,
|
|
126
|
+
formData: FORM_DATA
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
var ON_ACTION = function ON_ACTION() {};
|
|
130
|
+
|
|
131
|
+
var ROWS = (0, _getCYARowsForCollection.default)(PAGE, COLLECTION, FORM_DATA.collection, ON_ACTION);
|
|
132
|
+
expect(ROWS.length).toEqual(1); // Just the component row, no title row
|
|
133
|
+
|
|
134
|
+
(0, _setupTests.expectObjectLike)(ROWS[0], {
|
|
135
|
+
pageId: PAGE.id,
|
|
136
|
+
fieldId: COMPONENT.fieldId,
|
|
137
|
+
full_path: "".concat(COLLECTION.fieldId, "[0].").concat(COMPONENT.fieldId),
|
|
138
|
+
key: COMPONENT.label,
|
|
139
|
+
action: null,
|
|
140
|
+
component: _objectSpread(_objectSpread({}, COMPONENT), {}, {
|
|
141
|
+
full_path: "".concat(COLLECTION.fieldId, "[0].").concat(COMPONENT.fieldId)
|
|
142
|
+
}),
|
|
143
|
+
value: 'Bravo'
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
it('should interpolate a field label appropriately', function () {
|
|
147
|
+
var FORM_DATA = {
|
|
148
|
+
collection: [{
|
|
149
|
+
a: 'Bravo'
|
|
150
|
+
}]
|
|
151
|
+
};
|
|
152
|
+
var PAGE = {
|
|
153
|
+
id: 'page',
|
|
154
|
+
formData: FORM_DATA,
|
|
155
|
+
cya_link: {}
|
|
156
|
+
}; // eslint-disable-next-line no-template-curly-in-string
|
|
157
|
+
|
|
158
|
+
var COMPONENT = {
|
|
159
|
+
type: 'text',
|
|
160
|
+
readonly: true,
|
|
161
|
+
id: 'a',
|
|
162
|
+
fieldId: 'a',
|
|
163
|
+
label: 'Alpha ${index}'
|
|
164
|
+
};
|
|
165
|
+
var COLLECTION = {
|
|
166
|
+
id: 'collection',
|
|
167
|
+
fieldId: 'collection',
|
|
168
|
+
type: _models.ComponentTypes.COLLECTION,
|
|
169
|
+
item: [COMPONENT],
|
|
170
|
+
value: FORM_DATA.collection,
|
|
171
|
+
formData: FORM_DATA
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
var ON_ACTION = function ON_ACTION() {};
|
|
175
|
+
|
|
176
|
+
var ROWS = (0, _getCYARowsForCollection.default)(PAGE, COLLECTION, FORM_DATA.collection, ON_ACTION);
|
|
177
|
+
expect(ROWS.length).toEqual(2); // Title and item row.
|
|
178
|
+
|
|
179
|
+
(0, _setupTests.expectObjectLike)(ROWS[1], {
|
|
180
|
+
pageId: PAGE.id,
|
|
181
|
+
fieldId: COMPONENT.fieldId,
|
|
182
|
+
full_path: "".concat(COLLECTION.fieldId, "[0].").concat(COMPONENT.fieldId),
|
|
183
|
+
key: 'Alpha 1',
|
|
184
|
+
// no countOffset
|
|
185
|
+
action: null,
|
|
186
|
+
component: _objectSpread(_objectSpread({}, COMPONENT), {}, {
|
|
187
|
+
full_path: "".concat(COLLECTION.fieldId, "[0].").concat(COMPONENT.fieldId),
|
|
188
|
+
label: 'Alpha 1' // no countOffset
|
|
189
|
+
|
|
190
|
+
}),
|
|
191
|
+
value: 'Bravo'
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
});
|
|
@@ -2,18 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
var _models = require("../../models");
|
|
4
4
|
|
|
5
|
+
var _setupTests = require("../../setupTests");
|
|
6
|
+
|
|
5
7
|
var _getCYARowsForContainer = _interopRequireDefault(require("./getCYARowsForContainer"));
|
|
6
8
|
|
|
7
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
10
|
|
|
9
11
|
// Local imports
|
|
10
12
|
describe('utils.CheckYourAnswers.getCYARowsForContainer', function () {
|
|
11
|
-
var expectObjectLike = function expectObjectLike(received, expected) {
|
|
12
|
-
Object.keys(expected).forEach(function (key) {
|
|
13
|
-
expect(received[key]).toEqual(expected[key]);
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
|
|
17
13
|
it('should get an appropriate row for a container with a single readonly text component', function () {
|
|
18
14
|
var FORM_DATA = {
|
|
19
15
|
container: {
|
|
@@ -46,7 +42,7 @@ describe('utils.CheckYourAnswers.getCYARowsForContainer', function () {
|
|
|
46
42
|
var ROWS = (0, _getCYARowsForContainer.default)(PAGE, CONTAINER, FORM_DATA.container, ON_ACTION);
|
|
47
43
|
expect(ROWS.length).toEqual(1);
|
|
48
44
|
ROWS.forEach(function (row, index) {
|
|
49
|
-
expectObjectLike(row, {
|
|
45
|
+
(0, _setupTests.expectObjectLike)(row, {
|
|
50
46
|
pageId: PAGE.id,
|
|
51
47
|
fieldId: CONTAINER.components[index].fieldId,
|
|
52
48
|
key: CONTAINER.components[index].label,
|
|
@@ -94,14 +90,14 @@ describe('utils.CheckYourAnswers.getCYARowsForContainer', function () {
|
|
|
94
90
|
var ROWS = (0, _getCYARowsForContainer.default)(PAGE, CONTAINER, FORM_DATA.container, ON_ACTION);
|
|
95
91
|
expect(ROWS.length).toEqual(2);
|
|
96
92
|
ROWS.forEach(function (row, index) {
|
|
97
|
-
expectObjectLike(row, {
|
|
93
|
+
(0, _setupTests.expectObjectLike)(row, {
|
|
98
94
|
pageId: PAGE.id,
|
|
99
95
|
fieldId: CONTAINER.components[index].fieldId,
|
|
100
96
|
key: CONTAINER.components[index].label,
|
|
101
97
|
component: CONTAINER.components[index],
|
|
102
98
|
value: "".concat(CONTAINER.components[index].label, " Charlie")
|
|
103
99
|
});
|
|
104
|
-
expectObjectLike(row.action, {
|
|
100
|
+
(0, _setupTests.expectObjectLike)(row.action, {
|
|
105
101
|
onAction: ON_ACTION
|
|
106
102
|
});
|
|
107
103
|
});
|
|
@@ -148,14 +144,14 @@ describe('utils.CheckYourAnswers.getCYARowsForContainer', function () {
|
|
|
148
144
|
var ROWS = (0, _getCYARowsForContainer.default)(PAGE, CONTAINER, FORM_DATA.container, ON_ACTION);
|
|
149
145
|
expect(ROWS.length).toEqual(2);
|
|
150
146
|
ROWS.forEach(function (row, index) {
|
|
151
|
-
expectObjectLike(row, {
|
|
147
|
+
(0, _setupTests.expectObjectLike)(row, {
|
|
152
148
|
pageId: PAGE.id,
|
|
153
149
|
fieldId: CONTAINER.components[index].fieldId,
|
|
154
150
|
key: CONTAINER.components[index].label,
|
|
155
151
|
component: CONTAINER.components[index],
|
|
156
152
|
value: "".concat(CONTAINER.components[index].label, " Charlie")
|
|
157
153
|
});
|
|
158
|
-
expectObjectLike(row.action, {
|
|
154
|
+
(0, _setupTests.expectObjectLike)(row.action, {
|
|
159
155
|
onAction: ON_ACTION
|
|
160
156
|
});
|
|
161
157
|
});
|
|
@@ -202,7 +198,7 @@ describe('utils.CheckYourAnswers.getCYARowsForContainer', function () {
|
|
|
202
198
|
var ROWS = (0, _getCYARowsForContainer.default)(PAGE, CONTAINER, FORM_DATA.container, ON_ACTION);
|
|
203
199
|
expect(ROWS.length).toEqual(1);
|
|
204
200
|
ROWS.forEach(function (row, index) {
|
|
205
|
-
expectObjectLike(row, {
|
|
201
|
+
(0, _setupTests.expectObjectLike)(row, {
|
|
206
202
|
pageId: PAGE.id,
|
|
207
203
|
fieldId: NESTED_CONTAINER.components[index].fieldId,
|
|
208
204
|
key: NESTED_CONTAINER.components[index].label,
|
|
@@ -244,7 +240,7 @@ describe('utils.CheckYourAnswers.getCYARowsForContainer', function () {
|
|
|
244
240
|
var ROWS = (0, _getCYARowsForContainer.default)(PAGE, CONTAINER, undefined, ON_ACTION);
|
|
245
241
|
expect(ROWS.length).toEqual(1);
|
|
246
242
|
ROWS.forEach(function (row, index) {
|
|
247
|
-
expectObjectLike(row, {
|
|
243
|
+
(0, _setupTests.expectObjectLike)(row, {
|
|
248
244
|
pageId: PAGE.id,
|
|
249
245
|
fieldId: NESTED_CONTAINER.components[index].fieldId,
|
|
250
246
|
key: NESTED_CONTAINER.components[index].label,
|
|
@@ -13,6 +13,8 @@ var _getCYARow = _interopRequireDefault(require("./getCYARow"));
|
|
|
13
13
|
|
|
14
14
|
var _getCYARowForGroup2 = _interopRequireDefault(require("./getCYARowForGroup"));
|
|
15
15
|
|
|
16
|
+
var _getCYARowsForCollection = _interopRequireDefault(require("./getCYARowsForCollection"));
|
|
17
|
+
|
|
16
18
|
var _getCYARowsForContainer = _interopRequireDefault(require("./getCYARowsForContainer"));
|
|
17
19
|
|
|
18
20
|
var _showComponentCYA = _interopRequireDefault(require("./showComponentCYA"));
|
|
@@ -36,11 +38,16 @@ var getCYARowsForPage = function getCYARowsForPage(page, onAction) {
|
|
|
36
38
|
var rows = page.components.filter(function (c) {
|
|
37
39
|
return (0, _showComponentCYA.default)(c, page.formData);
|
|
38
40
|
}).flatMap(function (component) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
switch (component.type) {
|
|
42
|
+
case _models.ComponentTypes.CONTAINER:
|
|
43
|
+
return (0, _getCYARowsForContainer.default)(page, component, page.formData[component.fieldId], onAction);
|
|
42
44
|
|
|
43
|
-
|
|
45
|
+
case _models.ComponentTypes.COLLECTION:
|
|
46
|
+
return (0, _getCYARowsForCollection.default)(page, component, page.formData[component.fieldId], onAction);
|
|
47
|
+
|
|
48
|
+
default:
|
|
49
|
+
return (0, _getCYARow.default)(page, component, onAction);
|
|
50
|
+
}
|
|
44
51
|
});
|
|
45
52
|
|
|
46
53
|
if (((_page$groups = page.groups) === null || _page$groups === void 0 ? void 0 : _page$groups.length) > 0) {
|
|
@@ -2,23 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
var _react = require("@testing-library/react");
|
|
4
4
|
|
|
5
|
+
var _setupTests = require("../../setupTests");
|
|
6
|
+
|
|
5
7
|
var _models = require("../../models");
|
|
6
8
|
|
|
7
9
|
var _getCYARowsForPage = _interopRequireDefault(require("./getCYARowsForPage"));
|
|
8
10
|
|
|
9
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
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; }
|
|
14
|
+
|
|
15
|
+
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; }
|
|
16
|
+
|
|
17
|
+
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; }
|
|
18
|
+
|
|
13
19
|
describe('utils', function () {
|
|
14
20
|
describe('CheckYourAnswers', function () {
|
|
15
21
|
describe('getCYARowsForPage', function () {
|
|
16
|
-
var expectObjectLike = function expectObjectLike(received, expected) {
|
|
17
|
-
Object.keys(expected).forEach(function (key) {
|
|
18
|
-
expect(received[key]).toEqual(expected[key]);
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
|
|
22
22
|
it('should get a appropriate row for a page with a single readonly text component', function () {
|
|
23
23
|
var COMPONENT = {
|
|
24
24
|
type: 'text',
|
|
@@ -40,7 +40,7 @@ describe('utils', function () {
|
|
|
40
40
|
var ROWS = (0, _getCYARowsForPage.default)(PAGE, ON_ACTION);
|
|
41
41
|
expect(ROWS.length).toEqual(1);
|
|
42
42
|
ROWS.forEach(function (row, index) {
|
|
43
|
-
expectObjectLike(row, {
|
|
43
|
+
(0, _setupTests.expectObjectLike)(row, {
|
|
44
44
|
pageId: PAGE.id,
|
|
45
45
|
fieldId: PAGE.components[index].fieldId,
|
|
46
46
|
key: PAGE.components[index].label,
|
|
@@ -78,14 +78,14 @@ describe('utils', function () {
|
|
|
78
78
|
var ROWS = (0, _getCYARowsForPage.default)(PAGE, ON_ACTION);
|
|
79
79
|
expect(ROWS.length).toEqual(2);
|
|
80
80
|
ROWS.forEach(function (row, index) {
|
|
81
|
-
expectObjectLike(row, {
|
|
81
|
+
(0, _setupTests.expectObjectLike)(row, {
|
|
82
82
|
pageId: PAGE.id,
|
|
83
83
|
fieldId: PAGE.components[index].fieldId,
|
|
84
84
|
key: PAGE.components[index].label,
|
|
85
85
|
component: PAGE.components[index],
|
|
86
86
|
value: "".concat(PAGE.components[index].label, " Charlie")
|
|
87
87
|
});
|
|
88
|
-
expectObjectLike(row.action, {
|
|
88
|
+
(0, _setupTests.expectObjectLike)(row.action, {
|
|
89
89
|
onAction: ON_ACTION
|
|
90
90
|
});
|
|
91
91
|
});
|
|
@@ -122,14 +122,14 @@ describe('utils', function () {
|
|
|
122
122
|
var ROWS = (0, _getCYARowsForPage.default)(PAGE, ON_ACTION);
|
|
123
123
|
expect(ROWS.length).toEqual(2);
|
|
124
124
|
ROWS.forEach(function (row, index) {
|
|
125
|
-
expectObjectLike(row, {
|
|
125
|
+
(0, _setupTests.expectObjectLike)(row, {
|
|
126
126
|
pageId: PAGE.id,
|
|
127
127
|
fieldId: PAGE.components[index].fieldId,
|
|
128
128
|
key: PAGE.components[index].label,
|
|
129
129
|
component: PAGE.components[index],
|
|
130
130
|
value: "".concat(PAGE.components[index].label, " Charlie")
|
|
131
131
|
});
|
|
132
|
-
expectObjectLike(row.action, {
|
|
132
|
+
(0, _setupTests.expectObjectLike)(row.action, {
|
|
133
133
|
onAction: ON_ACTION
|
|
134
134
|
});
|
|
135
135
|
});
|
|
@@ -166,7 +166,7 @@ describe('utils', function () {
|
|
|
166
166
|
var ROWS = (0, _getCYARowsForPage.default)(PAGE, ON_ACTION);
|
|
167
167
|
expect(ROWS.length).toEqual(1);
|
|
168
168
|
ROWS.forEach(function (row, index) {
|
|
169
|
-
expectObjectLike(row, {
|
|
169
|
+
(0, _setupTests.expectObjectLike)(row, {
|
|
170
170
|
pageId: PAGE.id,
|
|
171
171
|
fieldId: CONTAINER.components[index].fieldId,
|
|
172
172
|
key: CONTAINER.components[index].label,
|
|
@@ -234,6 +234,50 @@ describe('utils', function () {
|
|
|
234
234
|
expect(addressValues[2].childNodes[0].textContent).toEqual('London');
|
|
235
235
|
expect(addressValues[3].childNodes[0].textContent).toEqual('SW1A 2AA');
|
|
236
236
|
});
|
|
237
|
+
it('should get appropriate rows for a page with a single readonly text component within a collection', function () {
|
|
238
|
+
var FORM_DATA = {
|
|
239
|
+
collection: [{
|
|
240
|
+
a: 'Bravo'
|
|
241
|
+
}]
|
|
242
|
+
};
|
|
243
|
+
var COMPONENT = {
|
|
244
|
+
type: 'text',
|
|
245
|
+
readonly: true,
|
|
246
|
+
id: 'a',
|
|
247
|
+
fieldId: 'a',
|
|
248
|
+
label: 'Alpha'
|
|
249
|
+
};
|
|
250
|
+
var COLLECTION = {
|
|
251
|
+
id: 'collection',
|
|
252
|
+
fieldId: 'collection',
|
|
253
|
+
type: _models.ComponentTypes.COLLECTION,
|
|
254
|
+
item: [COMPONENT],
|
|
255
|
+
value: FORM_DATA.collection,
|
|
256
|
+
formData: FORM_DATA
|
|
257
|
+
};
|
|
258
|
+
var PAGE = {
|
|
259
|
+
id: 'page',
|
|
260
|
+
components: [COLLECTION],
|
|
261
|
+
formData: FORM_DATA
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
var ON_ACTION = function ON_ACTION() {};
|
|
265
|
+
|
|
266
|
+
var ROWS = (0, _getCYARowsForPage.default)(PAGE, ON_ACTION);
|
|
267
|
+
expect(ROWS.length).toEqual(2); // Title and item row
|
|
268
|
+
|
|
269
|
+
(0, _setupTests.expectObjectLike)(ROWS[1], {
|
|
270
|
+
pageId: PAGE.id,
|
|
271
|
+
fieldId: COMPONENT.fieldId,
|
|
272
|
+
full_path: "".concat(COLLECTION.fieldId, "[0].").concat(COMPONENT.fieldId),
|
|
273
|
+
key: COMPONENT.label,
|
|
274
|
+
action: null,
|
|
275
|
+
component: _objectSpread(_objectSpread({}, COMPONENT), {}, {
|
|
276
|
+
full_path: "".concat(COLLECTION.fieldId, "[0].").concat(COMPONENT.fieldId)
|
|
277
|
+
}),
|
|
278
|
+
value: 'Bravo'
|
|
279
|
+
});
|
|
280
|
+
});
|
|
237
281
|
});
|
|
238
282
|
});
|
|
239
283
|
});
|
|
@@ -19,7 +19,7 @@ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToAr
|
|
|
19
19
|
|
|
20
20
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
21
21
|
|
|
22
|
-
var JSON_ONLY_PROPERTIES = ['source', 'use', 'show_when', 'options', 'additionalValidation', 'full_path'];
|
|
22
|
+
var JSON_ONLY_PROPERTIES = ['source', 'use', 'show_when', 'options', 'additionalValidation', 'full_path', 'shown', 'formData'];
|
|
23
23
|
/**
|
|
24
24
|
* This method removes and properties that are entirely specific to the JSON
|
|
25
25
|
* configuration and that should not be used as HTML attributes.
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = void 0;
|
|
6
|
+
exports.getNestedComponent = exports.default = void 0;
|
|
7
7
|
|
|
8
8
|
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
9
9
|
|
|
@@ -84,6 +84,13 @@ var getRadios = function getRadios(config) {
|
|
|
84
84
|
options = val;
|
|
85
85
|
});
|
|
86
86
|
|
|
87
|
+
options.forEach(function (option) {
|
|
88
|
+
if (!option.nested) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
option.nestedJSX = getNestedComponent(config, option);
|
|
93
|
+
});
|
|
87
94
|
var attrs = (0, _cleanAttributes.default)(config);
|
|
88
95
|
return /*#__PURE__*/_react.default.createElement(_copReactComponents.Radios, _extends({}, attrs, {
|
|
89
96
|
options: options
|
|
@@ -148,6 +155,34 @@ var getComponentByType = function getComponentByType(config) {
|
|
|
148
155
|
}
|
|
149
156
|
}
|
|
150
157
|
};
|
|
158
|
+
/**
|
|
159
|
+
* Get nested component with form data
|
|
160
|
+
* @param {*} parentConfig
|
|
161
|
+
* @param {*} nestedConfig
|
|
162
|
+
*/
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
var getNestedComponent = function getNestedComponent(parentConfig, nestedConfig) {
|
|
166
|
+
nestedConfig.nested.onChange = parentConfig.onChange;
|
|
167
|
+
|
|
168
|
+
if (parentConfig.formData) {
|
|
169
|
+
var _parentConfig$formDat;
|
|
170
|
+
|
|
171
|
+
nestedConfig.nested.value = parentConfig !== null && parentConfig !== void 0 && (_parentConfig$formDat = parentConfig.formData) !== null && _parentConfig$formDat !== void 0 && _parentConfig$formDat[nestedConfig.nested.fieldId] ? parentConfig.formData[nestedConfig.nested.fieldId] : '';
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if ('readonly' in nestedConfig.nested) delete nestedConfig.nested.readonly;
|
|
175
|
+
|
|
176
|
+
if (parentConfig.readonly) {
|
|
177
|
+
nestedConfig.nested.readonly = parentConfig.readonly;
|
|
178
|
+
return getComponent(nestedConfig.nested, false);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return getComponent(nestedConfig.nested);
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
exports.getNestedComponent = getNestedComponent;
|
|
185
|
+
|
|
151
186
|
/**
|
|
152
187
|
* Get a renderable component, based on a configuration object.
|
|
153
188
|
* @param {object} config The configuration object for the component.
|
|
@@ -155,8 +190,6 @@ var getComponentByType = function getComponentByType(config) {
|
|
|
155
190
|
* @param {Function} fnOverride An optional override function for component rendering.
|
|
156
191
|
* @returns A renderable component.
|
|
157
192
|
*/
|
|
158
|
-
|
|
159
|
-
|
|
160
193
|
var getComponent = function getComponent(config) {
|
|
161
194
|
var wrap = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
162
195
|
var fnOverride = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
|