@ukhomeoffice/cop-react-form-renderer 4.51.0 → 4.51.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.
@@ -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.51.1",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",