@ukhomeoffice/cop-react-form-renderer 4.51.0 → 4.52.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.
@@ -103,7 +103,7 @@ var DEFAULT_CLASS = 'hods-form';
103
103
  exports.DEFAULT_CLASS = DEFAULT_CLASS;
104
104
 
105
105
  var InternalFormRenderer = function InternalFormRenderer(_ref2) {
106
- var _formState$page5;
106
+ var _formState$page5, _formState$page$actio;
107
107
 
108
108
  var title = _ref2.title,
109
109
  type = _ref2.type,
@@ -605,7 +605,9 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
605
605
  }, title && !hide_title && pageId === _models.FormPages.HUB && /*#__PURE__*/_react.default.createElement(_copReactComponents.LargeHeading, null, title), formState.cya && /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, _extends({
606
606
  pages: _helpers.default.getRelevantPages(formState, pages, currentTask.fullPages)
607
607
  }, cya, ((_formState$page5 = formState.page) === null || _formState$page5 === void 0 ? void 0 : _formState$page5.type) === _models.FormPages.PARTIAL_CYA && {
608
- actions: formState.page.actions
608
+ actions: (_formState$page$actio = formState.page.actions) === null || _formState$page$actio === void 0 ? void 0 : _formState$page$actio.filter(function (action) {
609
+ return _utils.default.Component.show(action, data);
610
+ })
609
611
  }, formState.cya, {
610
612
  onAction: onCYAAction,
611
613
  onRowAction: onCYARowAction,
@@ -39,7 +39,7 @@ var validatePage = function validatePage(page) {
39
39
  }
40
40
  }
41
41
 
42
- if ((0, _showFormPage.default)(page, page.formData) && Array.isArray(page.components)) {
42
+ if ((0, _showFormPage.default)(page, data) && Array.isArray(page.components)) {
43
43
  var errs = page.components.reduce(function (errors, component) {
44
44
  var componentErrors = (0, _validateComponent.default)(component, data, data);
45
45
  return errors.concat(componentErrors).flat().map(function (err) {
@@ -73,6 +73,35 @@ describe('utils.Validate.Page', function () {
73
73
  error: 'Echo is required'
74
74
  });
75
75
  });
76
+ it('should return an error for each required component on a collection page', function () {
77
+ var COMPONENTS = [setup('a', _models.ComponentTypes.TEXT, 'Alpha', true), setup('b', _models.ComponentTypes.TEXT, 'Bravo', true), setup('c', _models.ComponentTypes.TEXT, 'Charlie', false), // The only unrequired one
78
+ setup('d', _models.ComponentTypes.TEXT, 'Delta', true), setup('e', _models.ComponentTypes.TEXT, 'Echo', true)];
79
+ var PAGE = {
80
+ components: COMPONENTS,
81
+ collection: {
82
+ name: 'testCollection'
83
+ },
84
+ formData: null
85
+ };
86
+ var RESULT = (0, _validatePage.default)(PAGE);
87
+ expect(RESULT.length).toEqual(4);
88
+ expect(RESULT[0]).toEqual({
89
+ id: 'a',
90
+ error: 'Alpha is required'
91
+ });
92
+ expect(RESULT[1]).toEqual({
93
+ id: 'b',
94
+ error: 'Bravo is required'
95
+ });
96
+ expect(RESULT[2]).toEqual({
97
+ id: 'd',
98
+ error: 'Delta is required'
99
+ });
100
+ expect(RESULT[3]).toEqual({
101
+ id: 'e',
102
+ error: 'Echo is required'
103
+ });
104
+ });
76
105
  it('should return an error for each required component with interpolated label', function () {
77
106
  var COMPONENTS = [// eslint-disable-next-line no-template-curly-in-string
78
107
  setup('a', _models.ComponentTypes.TEXT, 'Alpha ${tiger}', true), // eslint-disable-next-line no-template-curly-in-string
@@ -291,6 +320,70 @@ describe('utils.Validate.Page', function () {
291
320
  };
292
321
  expect((0, _validatePage.default)(PAGE).length).toEqual(0);
293
322
  });
323
+ it('should return an error for each required component on a collection page with a show_when that is true', function () {
324
+ var COMPONENTS = [setup('a', _models.ComponentTypes.TEXT, 'Alpha', true), setup('b', _models.ComponentTypes.TEXT, 'Bravo', true), setup('c', _models.ComponentTypes.TEXT, 'Charlie', false), // The only unrequired one
325
+ setup('d', _models.ComponentTypes.TEXT, 'Delta', true), setup('e', _models.ComponentTypes.TEXT, 'Echo', true)];
326
+ var PAGE = {
327
+ components: COMPONENTS,
328
+ collection: {
329
+ name: 'testCollection'
330
+ },
331
+ show_when: {
332
+ field: 'isShown',
333
+ op: '=',
334
+ value: true
335
+ },
336
+ formData: {
337
+ testCollectionActiveId: 123,
338
+ testCollection: [{
339
+ id: 123,
340
+ isShown: true
341
+ }]
342
+ }
343
+ };
344
+ var RESULT = (0, _validatePage.default)(PAGE);
345
+ expect(RESULT.length).toEqual(4);
346
+ expect(RESULT[0]).toEqual({
347
+ id: 'a',
348
+ error: 'Alpha is required'
349
+ });
350
+ expect(RESULT[1]).toEqual({
351
+ id: 'b',
352
+ error: 'Bravo is required'
353
+ });
354
+ expect(RESULT[2]).toEqual({
355
+ id: 'd',
356
+ error: 'Delta is required'
357
+ });
358
+ expect(RESULT[3]).toEqual({
359
+ id: 'e',
360
+ error: 'Echo is required'
361
+ });
362
+ });
363
+ it('should return no errors on a collection page with a show_when that is false', function () {
364
+ var COMPONENTS = [setup('a', _models.ComponentTypes.TEXT, 'Alpha', true), setup('b', _models.ComponentTypes.TEXT, 'Bravo', true), setup('c', _models.ComponentTypes.TEXT, 'Charlie', false), // The only unrequired one
365
+ setup('d', _models.ComponentTypes.TEXT, 'Delta', true), setup('e', _models.ComponentTypes.TEXT, 'Echo', true)];
366
+ var PAGE = {
367
+ components: COMPONENTS,
368
+ collection: {
369
+ name: 'testCollection'
370
+ },
371
+ show_when: {
372
+ field: 'isShown',
373
+ op: '=',
374
+ value: true
375
+ },
376
+ formData: {
377
+ testCollectionActiveId: 123,
378
+ testCollection: [{
379
+ id: 123,
380
+ isShown: false
381
+ }]
382
+ }
383
+ };
384
+ var RESULT = (0, _validatePage.default)(PAGE);
385
+ expect(RESULT.length).toEqual(0);
386
+ });
294
387
  });
295
388
  describe('when the form data has one field missing and includes an invalid email', function () {
296
389
  var _DATA2;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "4.51.0",
3
+ "version": "4.52.0",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",