@ukhomeoffice/cop-react-form-renderer 5.80.1 → 5.81.2
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/CollectionSummary/SummaryCardDetails.js +1 -1
- package/dist/components/CollectionSummary/SummaryCardDetails.test.js +11 -10
- package/dist/components/FormComponent/Container.js +2 -1
- package/dist/components/FormComponent/Container.test.js +69 -0
- package/dist/utils/Validate/validateComponent.js +7 -2
- package/dist/utils/Validate/validateComponent.test.js +31 -0
- package/package.json +2 -2
|
@@ -168,7 +168,7 @@ var SummaryCardDetails = function SummaryCardDetails(_ref) {
|
|
|
168
168
|
className: classes('section')
|
|
169
169
|
}, !hideChildSectionTitles && /*#__PURE__*/_react.default.createElement("h3", {
|
|
170
170
|
className: classes('section-title')
|
|
171
|
-
}, section.title), /*#__PURE__*/_react.default.createElement("div", {
|
|
171
|
+
}, _utils.default.FormPage.getConditionalText(section.title, _objectSpread(_objectSpread({}, childPage.formData), entryData))), /*#__PURE__*/_react.default.createElement("div", {
|
|
172
172
|
className: classes('section-content'),
|
|
173
173
|
style: {
|
|
174
174
|
'--dividers': columns.length - 1
|
|
@@ -156,16 +156,21 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
156
156
|
expect(section1Content.textContent).toContain('subThreeLabel');
|
|
157
157
|
expect(section1Content.textContent).toContain('charlie');
|
|
158
158
|
});
|
|
159
|
-
it('should render sections containing collections based on summaryLayout config', function () {
|
|
159
|
+
it('should render sections containing collections with dynamic titles based on summaryLayout config', function () {
|
|
160
|
+
var FORM_DATA = {
|
|
161
|
+
dummyTitleContent: "Kellogg's"
|
|
162
|
+
};
|
|
160
163
|
var CHILD_PAGES = [{
|
|
161
164
|
summaryLayout: {
|
|
162
165
|
sections: [{
|
|
163
|
-
|
|
166
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
167
|
+
title: 'Section 1 - ${dummyTitleContent}',
|
|
164
168
|
columns: [{
|
|
165
169
|
fields: ['collectionComponent']
|
|
166
170
|
}]
|
|
167
171
|
}]
|
|
168
172
|
},
|
|
173
|
+
formData: FORM_DATA,
|
|
169
174
|
components: [{
|
|
170
175
|
fieldId: 'collectionComponent',
|
|
171
176
|
id: 'collectionComponent',
|
|
@@ -221,17 +226,13 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
221
226
|
})),
|
|
222
227
|
container = _renderWithValidation3.container;
|
|
223
228
|
|
|
224
|
-
// Function to find an element by its text content
|
|
225
|
-
function getByTextContent(parent, text) {
|
|
226
|
-
return Array.from(parent.getElementsByClassName(classes('section-title'))).find(function (el) {
|
|
227
|
-
return el.textContent === text;
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
|
|
231
229
|
// Check for section title
|
|
232
|
-
var section1Title =
|
|
230
|
+
var section1Title = container.querySelector(".".concat(classes('section-title')));
|
|
233
231
|
expect(section1Title).not.toBeUndefined();
|
|
234
232
|
|
|
233
|
+
// Check for embedded variables in title
|
|
234
|
+
expect(section1Title.textContent).toEqual("Section 1 - Kellogg's");
|
|
235
|
+
|
|
235
236
|
// All four subcomponents from the container should have labels and values displayed
|
|
236
237
|
var section1Content = section1Title.parentNode.querySelector(".".concat(classes('section-content')));
|
|
237
238
|
expect(section1Content.textContent).toContain('North');
|
|
@@ -11,6 +11,7 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
11
11
|
var _models = require("../../models");
|
|
12
12
|
var _utils = _interopRequireDefault(require("../../utils"));
|
|
13
13
|
var _FormComponent = _interopRequireDefault(require("./FormComponent"));
|
|
14
|
+
var _getSourceData = _interopRequireDefault(require("../../utils/Data/getSourceData"));
|
|
14
15
|
var _excluded = ["container", "value", "formData", "onChange", "wrap", "onTopLevelChange"]; // Global imports
|
|
15
16
|
// Local imports
|
|
16
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -58,7 +59,7 @@ var Container = function Container(_ref) {
|
|
|
58
59
|
}
|
|
59
60
|
return _utils.default.Component.show(_objectSpread(_objectSpread({}, options), {}, {
|
|
60
61
|
full_path: fullPath
|
|
61
|
-
}), formData);
|
|
62
|
+
}), _objectSpread(_objectSpread({}, formData), (0, _getSourceData.default)(formData, container.full_path)));
|
|
62
63
|
};
|
|
63
64
|
var classes = _utils.default.classBuilder(DEFAULT_CLASS, [], container.className);
|
|
64
65
|
var cleanedAttrs = _copReactComponents.Utils.cleanHtmlAttributes(attrs);
|
|
@@ -368,4 +368,73 @@ describe('components.FormComponent.Container', function () {
|
|
|
368
368
|
}
|
|
369
369
|
}, _callee7);
|
|
370
370
|
})));
|
|
371
|
+
it('should render a container component appropriately with show_whens referencing other components in the container', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
372
|
+
var _ID2;
|
|
373
|
+
var TEXT_COMPONENT_CONDITIONAL, FORM_DATA_CONDITIONAL, CONTAINER, _renderWithValidation8, container, c, formGroup, label, input, formGroup2, label2, input2;
|
|
374
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
375
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
376
|
+
case 0:
|
|
377
|
+
TEXT_COMPONENT_CONDITIONAL = {
|
|
378
|
+
id: 'textTwo',
|
|
379
|
+
fieldId: 'textTwo',
|
|
380
|
+
type: _models.ComponentTypes.TEXT,
|
|
381
|
+
label: 'Text component 2',
|
|
382
|
+
show_when: {
|
|
383
|
+
field: TEXT_ID,
|
|
384
|
+
op: '=',
|
|
385
|
+
value: 'other'
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
FORM_DATA_CONDITIONAL = _defineProperty({}, ID, (_ID2 = {}, _defineProperty(_ID2, TEXT_ID, 'other'), _defineProperty(_ID2, "textTwo", 'blue'), _ID2));
|
|
389
|
+
CONTAINER = {
|
|
390
|
+
id: ID,
|
|
391
|
+
fieldId: ID,
|
|
392
|
+
type: _models.ComponentTypes.CONTAINER,
|
|
393
|
+
components: [TEXT_COMPONENT, TEXT_COMPONENT_CONDITIONAL],
|
|
394
|
+
full_path: ID
|
|
395
|
+
};
|
|
396
|
+
_renderWithValidation8 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
397
|
+
component: CONTAINER,
|
|
398
|
+
value: FORM_DATA_CONDITIONAL[ID],
|
|
399
|
+
formData: FORM_DATA_CONDITIONAL
|
|
400
|
+
})), container = _renderWithValidation8.container; // Check the container itself.
|
|
401
|
+
c = container.childNodes[0];
|
|
402
|
+
expect(c.tagName).toEqual('DIV');
|
|
403
|
+
expect(c.classList).toContain(_Container.DEFAULT_CLASS);
|
|
404
|
+
|
|
405
|
+
// And now check the first text component within it.
|
|
406
|
+
formGroup = c.childNodes[0];
|
|
407
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
408
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
409
|
+
label = formGroup.childNodes[0];
|
|
410
|
+
expect(label.tagName).toEqual('LABEL');
|
|
411
|
+
expect(label.classList).toContain('govuk-label');
|
|
412
|
+
expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
413
|
+
expect(label.getAttribute('for')).toEqual("".concat(ID, ".").concat(TEXT_ID));
|
|
414
|
+
input = formGroup.childNodes[2];
|
|
415
|
+
expect(input.tagName).toEqual('INPUT');
|
|
416
|
+
expect(input.classList).toContain('govuk-input');
|
|
417
|
+
expect(input.id).toEqual("".concat(ID, ".").concat(TEXT_ID));
|
|
418
|
+
expect(input.value).toEqual('other');
|
|
419
|
+
|
|
420
|
+
// And now check the second text component within it that should have passed the show_when
|
|
421
|
+
formGroup2 = c.childNodes[1];
|
|
422
|
+
expect(formGroup2.tagName).toEqual('DIV');
|
|
423
|
+
expect(formGroup2.classList).toContain('govuk-form-group');
|
|
424
|
+
label2 = formGroup2.childNodes[0];
|
|
425
|
+
expect(label2.tagName).toEqual('LABEL');
|
|
426
|
+
expect(label2.classList).toContain('govuk-label');
|
|
427
|
+
expect(label2.textContent).toEqual("".concat(TEXT_COMPONENT.label, " 2 (optional)"));
|
|
428
|
+
expect(label2.getAttribute('for')).toEqual("".concat(ID, ".").concat(TEXT_ID, "Two"));
|
|
429
|
+
input2 = formGroup2.childNodes[2];
|
|
430
|
+
expect(input2.tagName).toEqual('INPUT');
|
|
431
|
+
expect(input2.classList).toContain('govuk-input');
|
|
432
|
+
expect(input2.id).toEqual("".concat(ID, ".").concat(TEXT_ID, "Two"));
|
|
433
|
+
expect(input2.value).toEqual('blue');
|
|
434
|
+
case 33:
|
|
435
|
+
case "end":
|
|
436
|
+
return _context8.stop();
|
|
437
|
+
}
|
|
438
|
+
}, _callee8);
|
|
439
|
+
})));
|
|
371
440
|
});
|
|
@@ -19,7 +19,12 @@ var _validateRequired = _interopRequireDefault(require("./validateRequired"));
|
|
|
19
19
|
var _validateTextArea = _interopRequireDefault(require("./validateTextArea"));
|
|
20
20
|
var _validateTime = _interopRequireDefault(require("./validateTime"));
|
|
21
21
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
22
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
23
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
24
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
25
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
26
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
27
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } // Local imports
|
|
23
28
|
/**
|
|
24
29
|
* Validates a single component.
|
|
25
30
|
* @param {object} component The component to validate.
|
|
@@ -29,7 +34,7 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
|
|
|
29
34
|
*/
|
|
30
35
|
var validateComponent = function validateComponent(component, outerData, formData) {
|
|
31
36
|
var fd = formData || outerData;
|
|
32
|
-
if (!(0, _showComponent.default)(component, fd)) {
|
|
37
|
+
if (!(0, _showComponent.default)(component, _objectSpread(_objectSpread({}, fd), outerData))) {
|
|
33
38
|
return undefined;
|
|
34
39
|
}
|
|
35
40
|
if (component.type === _models.ComponentTypes.CONTAINER) {
|
|
@@ -182,6 +182,37 @@ describe('utils.Validate.Component', function () {
|
|
|
182
182
|
var DATA = _defineProperty({}, ID, _defineProperty({}, EMAIL_ID, 'alpha.bravo@digital.homeoffice.gov.uk'));
|
|
183
183
|
expect((0, _validateComponent.default)(CONTAINER, DATA)).toEqual([]);
|
|
184
184
|
});
|
|
185
|
+
it('should return an empty array when the container has only valid components', function () {
|
|
186
|
+
var TEXT_COMPONENT = {
|
|
187
|
+
id: 'one',
|
|
188
|
+
fieldId: 'one',
|
|
189
|
+
type: _models.ComponentTypes.TEXT,
|
|
190
|
+
label: 'Text component one'
|
|
191
|
+
};
|
|
192
|
+
var TEXT_COMPONENT_TWO = {
|
|
193
|
+
id: 'two',
|
|
194
|
+
fieldId: 'two',
|
|
195
|
+
type: _models.ComponentTypes.TEXT,
|
|
196
|
+
label: 'Text component two',
|
|
197
|
+
required: true,
|
|
198
|
+
show_when: {
|
|
199
|
+
field: 'one',
|
|
200
|
+
op: '=',
|
|
201
|
+
value: 'other'
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
var ID = 'container';
|
|
205
|
+
var LABEL = 'field';
|
|
206
|
+
var CONTAINER = setup(ID, _models.ComponentTypes.CONTAINER, LABEL, false);
|
|
207
|
+
CONTAINER.components = [TEXT_COMPONENT, TEXT_COMPONENT_TWO];
|
|
208
|
+
var DATA = _defineProperty({}, ID, {
|
|
209
|
+
one: 'other'
|
|
210
|
+
});
|
|
211
|
+
var errors = (0, _validateComponent.default)(CONTAINER, DATA, {
|
|
212
|
+
colour: 'blue'
|
|
213
|
+
});
|
|
214
|
+
expect(errors.length).toEqual(1);
|
|
215
|
+
});
|
|
185
216
|
});
|
|
186
217
|
describe('when the component is a collection', function () {
|
|
187
218
|
it('should return an empty array when the collection has only valid items', function () {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ukhomeoffice/cop-react-form-renderer",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.81.2",
|
|
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": "3.
|
|
19
|
+
"@ukhomeoffice/cop-react-components": "3.23.0",
|
|
20
20
|
"axios": "^0.23.0",
|
|
21
21
|
"dayjs": "^1.11.0",
|
|
22
22
|
"govuk-frontend": "^4.3.1",
|