@ukhomeoffice/cop-react-form-renderer 2.6.1 → 2.7.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/Answer.js +3 -1
- package/dist/components/CheckYourAnswers/Answer.test.js +3 -2
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +45 -5
- package/dist/components/CheckYourAnswers/CheckYourAnswers.scss +10 -0
- package/dist/components/CheckYourAnswers/CheckYourAnswers.stories.mdx +331 -269
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +74 -12
- package/dist/components/FormComponent/Container.test.js +89 -10
- package/dist/components/FormComponent/FormComponent.js +63 -14
- package/dist/components/FormRenderer/FormRenderer.test.js +1 -1
- package/dist/components/FormRenderer/helpers/canActionProceed.js +1 -1
- package/dist/components/FormRenderer/helpers/canCYASubmit.js +1 -1
- package/dist/components/SummaryList/GroupAction.js +68 -0
- package/dist/components/SummaryList/GroupAction.test.js +94 -0
- package/dist/components/SummaryList/SummaryList.js +15 -4
- package/dist/components/SummaryList/SummaryList.scss +29 -5
- package/dist/components/SummaryList/SummaryList.test.js +47 -4
- package/dist/components/SummaryList/helpers/getGroupActionAttributes.js +27 -0
- package/dist/components/SummaryList/helpers/getGroupActionAttributes.test.js +77 -0
- package/dist/json/groupOfRow.json +158 -0
- package/dist/json/groupOfRowData.json +15 -0
- package/dist/models/ComponentTypes.js +2 -0
- package/dist/utils/Component/getComponent.js +13 -5
- package/dist/utils/Component/getComponentTests/getComponent.file.test.js +81 -0
- package/dist/utils/Component/isEditable.js +1 -1
- package/dist/utils/Data/index.js +3 -0
- package/dist/utils/Data/setDataItem.js +29 -0
- package/dist/utils/Data/setDataItem.test.js +112 -0
- package/dist/utils/Validate/validatePage.js +7 -6
- package/dist/utils/Validate/validatePage.test.js +60 -12
- package/package.json +2 -2
|
@@ -22,6 +22,8 @@ var _userProfileData = _interopRequireDefault(require("../../json/userProfile.da
|
|
|
22
22
|
|
|
23
23
|
var _userProfile = _interopRequireDefault(require("../../json/userProfile.json"));
|
|
24
24
|
|
|
25
|
+
var _groupOfRow = _interopRequireDefault(require("../../json/groupOfRow.json"));
|
|
26
|
+
|
|
25
27
|
var _utils = _interopRequireDefault(require("../../utils"));
|
|
26
28
|
|
|
27
29
|
var _CheckYourAnswers = _interopRequireWildcard(require("./CheckYourAnswers"));
|
|
@@ -198,7 +200,7 @@ describe('components', function () {
|
|
|
198
200
|
}, _callee4);
|
|
199
201
|
})));
|
|
200
202
|
it('should show readonly page components correctly', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() {
|
|
201
|
-
var cya, _cya$childNodes, names, _names$childNodes, firstName, surname;
|
|
203
|
+
var cya, _cya$childNodes, cyaChildNode, names, _names$childNodes, firstName, surname;
|
|
202
204
|
|
|
203
205
|
return regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
204
206
|
while (1) {
|
|
@@ -226,14 +228,15 @@ describe('components', function () {
|
|
|
226
228
|
|
|
227
229
|
case 2:
|
|
228
230
|
cya = checkCYA(container);
|
|
229
|
-
_cya$childNodes = _slicedToArray(cya.childNodes, 2),
|
|
231
|
+
_cya$childNodes = _slicedToArray(cya.childNodes, 2), cyaChildNode = _cya$childNodes[1];
|
|
232
|
+
names = cyaChildNode.childNodes[0];
|
|
230
233
|
expect(names.tagName).toEqual('DL');
|
|
231
234
|
expect(names.classList).toContain("govuk-!-margin-bottom-".concat(_CheckYourAnswers.DEFAULT_MARGIN_BOTTOM));
|
|
232
235
|
_names$childNodes = _slicedToArray(names.childNodes, 2), firstName = _names$childNodes[0], surname = _names$childNodes[1];
|
|
233
236
|
checkRow(firstName, 'First name', 'John', false);
|
|
234
237
|
checkRow(surname, 'Last name', 'Smith', false);
|
|
235
238
|
|
|
236
|
-
case
|
|
239
|
+
case 10:
|
|
237
240
|
case "end":
|
|
238
241
|
return _context6.stop();
|
|
239
242
|
}
|
|
@@ -241,7 +244,7 @@ describe('components', function () {
|
|
|
241
244
|
}, _callee6);
|
|
242
245
|
})));
|
|
243
246
|
it('should show editable page components correctly', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8() {
|
|
244
|
-
var cya, _cya$childNodes2, title, civilServant, _civilServant$childNo, status;
|
|
247
|
+
var cya, _cya$childNodes2, title, cyaChildNode, civilServant, _civilServant$childNo, status;
|
|
245
248
|
|
|
246
249
|
return regeneratorRuntime.wrap(function _callee8$(_context8) {
|
|
247
250
|
while (1) {
|
|
@@ -269,14 +272,15 @@ describe('components', function () {
|
|
|
269
272
|
|
|
270
273
|
case 2:
|
|
271
274
|
cya = checkCYA(container);
|
|
272
|
-
_cya$childNodes2 = _slicedToArray(cya.childNodes, 4), title = _cya$childNodes2[2],
|
|
275
|
+
_cya$childNodes2 = _slicedToArray(cya.childNodes, 4), title = _cya$childNodes2[2], cyaChildNode = _cya$childNodes2[3];
|
|
276
|
+
civilServant = cyaChildNode.childNodes[0];
|
|
273
277
|
expect(title.textContent).toEqual('Are you a civil servant?');
|
|
274
278
|
expect(civilServant.tagName).toEqual('DL');
|
|
275
279
|
expect(civilServant.classList).toContain("govuk-!-margin-bottom-".concat(_CheckYourAnswers.DEFAULT_MARGIN_BOTTOM));
|
|
276
280
|
_civilServant$childNo = _slicedToArray(civilServant.childNodes, 1), status = _civilServant$childNo[0];
|
|
277
281
|
checkRow(status, 'Are you a civil servant?', 'Yes', true);
|
|
278
282
|
|
|
279
|
-
case
|
|
283
|
+
case 10:
|
|
280
284
|
case "end":
|
|
281
285
|
return _context8.stop();
|
|
282
286
|
}
|
|
@@ -284,7 +288,7 @@ describe('components', function () {
|
|
|
284
288
|
}, _callee8);
|
|
285
289
|
})));
|
|
286
290
|
it('should show editable page components correctly with page titles hidden', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee10() {
|
|
287
|
-
var cya, _cya$childNodes3, civilServant, _civilServant$childNo2, status;
|
|
291
|
+
var cya, _cya$childNodes3, cyaChildNode, civilServant, _civilServant$childNo2, status;
|
|
288
292
|
|
|
289
293
|
return regeneratorRuntime.wrap(function _callee10$(_context10) {
|
|
290
294
|
while (1) {
|
|
@@ -313,15 +317,16 @@ describe('components', function () {
|
|
|
313
317
|
|
|
314
318
|
case 2:
|
|
315
319
|
cya = checkCYA(container);
|
|
316
|
-
_cya$childNodes3 = _slicedToArray(cya.childNodes, 3),
|
|
320
|
+
_cya$childNodes3 = _slicedToArray(cya.childNodes, 3), cyaChildNode = _cya$childNodes3[2]; // The title simply isn't returned
|
|
317
321
|
|
|
322
|
+
civilServant = cyaChildNode.childNodes[0];
|
|
318
323
|
expect(civilServant.tagName).toEqual('DL');
|
|
319
324
|
expect(civilServant.classList).toContain("govuk-!-margin-bottom-0"); // Changed margin if no titles
|
|
320
325
|
|
|
321
326
|
_civilServant$childNo2 = _slicedToArray(civilServant.childNodes, 1), status = _civilServant$childNo2[0];
|
|
322
327
|
checkRow(status, 'Are you a civil servant?', 'Yes', true);
|
|
323
328
|
|
|
324
|
-
case
|
|
329
|
+
case 9:
|
|
325
330
|
case "end":
|
|
326
331
|
return _context10.stop();
|
|
327
332
|
}
|
|
@@ -329,7 +334,7 @@ describe('components', function () {
|
|
|
329
334
|
}, _callee10);
|
|
330
335
|
})));
|
|
331
336
|
it('should show no title if is set to hidden', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee12() {
|
|
332
|
-
var cya, _cya$childNodes4, names, _names$childNodes2, firstName, surname;
|
|
337
|
+
var cya, _cya$childNodes4, cyaChildNode, names, _names$childNodes2, firstName, surname;
|
|
333
338
|
|
|
334
339
|
return regeneratorRuntime.wrap(function _callee12$(_context12) {
|
|
335
340
|
while (1) {
|
|
@@ -358,19 +363,76 @@ describe('components', function () {
|
|
|
358
363
|
|
|
359
364
|
case 2:
|
|
360
365
|
cya = checkCYA(container);
|
|
361
|
-
_cya$childNodes4 = _slicedToArray(cya.childNodes, 1),
|
|
366
|
+
_cya$childNodes4 = _slicedToArray(cya.childNodes, 1), cyaChildNode = _cya$childNodes4[0];
|
|
367
|
+
names = cyaChildNode.childNodes[0];
|
|
362
368
|
expect(names.tagName).toEqual('DL');
|
|
363
369
|
expect(names.classList).toContain("govuk-!-margin-bottom-".concat(_CheckYourAnswers.DEFAULT_MARGIN_BOTTOM));
|
|
364
370
|
_names$childNodes2 = _slicedToArray(names.childNodes, 2), firstName = _names$childNodes2[0], surname = _names$childNodes2[1];
|
|
365
371
|
checkRow(firstName, 'First name', 'John', false);
|
|
366
372
|
checkRow(surname, 'Last name', 'Smith', false);
|
|
367
373
|
|
|
368
|
-
case
|
|
374
|
+
case 10:
|
|
369
375
|
case "end":
|
|
370
376
|
return _context12.stop();
|
|
371
377
|
}
|
|
372
378
|
}
|
|
373
379
|
}, _callee12);
|
|
374
380
|
})));
|
|
381
|
+
it('should render a group with one action button', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee14() {
|
|
382
|
+
var GROUP_PAGES, cya, namesGroup, firstNameRow, surname, changeButtonDiv, changeButton;
|
|
383
|
+
return regeneratorRuntime.wrap(function _callee14$(_context14) {
|
|
384
|
+
while (1) {
|
|
385
|
+
switch (_context14.prev = _context14.next) {
|
|
386
|
+
case 0:
|
|
387
|
+
GROUP_PAGES = _utils.default.FormPage.getAll(_groupOfRow.default.pages, _groupOfRow.default.components, _objectSpread({}, DATA));
|
|
388
|
+
_context14.next = 3;
|
|
389
|
+
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee13() {
|
|
390
|
+
return regeneratorRuntime.wrap(function _callee13$(_context13) {
|
|
391
|
+
while (1) {
|
|
392
|
+
switch (_context13.prev = _context13.next) {
|
|
393
|
+
case 0:
|
|
394
|
+
(0, _reactDom.render)( /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, {
|
|
395
|
+
pages: GROUP_PAGES,
|
|
396
|
+
onRowAction: ON_ROW_ACTION,
|
|
397
|
+
onAction: ON_ACTION,
|
|
398
|
+
groups: _groupOfRow.default.cya.groups
|
|
399
|
+
}), container);
|
|
400
|
+
|
|
401
|
+
case 1:
|
|
402
|
+
case "end":
|
|
403
|
+
return _context13.stop();
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}, _callee13);
|
|
407
|
+
})));
|
|
408
|
+
|
|
409
|
+
case 3:
|
|
410
|
+
cya = checkCYA(container);
|
|
411
|
+
namesGroup = cya.childNodes[2];
|
|
412
|
+
firstNameRow = namesGroup.childNodes[0].childNodes[0];
|
|
413
|
+
expect(firstNameRow.childNodes.length).toEqual(2);
|
|
414
|
+
expect(firstNameRow.childNodes[0].textContent).toEqual('First name (optional)');
|
|
415
|
+
expect(firstNameRow.childNodes[0].tagName).toEqual('DT');
|
|
416
|
+
expect(firstNameRow.childNodes[1].textContent).toEqual('John');
|
|
417
|
+
expect(firstNameRow.childNodes[1].tagName).toEqual('DD');
|
|
418
|
+
surname = namesGroup.childNodes[0].childNodes[1];
|
|
419
|
+
expect(surname.childNodes.length).toEqual(2);
|
|
420
|
+
expect(surname.childNodes[0].textContent).toEqual('Last name (optional)');
|
|
421
|
+
expect(surname.childNodes[0].tagName).toEqual('DT');
|
|
422
|
+
expect(surname.childNodes[1].textContent).toEqual('Smith');
|
|
423
|
+
expect(surname.childNodes[1].tagName).toEqual('DD');
|
|
424
|
+
changeButtonDiv = namesGroup.childNodes[0].childNodes[2];
|
|
425
|
+
expect(changeButtonDiv.classList).toContain('change-group-button');
|
|
426
|
+
changeButton = changeButtonDiv.childNodes[0];
|
|
427
|
+
expect(changeButton.tagName).toEqual('A');
|
|
428
|
+
expect(changeButton.textContent).toEqual('Change names');
|
|
429
|
+
|
|
430
|
+
case 22:
|
|
431
|
+
case "end":
|
|
432
|
+
return _context14.stop();
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}, _callee14);
|
|
436
|
+
})));
|
|
375
437
|
});
|
|
376
438
|
});
|
|
@@ -4,6 +4,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
|
|
|
4
4
|
|
|
5
5
|
var _react = require("@testing-library/react");
|
|
6
6
|
|
|
7
|
+
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
8
|
+
|
|
7
9
|
var _react2 = _interopRequireDefault(require("react"));
|
|
8
10
|
|
|
9
11
|
var _models = require("../../models");
|
|
@@ -16,6 +18,10 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
16
18
|
|
|
17
19
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
20
|
|
|
21
|
+
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; }
|
|
22
|
+
|
|
23
|
+
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; }
|
|
24
|
+
|
|
19
25
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
20
26
|
|
|
21
27
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
@@ -23,16 +29,20 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
|
|
|
23
29
|
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; }
|
|
24
30
|
|
|
25
31
|
describe('components.FormComponent.Container', function () {
|
|
26
|
-
var _ID;
|
|
32
|
+
var _ID, _FORM_DATA;
|
|
27
33
|
|
|
28
34
|
var ID = 'container';
|
|
29
35
|
var NESTED_ID = 'nested';
|
|
30
36
|
var TEXT_ID = 'text';
|
|
31
37
|
var TEXT_VALUE = 'alpha';
|
|
32
38
|
var NESTED_TEXT_VALUE = 'charlie';
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
39
|
+
var FORM_DATA = (_FORM_DATA = {}, _defineProperty(_FORM_DATA, ID, (_ID = {}, _defineProperty(_ID, TEXT_ID, TEXT_VALUE), _defineProperty(_ID, NESTED_ID, _defineProperty({}, TEXT_ID, NESTED_TEXT_VALUE)), _ID)), _defineProperty(_FORM_DATA, _FormComponent.META_PROPERTY, _defineProperty({}, _FormComponent.META_DOCUMENTS_PROPERTY, [{
|
|
40
|
+
field: 'epsilon.zeta',
|
|
41
|
+
name: 'ez.jpg',
|
|
42
|
+
type: 'image/jpg',
|
|
43
|
+
extension: 'jpg',
|
|
44
|
+
url: 'http://files.com/ez.jpg'
|
|
45
|
+
}])), _FORM_DATA);
|
|
36
46
|
var TEXT_COMPONENT = {
|
|
37
47
|
id: TEXT_ID,
|
|
38
48
|
fieldId: TEXT_ID,
|
|
@@ -201,22 +211,91 @@ describe('components.FormComponent.Container', function () {
|
|
|
201
211
|
}
|
|
202
212
|
}, _callee3);
|
|
203
213
|
})));
|
|
204
|
-
it('should handle a
|
|
205
|
-
var CONTAINER, _render4, container, c, formGroup,
|
|
214
|
+
it('should handle a change to a file type component appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
|
|
215
|
+
var FILE_ID, ON_CHANGE_EVENTS, ON_CHANGE, CONTAINER, _render4, container, c, formGroup, input, FILE_EXTENSION, FILE_NAME, FILE_TYPE, str, blob, FILE, containerChangeValue, metaChangeValue;
|
|
206
216
|
|
|
207
217
|
return regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
208
218
|
while (1) {
|
|
209
219
|
switch (_context4.prev = _context4.next) {
|
|
210
220
|
case 0:
|
|
221
|
+
FILE_ID = 'file';
|
|
222
|
+
ON_CHANGE_EVENTS = [];
|
|
223
|
+
|
|
224
|
+
ON_CHANGE = function ON_CHANGE(e) {
|
|
225
|
+
ON_CHANGE_EVENTS.push(e);
|
|
226
|
+
};
|
|
227
|
+
|
|
211
228
|
CONTAINER = {
|
|
212
229
|
id: ID,
|
|
213
230
|
fieldId: ID,
|
|
214
231
|
type: _models.ComponentTypes.CONTAINER,
|
|
215
|
-
components: [
|
|
232
|
+
components: [{
|
|
233
|
+
id: FILE_ID,
|
|
234
|
+
fieldId: FILE_ID,
|
|
235
|
+
full_path: "".concat(ID, ".").concat(FILE_ID),
|
|
236
|
+
type: _models.ComponentTypes.FILE,
|
|
237
|
+
label: 'File component'
|
|
238
|
+
}]
|
|
216
239
|
};
|
|
217
240
|
_render4 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
241
|
+
component: CONTAINER,
|
|
242
|
+
value: FORM_DATA[ID],
|
|
243
|
+
formData: FORM_DATA,
|
|
244
|
+
onChange: ON_CHANGE
|
|
245
|
+
})), container = _render4.container; // Get hold of the text input.
|
|
246
|
+
|
|
247
|
+
c = container.childNodes[0];
|
|
248
|
+
formGroup = c.childNodes[0];
|
|
249
|
+
input = formGroup.childNodes[2].childNodes[0];
|
|
250
|
+
FILE_EXTENSION = 'json';
|
|
251
|
+
FILE_NAME = "test.".concat(FILE_EXTENSION);
|
|
252
|
+
FILE_TYPE = 'application/JSON';
|
|
253
|
+
str = JSON.stringify({
|
|
254
|
+
alpha: 'bravo'
|
|
255
|
+
});
|
|
256
|
+
blob = new Blob([str]);
|
|
257
|
+
FILE = new File([blob], FILE_NAME, {
|
|
258
|
+
type: FILE_TYPE
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
_userEvent.default.upload(input, FILE); // And confirm the formData has been changed.
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
expect(ON_CHANGE_EVENTS.length).toEqual(2); // One for the file, another for the meta.
|
|
265
|
+
|
|
266
|
+
expect(ON_CHANGE_EVENTS[0].target.name).toEqual(ID);
|
|
267
|
+
expect(ON_CHANGE_EVENTS[1].target.name).toEqual(_FormComponent.META_PROPERTY);
|
|
268
|
+
containerChangeValue = JSON.parse(JSON.stringify(ON_CHANGE_EVENTS[0].target.value));
|
|
269
|
+
metaChangeValue = JSON.parse(JSON.stringify(ON_CHANGE_EVENTS[1].target.value));
|
|
270
|
+
expect(metaChangeValue.documents.length).toEqual(2); // Existing one, plus this new one.
|
|
271
|
+
|
|
272
|
+
expect(metaChangeValue.documents[1]).toMatchObject(_objectSpread(_objectSpread({}, containerChangeValue[FILE_ID]), {}, {
|
|
273
|
+
field: "".concat(ID, ".").concat(FILE_ID)
|
|
274
|
+
}));
|
|
275
|
+
|
|
276
|
+
case 22:
|
|
277
|
+
case "end":
|
|
278
|
+
return _context4.stop();
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}, _callee4);
|
|
282
|
+
})));
|
|
283
|
+
it('should handle a null value appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
|
|
284
|
+
var CONTAINER, _render5, container, c, formGroup, label, hint, input;
|
|
285
|
+
|
|
286
|
+
return regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
287
|
+
while (1) {
|
|
288
|
+
switch (_context5.prev = _context5.next) {
|
|
289
|
+
case 0:
|
|
290
|
+
CONTAINER = {
|
|
291
|
+
id: ID,
|
|
292
|
+
fieldId: ID,
|
|
293
|
+
type: _models.ComponentTypes.CONTAINER,
|
|
294
|
+
components: [TEXT_COMPONENT]
|
|
295
|
+
};
|
|
296
|
+
_render5 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
218
297
|
component: CONTAINER
|
|
219
|
-
})), container =
|
|
298
|
+
})), container = _render5.container; // Check the container itself.
|
|
220
299
|
|
|
221
300
|
c = container.childNodes[0];
|
|
222
301
|
expect(c.tagName).toEqual('DIV');
|
|
@@ -242,9 +321,9 @@ describe('components.FormComponent.Container', function () {
|
|
|
242
321
|
|
|
243
322
|
case 22:
|
|
244
323
|
case "end":
|
|
245
|
-
return
|
|
324
|
+
return _context5.stop();
|
|
246
325
|
}
|
|
247
326
|
}
|
|
248
|
-
},
|
|
327
|
+
}, _callee5);
|
|
249
328
|
})));
|
|
250
329
|
});
|
|
@@ -5,7 +5,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.default = exports.DEFAULT_CONTAINER_CLASS = void 0;
|
|
8
|
+
exports.default = exports.META_PROPERTY = exports.META_DOCUMENTS_PROPERTY = exports.DEFAULT_CONTAINER_CLASS = void 0;
|
|
9
9
|
|
|
10
10
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
11
|
|
|
@@ -50,6 +50,10 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
|
|
|
50
50
|
|
|
51
51
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
52
52
|
|
|
53
|
+
var META_PROPERTY = 'meta';
|
|
54
|
+
exports.META_PROPERTY = META_PROPERTY;
|
|
55
|
+
var META_DOCUMENTS_PROPERTY = 'documents';
|
|
56
|
+
exports.META_DOCUMENTS_PROPERTY = META_DOCUMENTS_PROPERTY;
|
|
53
57
|
var DEFAULT_CONTAINER_CLASS = 'hods-form-container';
|
|
54
58
|
exports.DEFAULT_CONTAINER_CLASS = DEFAULT_CONTAINER_CLASS;
|
|
55
59
|
|
|
@@ -64,15 +68,21 @@ var Container = function Container(_ref) {
|
|
|
64
68
|
var onComponentChange = function onComponentChange(_ref2) {
|
|
65
69
|
var target = _ref2.target;
|
|
66
70
|
|
|
67
|
-
var val = _objectSpread(_objectSpread({}, value), {}, _defineProperty({}, target.name, target.value));
|
|
68
|
-
|
|
69
71
|
if (typeof onChange === 'function') {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
if (target.name === META_PROPERTY) {
|
|
73
|
+
onChange({
|
|
74
|
+
target: target
|
|
75
|
+
});
|
|
76
|
+
} else {
|
|
77
|
+
var val = _objectSpread(_objectSpread({}, value), {}, _defineProperty({}, target.name, target.value));
|
|
78
|
+
|
|
79
|
+
onChange({
|
|
80
|
+
target: {
|
|
81
|
+
name: container.fieldId,
|
|
82
|
+
value: val
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
76
86
|
}
|
|
77
87
|
};
|
|
78
88
|
|
|
@@ -88,12 +98,13 @@ var Container = function Container(_ref) {
|
|
|
88
98
|
className: DEFAULT_CONTAINER_CLASS,
|
|
89
99
|
id: container.id
|
|
90
100
|
}), container.components && container.components.filter(shouldShow).map(function (component, index) {
|
|
91
|
-
var
|
|
101
|
+
var defaultValue = component.type === _models.ComponentTypes.FILE ? {} : '';
|
|
102
|
+
var val = value ? value[component.fieldId] : defaultValue;
|
|
92
103
|
return /*#__PURE__*/_react.default.createElement(FormComponent, {
|
|
93
104
|
key: index,
|
|
94
105
|
component: component,
|
|
95
106
|
formData: formData,
|
|
96
|
-
value: val ||
|
|
107
|
+
value: val || defaultValue,
|
|
97
108
|
wrap: wrap,
|
|
98
109
|
onChange: onComponentChange
|
|
99
110
|
});
|
|
@@ -144,22 +155,60 @@ var FormComponent = function FormComponent(_ref3) {
|
|
|
144
155
|
}
|
|
145
156
|
}, [component, data, status]);
|
|
146
157
|
|
|
158
|
+
var changeMetaDocuments = function changeMetaDocuments(document) {
|
|
159
|
+
var _formData$META_PROPER;
|
|
160
|
+
|
|
161
|
+
var documents = (((_formData$META_PROPER = formData[META_PROPERTY]) === null || _formData$META_PROPER === void 0 ? void 0 : _formData$META_PROPER.documents) || []).filter(function (d) {
|
|
162
|
+
return d.field !== component.full_path;
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
if (document) {
|
|
166
|
+
documents.push(_objectSpread(_objectSpread({}, document), {}, {
|
|
167
|
+
field: component.full_path
|
|
168
|
+
}));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
onChange({
|
|
172
|
+
target: {
|
|
173
|
+
name: META_PROPERTY,
|
|
174
|
+
value: _objectSpread(_objectSpread({}, formData[META_PROPERTY]), {}, {
|
|
175
|
+
documents: documents
|
|
176
|
+
})
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
var onComponentChange = function onComponentChange(_ref4) {
|
|
182
|
+
var target = _ref4.target;
|
|
183
|
+
|
|
184
|
+
if (typeof onChange === 'function') {
|
|
185
|
+
onChange({
|
|
186
|
+
target: target
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
if (component.type === _models.ComponentTypes.FILE) {
|
|
190
|
+
changeMetaDocuments(target.value);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
|
|
147
195
|
if (component.type === _models.ComponentTypes.CONTAINER) {
|
|
148
196
|
return /*#__PURE__*/_react.default.createElement(Container, {
|
|
149
197
|
container: component,
|
|
150
198
|
wrap: wrap,
|
|
151
|
-
onChange:
|
|
199
|
+
onChange: onComponentChange,
|
|
152
200
|
value: value,
|
|
153
201
|
formData: formData
|
|
154
202
|
});
|
|
155
203
|
}
|
|
156
204
|
|
|
205
|
+
var defaultValue = component.type === _models.ComponentTypes.FILE ? {} : '';
|
|
157
206
|
return _utils.default.Component.get(_objectSpread(_objectSpread(_objectSpread({}, attrs), component), {}, {
|
|
158
207
|
label: component.label || '',
|
|
159
208
|
hint: component.hint || '',
|
|
160
209
|
options: options,
|
|
161
|
-
value: value ||
|
|
162
|
-
onChange:
|
|
210
|
+
value: value || defaultValue,
|
|
211
|
+
onChange: onComponentChange
|
|
163
212
|
}), wrap, hooks.onGetComponent);
|
|
164
213
|
};
|
|
165
214
|
|
|
@@ -89,7 +89,7 @@ describe('components', function () {
|
|
|
89
89
|
};
|
|
90
90
|
|
|
91
91
|
var getChangeLink = function getChangeLink(summaryList) {
|
|
92
|
-
var _summaryList$childNod = _slicedToArray(summaryList.childNodes[0].childNodes, 3),
|
|
92
|
+
var _summaryList$childNod = _slicedToArray(summaryList.childNodes[0].childNodes[0].childNodes, 3),
|
|
93
93
|
actions = _summaryList$childNod[2];
|
|
94
94
|
|
|
95
95
|
return actions.childNodes[0];
|
|
@@ -22,7 +22,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
22
22
|
*/
|
|
23
23
|
var canActionProceed = function canActionProceed(action, page, onError) {
|
|
24
24
|
if (action.validate) {
|
|
25
|
-
var errors = _utils.default.Validate.page(page
|
|
25
|
+
var errors = _utils.default.Validate.page(page);
|
|
26
26
|
|
|
27
27
|
onError(errors);
|
|
28
28
|
return errors.length === 0;
|
|
@@ -32,7 +32,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
32
32
|
var canCYASubmit = function canCYASubmit(pages, onError) {
|
|
33
33
|
var errors = [];
|
|
34
34
|
pages.forEach(function (p) {
|
|
35
|
-
errors.push.apply(errors, _toConsumableArray(_utils.default.Validate.page(p
|
|
35
|
+
errors.push.apply(errors, _toConsumableArray(_utils.default.Validate.page(p)));
|
|
36
36
|
});
|
|
37
37
|
onError(errors);
|
|
38
38
|
return errors.length === 0;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
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); }
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
+
|
|
12
|
+
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
13
|
+
|
|
14
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
15
|
+
|
|
16
|
+
var _getGroupActionAttributes = _interopRequireDefault(require("./helpers/getGroupActionAttributes"));
|
|
17
|
+
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
+
|
|
20
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
21
|
+
|
|
22
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
23
|
+
|
|
24
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
25
|
+
|
|
26
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
27
|
+
|
|
28
|
+
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); }
|
|
29
|
+
|
|
30
|
+
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; }
|
|
31
|
+
|
|
32
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
33
|
+
|
|
34
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
35
|
+
|
|
36
|
+
var GroupAction = function GroupAction(_ref) {
|
|
37
|
+
var group = _ref.group;
|
|
38
|
+
|
|
39
|
+
var _useState = (0, _react.useState)({}),
|
|
40
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
41
|
+
attrs = _useState2[0],
|
|
42
|
+
setAttrs = _useState2[1];
|
|
43
|
+
|
|
44
|
+
(0, _react.useEffect)(function () {
|
|
45
|
+
setAttrs((0, _getGroupActionAttributes.default)(group));
|
|
46
|
+
}, [group, setAttrs]);
|
|
47
|
+
|
|
48
|
+
if (!group.action) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return /*#__PURE__*/_react.default.createElement(_copReactComponents.Link, attrs, group.action.label, group.action.aria_suffix && /*#__PURE__*/_react.default.createElement("span", {
|
|
53
|
+
className: "mobile-text govuk-link"
|
|
54
|
+
}, ' ', "".concat(group.action.aria_suffix)));
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
GroupAction.propTypes = {
|
|
58
|
+
group: _propTypes.default.shape({
|
|
59
|
+
action: _propTypes.default.shape({
|
|
60
|
+
label: _propTypes.default.string.isRequired,
|
|
61
|
+
page: _propTypes.default.string,
|
|
62
|
+
aria_suffix: _propTypes.default.string,
|
|
63
|
+
onAction: _propTypes.default.func
|
|
64
|
+
})
|
|
65
|
+
}).isRequired
|
|
66
|
+
};
|
|
67
|
+
var _default = GroupAction;
|
|
68
|
+
exports.default = _default;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _react = require("@testing-library/react");
|
|
4
|
+
|
|
5
|
+
var _react2 = _interopRequireDefault(require("react"));
|
|
6
|
+
|
|
7
|
+
var _GroupAction = _interopRequireDefault(require("./GroupAction"));
|
|
8
|
+
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
|
|
11
|
+
// Global imports
|
|
12
|
+
// Local imports
|
|
13
|
+
describe('components', function () {
|
|
14
|
+
describe('SummaryList.GroupAction', function () {
|
|
15
|
+
it('should handle a group row without an action', function () {
|
|
16
|
+
var ROW = {};
|
|
17
|
+
|
|
18
|
+
var _render = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_GroupAction.default, {
|
|
19
|
+
group: ROW
|
|
20
|
+
})),
|
|
21
|
+
container = _render.container;
|
|
22
|
+
|
|
23
|
+
expect(container.childNodes.length).toEqual(0);
|
|
24
|
+
});
|
|
25
|
+
it('should handle a row with an href in the action', function () {
|
|
26
|
+
var PAGE = 'alpha';
|
|
27
|
+
var ROW = {
|
|
28
|
+
action: {
|
|
29
|
+
page: PAGE,
|
|
30
|
+
label: 'Change'
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
var _render2 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_GroupAction.default, {
|
|
35
|
+
group: ROW
|
|
36
|
+
})),
|
|
37
|
+
container = _render2.container;
|
|
38
|
+
|
|
39
|
+
var link = container.childNodes[0];
|
|
40
|
+
expect(link.tagName).toEqual('A');
|
|
41
|
+
expect(link.getAttribute('href')).toEqual("/".concat(PAGE));
|
|
42
|
+
expect(link.textContent).toEqual(ROW.action.label);
|
|
43
|
+
});
|
|
44
|
+
it('should render an aria_suffix appropriately', function () {
|
|
45
|
+
var PAGE = 'alpha';
|
|
46
|
+
var ROW = {
|
|
47
|
+
action: {
|
|
48
|
+
page: PAGE,
|
|
49
|
+
label: 'Change',
|
|
50
|
+
aria_suffix: 'the thing'
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
var _render3 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_GroupAction.default, {
|
|
55
|
+
group: ROW
|
|
56
|
+
})),
|
|
57
|
+
container = _render3.container;
|
|
58
|
+
|
|
59
|
+
var link = container.childNodes[0];
|
|
60
|
+
expect(link.tagName).toEqual('A');
|
|
61
|
+
expect(link.getAttribute('href')).toEqual("/".concat(PAGE));
|
|
62
|
+
expect(link.textContent).toEqual("".concat(ROW.action.label, " ").concat(ROW.action.aria_suffix));
|
|
63
|
+
});
|
|
64
|
+
it('should handle a row with an onAction in the action', function () {
|
|
65
|
+
var ON_ACTION_CALLS = [];
|
|
66
|
+
|
|
67
|
+
var ON_ACTION = function ON_ACTION(row) {
|
|
68
|
+
ON_ACTION_CALLS.push(row);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
var ROW = {
|
|
72
|
+
action: {
|
|
73
|
+
onAction: ON_ACTION,
|
|
74
|
+
label: 'Change'
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
var _render4 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_GroupAction.default, {
|
|
79
|
+
group: ROW
|
|
80
|
+
})),
|
|
81
|
+
container = _render4.container;
|
|
82
|
+
|
|
83
|
+
var link = container.childNodes[0];
|
|
84
|
+
expect(link.tagName).toEqual('A');
|
|
85
|
+
expect(link.getAttribute('onClick')).toBeDefined();
|
|
86
|
+
expect(link.textContent).toEqual(ROW.action.label);
|
|
87
|
+
|
|
88
|
+
_react.fireEvent.click(link, {});
|
|
89
|
+
|
|
90
|
+
expect(ON_ACTION_CALLS.length).toEqual(1);
|
|
91
|
+
expect(ON_ACTION_CALLS[0]).toEqual(ROW);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
});
|