@ukhomeoffice/cop-react-form-renderer 3.26.3 → 3.32.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.
Files changed (27) hide show
  1. package/dist/components/CheckYourAnswers/CheckYourAnswers.js +5 -2
  2. package/dist/components/CollectionPage/CollectionPage.js +149 -0
  3. package/dist/components/CollectionPage/CollectionPage.test.js +428 -0
  4. package/dist/components/CollectionPage/index.js +13 -0
  5. package/dist/components/FormPage/FormPage.js +6 -1
  6. package/dist/components/FormRenderer/FormRenderer.js +61 -17
  7. package/dist/components/PageActions/ActionButton.js +1 -1
  8. package/dist/components/TaskList/TaskList.js +11 -7
  9. package/dist/components/TaskList/TaskList.scss +26 -4
  10. package/dist/components/TaskList/TaskList.test.js +5 -5
  11. package/dist/models/PageAction.js +5 -1
  12. package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +85 -0
  13. package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +107 -0
  14. package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +6 -0
  15. package/dist/utils/CheckYourAnswers/showComponentCYA.js +4 -0
  16. package/dist/utils/CheckYourAnswers/showComponentCYA.test.js +10 -0
  17. package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.js +45 -0
  18. package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.test.js +41 -0
  19. package/dist/utils/CollectionPage/getCollectionPageActiveIndex.js +34 -0
  20. package/dist/utils/CollectionPage/getCollectionPageActiveIndex.test.js +54 -0
  21. package/dist/utils/CollectionPage/index.js +23 -0
  22. package/dist/utils/CollectionPage/mergeCollectionPages.js +69 -0
  23. package/dist/utils/CollectionPage/mergeCollectionPages.test.js +131 -0
  24. package/dist/utils/Validate/validatePage.js +16 -2
  25. package/dist/utils/Validate/validatePage.test.js +352 -206
  26. package/dist/utils/index.js +3 -0
  27. package/package.json +2 -2
@@ -12,224 +12,370 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
12
12
 
13
13
  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; }
14
14
 
15
- describe('utils', function () {
16
- describe('Validate', function () {
17
- describe('page', function () {
18
- var setup = function setup(id, type, label, required) {
19
- return {
20
- id: id,
21
- fieldId: id,
22
- type: type,
23
- label: label,
24
- required: required
25
- };
15
+ describe('utils.Validate.Page', function () {
16
+ describe('with FormPage', function () {
17
+ var setup = function setup(id, type, label, required) {
18
+ return {
19
+ id: id,
20
+ fieldId: id,
21
+ type: type,
22
+ label: label,
23
+ required: required
26
24
  };
25
+ };
27
26
 
28
- it('should return no error when the components array is null', function () {
27
+ it('should return no error when the components array is null', function () {
28
+ var PAGE = {
29
+ components: null,
30
+ formData: null
31
+ };
32
+ expect((0, _validatePage.default)(PAGE).length).toEqual(0);
33
+ });
34
+ it('should return no error when the components array is empty', function () {
35
+ var PAGE = {
36
+ components: [],
37
+ formData: null
38
+ };
39
+ expect((0, _validatePage.default)(PAGE).length).toEqual(0);
40
+ });
41
+ describe('when there is no form data', function () {
42
+ it('should return no errors when no components are required', function () {
43
+ var COMPONENTS = [setup('a', _models.ComponentTypes.TEXT, 'Alpha', false), setup('b', _models.ComponentTypes.TEXT, 'Bravo', false)];
44
+ var PAGE = {
45
+ components: COMPONENTS,
46
+ formData: null
47
+ };
48
+ expect((0, _validatePage.default)(PAGE).length).toEqual(0);
49
+ });
50
+ it('should return an error for each required component', function () {
51
+ 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
52
+ setup('d', _models.ComponentTypes.TEXT, 'Delta', true), setup('e', _models.ComponentTypes.TEXT, 'Echo', true)];
53
+ var PAGE = {
54
+ components: COMPONENTS,
55
+ formData: null
56
+ };
57
+ var RESULT = (0, _validatePage.default)(PAGE);
58
+ expect(RESULT.length).toEqual(4);
59
+ expect(RESULT[0]).toEqual({
60
+ id: 'a',
61
+ error: 'Alpha is required'
62
+ });
63
+ expect(RESULT[1]).toEqual({
64
+ id: 'b',
65
+ error: 'Bravo is required'
66
+ });
67
+ expect(RESULT[2]).toEqual({
68
+ id: 'd',
69
+ error: 'Delta is required'
70
+ });
71
+ expect(RESULT[3]).toEqual({
72
+ id: 'e',
73
+ error: 'Echo is required'
74
+ });
75
+ });
76
+ it('should return an error for each required component with interpolated label', function () {
77
+ var COMPONENTS = [// eslint-disable-next-line no-template-curly-in-string
78
+ setup('a', _models.ComponentTypes.TEXT, 'Alpha ${tiger}', true), // eslint-disable-next-line no-template-curly-in-string
79
+ setup('b', _models.ComponentTypes.EMAIL, 'Bravo ${panther}', true), // eslint-disable-next-line no-template-curly-in-string
80
+ setup('c', _models.ComponentTypes.AUTOCOMPLETE, 'Charlie ${eagle}', true), // eslint-disable-next-line no-template-curly-in-string
81
+ setup('d', _models.ComponentTypes.CHECKBOXES, 'Delta ${lion}', true), // eslint-disable-next-line no-template-curly-in-string
82
+ setup('e', _models.ComponentTypes.FILE, 'Echo ${zoo}', true)];
83
+ var PAGE = {
84
+ components: COMPONENTS,
85
+ formData: {
86
+ tiger: 'Tiger',
87
+ panther: 'Panther',
88
+ eagle: 'Eagle',
89
+ lion: 'Lion',
90
+ zoo: 'Zoo'
91
+ }
92
+ };
93
+ var RESULT = (0, _validatePage.default)(PAGE);
94
+ expect(RESULT.length).toEqual(5);
95
+ expect(RESULT[0]).toEqual({
96
+ id: 'a',
97
+ error: "Alpha ".concat(PAGE.formData.tiger, " is required")
98
+ });
99
+ expect(RESULT[1]).toEqual({
100
+ id: 'b',
101
+ error: "Bravo ".concat(PAGE.formData.panther, " is required")
102
+ });
103
+ expect(RESULT[2]).toEqual({
104
+ id: 'c',
105
+ error: "Charlie ".concat(PAGE.formData.eagle, " is required")
106
+ });
107
+ expect(RESULT[3]).toEqual({
108
+ id: 'd',
109
+ error: "Delta ".concat(PAGE.formData.lion, " is required")
110
+ });
111
+ expect(RESULT[4]).toEqual({
112
+ id: 'e',
113
+ error: "Echo ".concat(PAGE.formData.zoo, " is required")
114
+ });
115
+ });
116
+ });
117
+ describe('when the form data is fully valid', function () {
118
+ var DATA = {
119
+ alpha: 'alpha.smith@digital.homeoffice.gov.uk',
120
+ bravo: 'bravo.jones@digital.homeoffice.gov.uk'
121
+ };
122
+ it('should return no errors when none of the components are required or email types', function () {
123
+ var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', false), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', false)];
124
+ var PAGE = {
125
+ components: COMPONENTS,
126
+ formData: DATA
127
+ };
128
+ expect((0, _validatePage.default)(PAGE).length).toEqual(0);
129
+ });
130
+ it('should return no errors when all of the components are required but not email types', function () {
131
+ var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', true), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', true)];
132
+ var PAGE = {
133
+ components: COMPONENTS,
134
+ formData: DATA
135
+ };
136
+ expect((0, _validatePage.default)(PAGE).length).toEqual(0);
137
+ });
138
+ it('should return no errors when none of the components are required but are all email types', function () {
139
+ var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', false), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', false)];
140
+ var PAGE = {
141
+ components: COMPONENTS,
142
+ formData: DATA
143
+ };
144
+ expect((0, _validatePage.default)(PAGE).length).toEqual(0);
145
+ });
146
+ it('should return no errors when all of the components are required and email types', function () {
147
+ var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', true)];
148
+ var PAGE = {
149
+ components: COMPONENTS,
150
+ formData: DATA
151
+ };
152
+ expect((0, _validatePage.default)(PAGE).length).toEqual(0);
153
+ });
154
+ });
155
+ describe('when the form data has one field missing and includes an invalid email', function () {
156
+ var DATA = {
157
+ alpha: 'alpha.smith@digital.homeoffice.gov.uk',
158
+ bravo: 'bravo.jones@hotmail.com'
159
+ };
160
+ it('should return no errors when none of the components are required or email types', function () {
161
+ var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', false), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', false), setup('charlie', _models.ComponentTypes.TEXT, 'Charlie', false)];
29
162
  var PAGE = {
30
- components: null,
163
+ components: COMPONENTS,
31
164
  formData: null
32
165
  };
33
166
  expect((0, _validatePage.default)(PAGE).length).toEqual(0);
34
167
  });
35
- it('should return no error when the components array is empty', function () {
168
+ it('should return an error for the missing field when all are required but not email types', function () {
169
+ var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', true), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', true), setup('charlie', _models.ComponentTypes.TEXT, 'Charlie', true)];
170
+ var PAGE = {
171
+ components: COMPONENTS,
172
+ formData: DATA
173
+ };
174
+ var RESULT = (0, _validatePage.default)(PAGE);
175
+ expect(RESULT.length).toEqual(1);
176
+ expect(RESULT[0]).toEqual({
177
+ id: 'charlie',
178
+ error: 'Charlie is required'
179
+ });
180
+ });
181
+ it('should return an error for the invalid email field when none are required but all email types', function () {
182
+ var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', false), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', false), setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie', false)];
183
+ var PAGE = {
184
+ components: COMPONENTS,
185
+ formData: DATA
186
+ };
187
+ var RESULT = (0, _validatePage.default)(PAGE);
188
+ expect(RESULT.length).toEqual(1);
189
+ expect(RESULT[0]).toEqual({
190
+ id: 'bravo',
191
+ error: 'Enter bravo in the correct format, like jane.doe@homeoffice.gov.uk'
192
+ });
193
+ });
194
+ it('should return an error for both invalid fields when all are required and email types', function () {
195
+ var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', true), setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie', true)];
196
+ var PAGE = {
197
+ components: COMPONENTS,
198
+ formData: DATA
199
+ };
200
+ var RESULT = (0, _validatePage.default)(PAGE);
201
+ expect(RESULT.length).toEqual(2);
202
+ expect(RESULT[0]).toEqual({
203
+ id: 'bravo',
204
+ error: 'Enter bravo in the correct format, like jane.doe@homeoffice.gov.uk'
205
+ });
206
+ expect(RESULT[1]).toEqual({
207
+ id: 'charlie',
208
+ error: 'Charlie is required'
209
+ });
210
+ });
211
+ it('should return an interpolated error for both invalid fields when all are required and email types', function () {
212
+ var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true), // eslint-disable-next-line no-template-curly-in-string
213
+ setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo ${lion}', true), // eslint-disable-next-line no-template-curly-in-string
214
+ setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie ${panther}', true)];
215
+ var PAGE = {
216
+ components: COMPONENTS,
217
+ formData: _objectSpread(_objectSpread({}, DATA), {}, {
218
+ lion: 'Lion',
219
+ panther: 'Panther'
220
+ })
221
+ };
222
+ var RESULT = (0, _validatePage.default)(PAGE);
223
+ expect(RESULT.length).toEqual(2);
224
+ expect(RESULT[0]).toEqual({
225
+ id: 'bravo',
226
+ error: "Enter bravo ".concat(PAGE.formData.lion, " in the correct format, like jane.doe@homeoffice.gov.uk")
227
+ });
228
+ expect(RESULT[1]).toEqual({
229
+ id: 'charlie',
230
+ error: "Charlie ".concat(PAGE.formData.panther, " is required")
231
+ });
232
+ });
233
+ });
234
+ });
235
+ describe('with CollectionPage', function () {
236
+ var COLLECTION = {
237
+ name: 'pageCollection'
238
+ };
239
+
240
+ var setup = function setup(id, type, label, required) {
241
+ return {
242
+ id: id,
243
+ fieldId: id,
244
+ type: type,
245
+ label: label,
246
+ required: required
247
+ };
248
+ };
249
+
250
+ describe('when the form data is fully valid', function () {
251
+ var _DATA;
252
+
253
+ var DATA = (_DATA = {}, _defineProperty(_DATA, "".concat(COLLECTION.name, "ActiveId"), '01'), _defineProperty(_DATA, COLLECTION.name, [{
254
+ id: '01',
255
+ alpha: 'alpha.smith@digital.homeoffice.gov.uk',
256
+ bravo: 'bravo.jones@digital.homeoffice.gov.uk'
257
+ }]), _DATA);
258
+ it('should return no errors when none of the components are required or email types', function () {
259
+ var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', false), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', false)];
260
+ var PAGE = {
261
+ collection: COLLECTION,
262
+ components: COMPONENTS,
263
+ formData: DATA
264
+ };
265
+ expect((0, _validatePage.default)(PAGE).length).toEqual(0);
266
+ });
267
+ it('should return no errors when all of the components are required but not email types', function () {
268
+ var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', true), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', true)];
269
+ var PAGE = {
270
+ collection: COLLECTION,
271
+ components: COMPONENTS,
272
+ formData: DATA
273
+ };
274
+ expect((0, _validatePage.default)(PAGE).length).toEqual(0);
275
+ });
276
+ it('should return no errors when none of the components are required but are all email types', function () {
277
+ var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', false), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', false)];
36
278
  var PAGE = {
37
- components: [],
279
+ collection: COLLECTION,
280
+ components: COMPONENTS,
281
+ formData: DATA
282
+ };
283
+ expect((0, _validatePage.default)(PAGE).length).toEqual(0);
284
+ });
285
+ it('should return no errors when all of the components are required and email types', function () {
286
+ var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', true)];
287
+ var PAGE = {
288
+ collection: COLLECTION,
289
+ components: COMPONENTS,
290
+ formData: DATA
291
+ };
292
+ expect((0, _validatePage.default)(PAGE).length).toEqual(0);
293
+ });
294
+ });
295
+ describe('when the form data has one field missing and includes an invalid email', function () {
296
+ var _DATA2;
297
+
298
+ var DATA = (_DATA2 = {}, _defineProperty(_DATA2, "".concat(COLLECTION.name, "ActiveId"), '01'), _defineProperty(_DATA2, COLLECTION.name, [{
299
+ id: '01',
300
+ alpha: 'alpha.smith@digital.homeoffice.gov.uk',
301
+ bravo: 'bravo.jones@hotmail.com'
302
+ }]), _DATA2);
303
+ it('should return no errors when none of the components are required or email types', function () {
304
+ var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', false), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', false), setup('charlie', _models.ComponentTypes.TEXT, 'Charlie', false)];
305
+ var PAGE = {
306
+ collection: COLLECTION,
307
+ components: COMPONENTS,
38
308
  formData: null
39
309
  };
40
310
  expect((0, _validatePage.default)(PAGE).length).toEqual(0);
41
311
  });
42
- describe('when there is no form data', function () {
43
- it('should return no errors when no components are required', function () {
44
- var COMPONENTS = [setup('a', _models.ComponentTypes.TEXT, 'Alpha', false), setup('b', _models.ComponentTypes.TEXT, 'Bravo', false)];
45
- var PAGE = {
46
- components: COMPONENTS,
47
- formData: null
48
- };
49
- expect((0, _validatePage.default)(PAGE).length).toEqual(0);
50
- });
51
- it('should return an error for each required component', function () {
52
- 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
53
- setup('d', _models.ComponentTypes.TEXT, 'Delta', true), setup('e', _models.ComponentTypes.TEXT, 'Echo', true)];
54
- var PAGE = {
55
- components: COMPONENTS,
56
- formData: null
57
- };
58
- var RESULT = (0, _validatePage.default)(PAGE);
59
- expect(RESULT.length).toEqual(4);
60
- expect(RESULT[0]).toEqual({
61
- id: 'a',
62
- error: 'Alpha is required'
63
- });
64
- expect(RESULT[1]).toEqual({
65
- id: 'b',
66
- error: 'Bravo is required'
67
- });
68
- expect(RESULT[2]).toEqual({
69
- id: 'd',
70
- error: 'Delta is required'
71
- });
72
- expect(RESULT[3]).toEqual({
73
- id: 'e',
74
- error: 'Echo is required'
75
- });
76
- });
77
- it('should return an error for each required component with interpolated label', function () {
78
- var COMPONENTS = [// eslint-disable-next-line no-template-curly-in-string
79
- setup('a', _models.ComponentTypes.TEXT, 'Alpha ${tiger}', true), // eslint-disable-next-line no-template-curly-in-string
80
- setup('b', _models.ComponentTypes.EMAIL, 'Bravo ${panther}', true), // eslint-disable-next-line no-template-curly-in-string
81
- setup('c', _models.ComponentTypes.AUTOCOMPLETE, 'Charlie ${eagle}', true), // eslint-disable-next-line no-template-curly-in-string
82
- setup('d', _models.ComponentTypes.CHECKBOXES, 'Delta ${lion}', true), // eslint-disable-next-line no-template-curly-in-string
83
- setup('e', _models.ComponentTypes.FILE, 'Echo ${zoo}', true)];
84
- var PAGE = {
85
- components: COMPONENTS,
86
- formData: {
87
- tiger: 'Tiger',
88
- panther: 'Panther',
89
- eagle: 'Eagle',
90
- lion: 'Lion',
91
- zoo: 'Zoo'
92
- }
93
- };
94
- var RESULT = (0, _validatePage.default)(PAGE);
95
- expect(RESULT.length).toEqual(5);
96
- expect(RESULT[0]).toEqual({
97
- id: 'a',
98
- error: "Alpha ".concat(PAGE.formData.tiger, " is required")
99
- });
100
- expect(RESULT[1]).toEqual({
101
- id: 'b',
102
- error: "Bravo ".concat(PAGE.formData.panther, " is required")
103
- });
104
- expect(RESULT[2]).toEqual({
105
- id: 'c',
106
- error: "Charlie ".concat(PAGE.formData.eagle, " is required")
107
- });
108
- expect(RESULT[3]).toEqual({
109
- id: 'd',
110
- error: "Delta ".concat(PAGE.formData.lion, " is required")
111
- });
112
- expect(RESULT[4]).toEqual({
113
- id: 'e',
114
- error: "Echo ".concat(PAGE.formData.zoo, " is required")
115
- });
116
- });
117
- });
118
- describe('when the form data is fully valid', function () {
119
- var DATA = {
120
- alpha: 'alpha.smith@digital.homeoffice.gov.uk',
121
- bravo: 'bravo.jones@digital.homeoffice.gov.uk'
122
- };
123
- it('should return no errors when none of the components are required or email types', function () {
124
- var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', false), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', false)];
125
- var PAGE = {
126
- components: COMPONENTS,
127
- formData: DATA
128
- };
129
- expect((0, _validatePage.default)(PAGE).length).toEqual(0);
130
- });
131
- it('should return no errors when all of the components are required but not email types', function () {
132
- var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', true), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', true)];
133
- var PAGE = {
134
- components: COMPONENTS,
135
- formData: DATA
136
- };
137
- expect((0, _validatePage.default)(PAGE).length).toEqual(0);
138
- });
139
- it('should return no errors when none of the components are required but are all email types', function () {
140
- var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', false), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', false)];
141
- var PAGE = {
142
- components: COMPONENTS,
143
- formData: DATA
144
- };
145
- expect((0, _validatePage.default)(PAGE).length).toEqual(0);
146
- });
147
- it('should return no errors when all of the components are required and email types', function () {
148
- var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', true)];
149
- var PAGE = {
150
- components: COMPONENTS,
151
- formData: DATA
152
- };
153
- expect((0, _validatePage.default)(PAGE).length).toEqual(0);
154
- });
155
- });
156
- describe('when the form data has one field missing and includes an invalid email', function () {
157
- var DATA = {
158
- alpha: 'alpha.smith@digital.homeoffice.gov.uk',
159
- bravo: 'bravo.jones@hotmail.com'
160
- };
161
- it('should return no errors when none of the components are required or email types', function () {
162
- var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', false), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', false), setup('charlie', _models.ComponentTypes.TEXT, 'Charlie', false)];
163
- var PAGE = {
164
- components: COMPONENTS,
165
- formData: null
166
- };
167
- expect((0, _validatePage.default)(PAGE).length).toEqual(0);
168
- });
169
- it('should return an error for the missing field when all are required but not email types', function () {
170
- var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', true), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', true), setup('charlie', _models.ComponentTypes.TEXT, 'Charlie', true)];
171
- var PAGE = {
172
- components: COMPONENTS,
173
- formData: DATA
174
- };
175
- var RESULT = (0, _validatePage.default)(PAGE);
176
- expect(RESULT.length).toEqual(1);
177
- expect(RESULT[0]).toEqual({
178
- id: 'charlie',
179
- error: 'Charlie is required'
180
- });
181
- });
182
- it('should return an error for the invalid email field when none are required but all email types', function () {
183
- var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', false), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', false), setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie', false)];
184
- var PAGE = {
185
- components: COMPONENTS,
186
- formData: DATA
187
- };
188
- var RESULT = (0, _validatePage.default)(PAGE);
189
- expect(RESULT.length).toEqual(1);
190
- expect(RESULT[0]).toEqual({
191
- id: 'bravo',
192
- error: 'Enter bravo in the correct format, like jane.doe@homeoffice.gov.uk'
193
- });
194
- });
195
- it('should return an error for both invalid fields when all are required and email types', function () {
196
- var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', true), setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie', true)];
197
- var PAGE = {
198
- components: COMPONENTS,
199
- formData: DATA
200
- };
201
- var RESULT = (0, _validatePage.default)(PAGE);
202
- expect(RESULT.length).toEqual(2);
203
- expect(RESULT[0]).toEqual({
204
- id: 'bravo',
205
- error: 'Enter bravo in the correct format, like jane.doe@homeoffice.gov.uk'
206
- });
207
- expect(RESULT[1]).toEqual({
208
- id: 'charlie',
209
- error: 'Charlie is required'
210
- });
211
- });
212
- it('should return an interpolated error for both invalid fields when all are required and email types', function () {
213
- var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true), // eslint-disable-next-line no-template-curly-in-string
214
- setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo ${lion}', true), // eslint-disable-next-line no-template-curly-in-string
215
- setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie ${panther}', true)];
216
- var PAGE = {
217
- components: COMPONENTS,
218
- formData: _objectSpread(_objectSpread({}, DATA), {}, {
219
- lion: 'Lion',
220
- panther: 'Panther'
221
- })
222
- };
223
- var RESULT = (0, _validatePage.default)(PAGE);
224
- expect(RESULT.length).toEqual(2);
225
- expect(RESULT[0]).toEqual({
226
- id: 'bravo',
227
- error: "Enter bravo ".concat(PAGE.formData.lion, " in the correct format, like jane.doe@homeoffice.gov.uk")
228
- });
229
- expect(RESULT[1]).toEqual({
230
- id: 'charlie',
231
- error: "Charlie ".concat(PAGE.formData.panther, " is required")
232
- });
312
+ it('should return an error for the missing field when all are required but not email types', function () {
313
+ var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', true), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', true), setup('charlie', _models.ComponentTypes.TEXT, 'Charlie', true)];
314
+ var PAGE = {
315
+ collection: COLLECTION,
316
+ components: COMPONENTS,
317
+ formData: DATA
318
+ };
319
+ var RESULT = (0, _validatePage.default)(PAGE);
320
+ expect(RESULT.length).toEqual(1);
321
+ expect(RESULT[0]).toEqual({
322
+ id: 'charlie',
323
+ error: 'Charlie is required'
324
+ });
325
+ });
326
+ it('should return an error for the invalid email field when none are required but all email types', function () {
327
+ var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', false), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', false), setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie', false)];
328
+ var PAGE = {
329
+ collection: COLLECTION,
330
+ components: COMPONENTS,
331
+ formData: DATA
332
+ };
333
+ var RESULT = (0, _validatePage.default)(PAGE);
334
+ expect(RESULT.length).toEqual(1);
335
+ expect(RESULT[0]).toEqual({
336
+ id: 'bravo',
337
+ error: 'Enter bravo in the correct format, like jane.doe@homeoffice.gov.uk'
338
+ });
339
+ });
340
+ it('should return an error for both invalid fields when all are required and email types', function () {
341
+ var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', true), setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie', true)];
342
+ var PAGE = {
343
+ collection: COLLECTION,
344
+ components: COMPONENTS,
345
+ formData: DATA
346
+ };
347
+ var RESULT = (0, _validatePage.default)(PAGE);
348
+ expect(RESULT.length).toEqual(2);
349
+ expect(RESULT[0]).toEqual({
350
+ id: 'bravo',
351
+ error: 'Enter bravo in the correct format, like jane.doe@homeoffice.gov.uk'
352
+ });
353
+ expect(RESULT[1]).toEqual({
354
+ id: 'charlie',
355
+ error: 'Charlie is required'
356
+ });
357
+ });
358
+ it('should return an interpolated error for both invalid fields when all are required and email types', function () {
359
+ var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true), // eslint-disable-next-line no-template-curly-in-string
360
+ setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo ${lion}', true), // eslint-disable-next-line no-template-curly-in-string
361
+ setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie ${panther}', true)];
362
+ var PAGE = {
363
+ collection: COLLECTION,
364
+ components: COMPONENTS,
365
+ formData: _objectSpread(_objectSpread({}, DATA), {}, _defineProperty({}, COLLECTION.name, [_objectSpread(_objectSpread({}, DATA[COLLECTION.name][0]), {}, {
366
+ lion: 'Lion',
367
+ panther: 'Panther'
368
+ })]))
369
+ };
370
+ var RESULT = (0, _validatePage.default)(PAGE);
371
+ expect(RESULT.length).toEqual(2);
372
+ expect(RESULT[0]).toEqual({
373
+ id: 'bravo',
374
+ error: "Enter bravo ".concat(PAGE.formData[COLLECTION.name][0].lion, " in the correct format, like jane.doe@homeoffice.gov.uk")
375
+ });
376
+ expect(RESULT[1]).toEqual({
377
+ id: 'charlie',
378
+ error: "Charlie ".concat(PAGE.formData[COLLECTION.name][0].panther, " is required")
233
379
  });
234
380
  });
235
381
  });
@@ -11,6 +11,8 @@ var _CheckYourAnswers = _interopRequireDefault(require("./CheckYourAnswers"));
11
11
 
12
12
  var _Component = _interopRequireDefault(require("./Component"));
13
13
 
14
+ var _CollectionPage = _interopRequireDefault(require("./CollectionPage"));
15
+
14
16
  var _Condition = _interopRequireDefault(require("./Condition"));
15
17
 
16
18
  var _Container = _interopRequireDefault(require("./Container"));
@@ -37,6 +39,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
37
39
 
38
40
  var Utils = _objectSpread({
39
41
  CheckYourAnswers: _CheckYourAnswers.default,
42
+ CollectionPage: _CollectionPage.default,
40
43
  Component: _Component.default,
41
44
  Condition: _Condition.default,
42
45
  Container: _Container.default,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "3.26.3",
3
+ "version": "3.32.0",
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": "1.13.4",
19
+ "@ukhomeoffice/cop-react-components": "1.14.0",
20
20
  "axios": "^0.23.0",
21
21
  "dayjs": "^1.11.0",
22
22
  "govuk-frontend": "^3.13.0",