@ukhomeoffice/cop-react-form-renderer 2.7.4 → 2.8.4
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/CheckYourAnswers.stories.mdx +392 -331
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +66 -7
- package/dist/components/FormRenderer/FormRenderer.js +29 -9
- package/dist/components/FormRenderer/FormRenderer.test.js +10 -9
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +10 -3
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +3 -3
- package/dist/components/TaskList/Task.js +7 -1
- package/dist/components/TaskList/TaskList.js +3 -3
- package/dist/components/TaskList/TaskList.scss +5 -6
- package/dist/json/group.data.json +21 -0
- package/dist/json/group.json +418 -0
- package/dist/json/userProfile.data.json +6 -0
- package/dist/utils/CheckYourAnswers/getCYARow.js +1 -0
- package/dist/utils/CheckYourAnswers/getCYARow.test.js +2 -0
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.js +82 -0
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.test.js +78 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +29 -3
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +61 -0
- package/package.json +1 -1
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "userProfile",
|
|
3
|
+
"version": "1",
|
|
4
|
+
"name": "userProfile",
|
|
5
|
+
"title": "Your profile",
|
|
6
|
+
"type": "hub-and-spoke",
|
|
7
|
+
"components": [
|
|
8
|
+
{
|
|
9
|
+
"id": "firstName",
|
|
10
|
+
"fieldId": "firstName",
|
|
11
|
+
"label": "First name",
|
|
12
|
+
"type": "input",
|
|
13
|
+
"readonly": true,
|
|
14
|
+
"groupId": "addressDetails",
|
|
15
|
+
"source": {
|
|
16
|
+
"field": "currentUser.givenName"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"id": "surname",
|
|
21
|
+
"fieldId": "surname",
|
|
22
|
+
"label": "Last name",
|
|
23
|
+
"type": "text",
|
|
24
|
+
"readonly": true,
|
|
25
|
+
"groupId": "addressDetails",
|
|
26
|
+
"source": {
|
|
27
|
+
"field": "currentUser.familyName"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"id": "areYouACivilServant",
|
|
32
|
+
"fieldId": "areYouACivilServant",
|
|
33
|
+
"label": "Are you a civil servant?",
|
|
34
|
+
"type": "radios",
|
|
35
|
+
"required": true,
|
|
36
|
+
"groupId": "addressDetails",
|
|
37
|
+
"data": {
|
|
38
|
+
"url": "${urls.refData}/areYouACivilServant"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"id": "staffGradeId",
|
|
43
|
+
"fieldId": "staffGradeId",
|
|
44
|
+
"label": "Grade",
|
|
45
|
+
"hint": "We use this to assign you tasks",
|
|
46
|
+
"type": "radios",
|
|
47
|
+
"required": true,
|
|
48
|
+
"data": {
|
|
49
|
+
"url": "${urls.refData}/grade"
|
|
50
|
+
},
|
|
51
|
+
"source": {
|
|
52
|
+
"field": "userDetails.gradeid"
|
|
53
|
+
},
|
|
54
|
+
"show_when": {
|
|
55
|
+
"field": "areYouACivilServant",
|
|
56
|
+
"op": "eq",
|
|
57
|
+
"value": "yes"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"id": "team",
|
|
62
|
+
"fieldId": "team",
|
|
63
|
+
"label": "Team",
|
|
64
|
+
"hint": "We use this to assign you tasks",
|
|
65
|
+
"type": "autocomplete",
|
|
66
|
+
"required": true,
|
|
67
|
+
"item": {
|
|
68
|
+
"value": "id",
|
|
69
|
+
"label": "name"
|
|
70
|
+
},
|
|
71
|
+
"data": {
|
|
72
|
+
"url": "${urls.refData}/team"
|
|
73
|
+
},
|
|
74
|
+
"displayMenu": "inline",
|
|
75
|
+
"source": {
|
|
76
|
+
"field": "userDetails.defaultteam"
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"id": "linemanagerEmail",
|
|
81
|
+
"fieldId": "linemanagerEmail",
|
|
82
|
+
"label": "Line manager email",
|
|
83
|
+
"hint": "Must be a homeoffice.gov.uk or digital.homeoffice.gov.uk address",
|
|
84
|
+
"type": "email",
|
|
85
|
+
"format": {
|
|
86
|
+
"type": "lowercase",
|
|
87
|
+
"on": "submit"
|
|
88
|
+
},
|
|
89
|
+
"required": true,
|
|
90
|
+
"source": {
|
|
91
|
+
"field": "userDetails.linemanagerEmail"
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"id": "delegateEmails",
|
|
96
|
+
"fieldId": "delegateEmails",
|
|
97
|
+
"label": "Delegate email",
|
|
98
|
+
"hint": "Must be a homeoffice.gov.uk or digital.homeoffice.gov.uk address",
|
|
99
|
+
"type": "email",
|
|
100
|
+
"format": {
|
|
101
|
+
"type": "lowercase",
|
|
102
|
+
"on": "submit"
|
|
103
|
+
},
|
|
104
|
+
"required": true,
|
|
105
|
+
"source": {
|
|
106
|
+
"field": "userDetails.delegateEmails"
|
|
107
|
+
},
|
|
108
|
+
"show_when": [
|
|
109
|
+
{
|
|
110
|
+
"field": "areYouACivilServant",
|
|
111
|
+
"op": "eq",
|
|
112
|
+
"value": "yes"
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
"field": "staffGradeId",
|
|
116
|
+
"op": "in",
|
|
117
|
+
"values": [
|
|
118
|
+
"373979c1-2360-46be-b712-0409ac068059",
|
|
119
|
+
"36c80dfe-0aae-455b-9445-2e1c09dcafdc",
|
|
120
|
+
"1b041cda-b151-4769-b76a-d42d67b0b960",
|
|
121
|
+
"172de41d-f7b0-4be9-b7e8-0cf4f1a1342f",
|
|
122
|
+
"39e18b45-0358-4a45-83ec-5a70b74641e8"
|
|
123
|
+
]
|
|
124
|
+
}
|
|
125
|
+
]
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
"id": "firstLineOfTheAddress",
|
|
129
|
+
"fieldId": "firstLineOfTheAddress",
|
|
130
|
+
"label": "Address",
|
|
131
|
+
"type": "text",
|
|
132
|
+
"required": true,
|
|
133
|
+
"groupId": "addressDetails",
|
|
134
|
+
"custom_errors": [
|
|
135
|
+
{
|
|
136
|
+
"type": "required",
|
|
137
|
+
"message": "Please enter first line of the the address"
|
|
138
|
+
}
|
|
139
|
+
],
|
|
140
|
+
"source": {
|
|
141
|
+
"field": "addressDetails.firstLineOfTheAddress"
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
"id": "city",
|
|
146
|
+
"fieldId": "city",
|
|
147
|
+
"label": "City",
|
|
148
|
+
"type": "text",
|
|
149
|
+
"required": true,
|
|
150
|
+
"groupId": "addressDetails",
|
|
151
|
+
"custom_errors": [
|
|
152
|
+
{
|
|
153
|
+
"type": "required",
|
|
154
|
+
"message": "Please enter city"
|
|
155
|
+
}
|
|
156
|
+
],
|
|
157
|
+
"source": {
|
|
158
|
+
"field": "addressDetails.city"
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
"id": "town",
|
|
163
|
+
"fieldId": "town",
|
|
164
|
+
"label": "Town",
|
|
165
|
+
"type": "text",
|
|
166
|
+
"required": true,
|
|
167
|
+
|
|
168
|
+
"custom_errors": [
|
|
169
|
+
{
|
|
170
|
+
"type": "required",
|
|
171
|
+
"message": "Please enter Town"
|
|
172
|
+
}
|
|
173
|
+
],
|
|
174
|
+
"source": {
|
|
175
|
+
"field": "addressDetails.town"
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
"id": "postCode",
|
|
180
|
+
"fieldId": "postCode",
|
|
181
|
+
"label": "Postcode",
|
|
182
|
+
"type": "text",
|
|
183
|
+
"required": true,
|
|
184
|
+
"groupId": "addressDetails",
|
|
185
|
+
"custom_errors": [
|
|
186
|
+
{
|
|
187
|
+
"type": "required",
|
|
188
|
+
"message": "Please enter postcode"
|
|
189
|
+
}
|
|
190
|
+
],
|
|
191
|
+
"source": {
|
|
192
|
+
"field": "addressDetails.postCode"
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
"id": "postCode",
|
|
197
|
+
"fieldId": "postCode",
|
|
198
|
+
"label": "Postcode",
|
|
199
|
+
"type": "text",
|
|
200
|
+
"required": true,
|
|
201
|
+
"groupId": "addressDetails",
|
|
202
|
+
"custom_errors": [
|
|
203
|
+
{
|
|
204
|
+
"type": "required",
|
|
205
|
+
"message": "Please enter postcode"
|
|
206
|
+
}
|
|
207
|
+
],
|
|
208
|
+
"source": {
|
|
209
|
+
"field": "addressDetails.postCode"
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
],
|
|
213
|
+
"pages": [
|
|
214
|
+
{
|
|
215
|
+
"id": "names",
|
|
216
|
+
"name": "names",
|
|
217
|
+
"components": [
|
|
218
|
+
{
|
|
219
|
+
"use": "firstName"
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
"use": "surname"
|
|
223
|
+
}
|
|
224
|
+
]
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
"id": "civil-servant-status",
|
|
228
|
+
"name": "civil-servant-status",
|
|
229
|
+
"title": "Are you a civil servant?",
|
|
230
|
+
"components": [
|
|
231
|
+
{
|
|
232
|
+
"use": "areYouACivilServant",
|
|
233
|
+
"label": ""
|
|
234
|
+
}
|
|
235
|
+
],
|
|
236
|
+
"actions": ["submit"],
|
|
237
|
+
"cya_link": {
|
|
238
|
+
"page": "civil-servant-status",
|
|
239
|
+
"aria_suffix": "civil servant status"
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
"id": "grade",
|
|
244
|
+
"name": "grade",
|
|
245
|
+
"title": "What's your grade?",
|
|
246
|
+
"components": [
|
|
247
|
+
{
|
|
248
|
+
"use": "staffGradeId",
|
|
249
|
+
"label": ""
|
|
250
|
+
}
|
|
251
|
+
],
|
|
252
|
+
"actions": ["submit"],
|
|
253
|
+
"cya_link": {
|
|
254
|
+
"page": "grade",
|
|
255
|
+
"aria_suffix": "grade"
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
"id": "team-name",
|
|
260
|
+
"name": "team-name",
|
|
261
|
+
"title": "What's your team name?",
|
|
262
|
+
"components": [
|
|
263
|
+
{
|
|
264
|
+
"use": "team",
|
|
265
|
+
"label": ""
|
|
266
|
+
}
|
|
267
|
+
],
|
|
268
|
+
"actions": ["submit"],
|
|
269
|
+
"cya_link": {
|
|
270
|
+
"page": "team-name",
|
|
271
|
+
"aria_suffix": "teams"
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
"id": "add-or-change-line-manager",
|
|
276
|
+
"name": "add-or-change-line-manager",
|
|
277
|
+
"title": "Add or change a line manager",
|
|
278
|
+
"components": [
|
|
279
|
+
"Your line manager will need to review some of your forms. It’s important to keep their details up-to-date.",
|
|
280
|
+
"An email will be sent to your line manager to ask if they want to approve your request to add them.",
|
|
281
|
+
{
|
|
282
|
+
"type": "inset-text",
|
|
283
|
+
"content": "The changes will show in your profile when they approve your request."
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
"type": "heading",
|
|
287
|
+
"size": "m",
|
|
288
|
+
"content": "Mandatory declarations"
|
|
289
|
+
},
|
|
290
|
+
"Mandatory declarations will not go to your line manager until they have approved your request."
|
|
291
|
+
],
|
|
292
|
+
"actions": [
|
|
293
|
+
{
|
|
294
|
+
"type": "navigate",
|
|
295
|
+
"page": "line-manager-email"
|
|
296
|
+
}
|
|
297
|
+
],
|
|
298
|
+
"show_on_cya": false
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
"id": "line-manager-email",
|
|
302
|
+
"name": "line-manager-email",
|
|
303
|
+
"title": "What’s your line manager’s email address?",
|
|
304
|
+
"components": [
|
|
305
|
+
{
|
|
306
|
+
"use": "linemanagerEmail"
|
|
307
|
+
}
|
|
308
|
+
],
|
|
309
|
+
"actions": ["submit"],
|
|
310
|
+
"cya_link": {
|
|
311
|
+
"page": "add-or-change-line-manager",
|
|
312
|
+
"aria_suffix": "line manager email address"
|
|
313
|
+
}
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
"id": "add-or-change-delegate",
|
|
317
|
+
"name": "add-or-change-delegate",
|
|
318
|
+
"title": "Add or change a delegate",
|
|
319
|
+
"components": [
|
|
320
|
+
"A delegate can review a mandatory declaration on your behalf.",
|
|
321
|
+
"An email will be sent to the delegate to ask if they want to approve your request.",
|
|
322
|
+
{
|
|
323
|
+
"type": "inset-text",
|
|
324
|
+
"content": "The changes will show in your profile when they approve your request."
|
|
325
|
+
}
|
|
326
|
+
],
|
|
327
|
+
"actions": [
|
|
328
|
+
{
|
|
329
|
+
"type": "navigate",
|
|
330
|
+
"page": "delegate-email"
|
|
331
|
+
}
|
|
332
|
+
],
|
|
333
|
+
"show_on_cya": false
|
|
334
|
+
},
|
|
335
|
+
{
|
|
336
|
+
"id": "delegate-email",
|
|
337
|
+
"name": "delegate-email",
|
|
338
|
+
"title": "What’s your delegate's email address?",
|
|
339
|
+
"components": [
|
|
340
|
+
{
|
|
341
|
+
"use": "delegateEmails",
|
|
342
|
+
"label": "Delegate email address"
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
"use": "delegateEmails",
|
|
346
|
+
"label": "Delegate email address"
|
|
347
|
+
}
|
|
348
|
+
],
|
|
349
|
+
"actions": ["submit"],
|
|
350
|
+
"cya_link": {
|
|
351
|
+
"page": "add-or-change-delegate"
|
|
352
|
+
},
|
|
353
|
+
"show_when": [
|
|
354
|
+
{
|
|
355
|
+
"field": "areYouACivilServant",
|
|
356
|
+
"op": "eq",
|
|
357
|
+
"value": "yes"
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
"field": "staffGradeId",
|
|
361
|
+
"op": "in",
|
|
362
|
+
"values": [
|
|
363
|
+
"373979c1-2360-46be-b712-0409ac068059",
|
|
364
|
+
"36c80dfe-0aae-455b-9445-2e1c09dcafdc",
|
|
365
|
+
"1b041cda-b151-4769-b76a-d42d67b0b960",
|
|
366
|
+
"172de41d-f7b0-4be9-b7e8-0cf4f1a1342f",
|
|
367
|
+
"39e18b45-0358-4a45-83ec-5a70b74641e8"
|
|
368
|
+
]
|
|
369
|
+
}
|
|
370
|
+
]
|
|
371
|
+
},
|
|
372
|
+
|
|
373
|
+
{
|
|
374
|
+
"id": "address-details",
|
|
375
|
+
"groupLabel": "UK address",
|
|
376
|
+
"fieldId": "UK address",
|
|
377
|
+
"groups": [
|
|
378
|
+
{
|
|
379
|
+
"id": "address",
|
|
380
|
+
"label": "Address details",
|
|
381
|
+
"components": ["firstLineOfTheAddress", "town", "city", "postCode"]
|
|
382
|
+
}
|
|
383
|
+
],
|
|
384
|
+
"name": "address-details",
|
|
385
|
+
"title": "Address details",
|
|
386
|
+
"components": [
|
|
387
|
+
{
|
|
388
|
+
"use": "firstLineOfTheAddress",
|
|
389
|
+
"label": "Address"
|
|
390
|
+
},
|
|
391
|
+
{
|
|
392
|
+
"use": "town",
|
|
393
|
+
"label": "Town"
|
|
394
|
+
},
|
|
395
|
+
{
|
|
396
|
+
"use": "city",
|
|
397
|
+
"label": "City"
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
"use": "postCode",
|
|
401
|
+
"label": "Postcode"
|
|
402
|
+
}
|
|
403
|
+
],
|
|
404
|
+
"actions": ["saveAndContinue", "saveAndReturn"],
|
|
405
|
+
"cya_link": {
|
|
406
|
+
"url": "/address-details",
|
|
407
|
+
"aria_suffix": "address details"
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
],
|
|
411
|
+
"hub": {
|
|
412
|
+
"format": "CYA"
|
|
413
|
+
},
|
|
414
|
+
"cya": {
|
|
415
|
+
"hide_page_titles": true,
|
|
416
|
+
"hide_actions": true
|
|
417
|
+
}
|
|
418
|
+
}
|
|
@@ -11,5 +11,11 @@
|
|
|
11
11
|
"linemanagerEmail": "line.manager@digital.homeoffice.gov.uk",
|
|
12
12
|
"delegateEmails": "del.egate@digital.homeoffice.gov.uk"
|
|
13
13
|
},
|
|
14
|
+
"addressDetails": {
|
|
15
|
+
"firstLineOfTheAddress": "10 Downing Street",
|
|
16
|
+
"city": "London",
|
|
17
|
+
"town": "City of Westminster",
|
|
18
|
+
"postCode": "SW1A 2AA"
|
|
19
|
+
},
|
|
14
20
|
"businessKey": "123456789"
|
|
15
21
|
}
|
|
@@ -31,6 +31,7 @@ var getCYARow = function getCYARow(page, component, onAction) {
|
|
|
31
31
|
|
|
32
32
|
return {
|
|
33
33
|
pageId: page.id,
|
|
34
|
+
id: component.id,
|
|
34
35
|
fieldId: component.fieldId,
|
|
35
36
|
key: component.label || component.cya_label,
|
|
36
37
|
component: _Component.default.editable(component) ? component : undefined,
|
|
@@ -58,6 +58,7 @@ describe('utils', function () {
|
|
|
58
58
|
|
|
59
59
|
expect((0, _getCYARow.default)(PAGE, COMPONENT, ON_ACTION)).toEqual({
|
|
60
60
|
pageId: PAGE.id,
|
|
61
|
+
id: COMPONENT.id,
|
|
61
62
|
fieldId: COMPONENT.fieldId,
|
|
62
63
|
key: COMPONENT.label,
|
|
63
64
|
value: '',
|
|
@@ -84,6 +85,7 @@ describe('utils', function () {
|
|
|
84
85
|
|
|
85
86
|
expect((0, _getCYARow.default)(PAGE, COMPONENT, ON_ACTION)).toEqual({
|
|
86
87
|
pageId: PAGE.id,
|
|
88
|
+
id: COMPONENT.id,
|
|
87
89
|
fieldId: COMPONENT.fieldId,
|
|
88
90
|
key: COMPONENT.label,
|
|
89
91
|
value: 'BLAH',
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
|
|
10
|
+
var _FormComponent = _interopRequireDefault(require("../../components/FormComponent"));
|
|
11
|
+
|
|
12
|
+
var _getCYAAction = _interopRequireDefault(require("./getCYAAction"));
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
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; }
|
|
17
|
+
|
|
18
|
+
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; }
|
|
19
|
+
|
|
20
|
+
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; }
|
|
21
|
+
|
|
22
|
+
var getRowValue = function getRowValue(row) {
|
|
23
|
+
if (!row.value) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (!row.component) {
|
|
28
|
+
return row.value;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
32
|
+
key: row.id
|
|
33
|
+
}, /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
34
|
+
component: _objectSpread(_objectSpread({}, row.component), {}, {
|
|
35
|
+
readonly: true
|
|
36
|
+
}),
|
|
37
|
+
wrap: false,
|
|
38
|
+
value: row.value
|
|
39
|
+
}));
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
var getGroupValue = function getGroupValue(group, rows) {
|
|
43
|
+
var firstComponentIndex = -1;
|
|
44
|
+
|
|
45
|
+
var value = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, group.components.map(function (componentId) {
|
|
46
|
+
var rowIndex = rows.findIndex(function (r) {
|
|
47
|
+
return r.id === componentId;
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
if (firstComponentIndex < 0) {
|
|
51
|
+
firstComponentIndex = rowIndex;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return rowIndex > -1 ? getRowValue(rows[rowIndex]) : null;
|
|
55
|
+
}));
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
value: value,
|
|
59
|
+
firstComponentIndex: firstComponentIndex
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
var getCYARowForGroup = function getCYARowForGroup(page, group, rows, onAction) {
|
|
64
|
+
var _getGroupValue = getGroupValue(group, rows),
|
|
65
|
+
value = _getGroupValue.value,
|
|
66
|
+
firstComponentIndex = _getGroupValue.firstComponentIndex;
|
|
67
|
+
|
|
68
|
+
var row = {
|
|
69
|
+
pageId: page.id,
|
|
70
|
+
fieldId: group.id,
|
|
71
|
+
key: group.label,
|
|
72
|
+
value: value,
|
|
73
|
+
action: (0, _getCYAAction.default)(false, page, onAction)
|
|
74
|
+
};
|
|
75
|
+
return {
|
|
76
|
+
row: row,
|
|
77
|
+
insertAt: firstComponentIndex
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
var _default = getCYARowForGroup;
|
|
82
|
+
exports.default = _default;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _react = require("@testing-library/react");
|
|
4
|
+
|
|
5
|
+
var _getCYARowForGroup = _interopRequireDefault(require("./getCYARowForGroup"));
|
|
6
|
+
|
|
7
|
+
var _getCYARow = _interopRequireDefault(require("./getCYARow"));
|
|
8
|
+
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
|
|
11
|
+
// Global imports
|
|
12
|
+
//local imports
|
|
13
|
+
describe('utils', function () {
|
|
14
|
+
describe('CheckYourAnswers', function () {
|
|
15
|
+
describe('getCYARowsForGroup', function () {
|
|
16
|
+
it('should check address values block', function () {
|
|
17
|
+
var COMPONENT_ADDRESS = {
|
|
18
|
+
id: 'firstLineOfTheAddress',
|
|
19
|
+
fieldId: 'firstLineOfTheAddress',
|
|
20
|
+
label: 'address',
|
|
21
|
+
type: 'text'
|
|
22
|
+
};
|
|
23
|
+
var COMPONENT_TOWN = {
|
|
24
|
+
id: 'town',
|
|
25
|
+
fieldId: 'town',
|
|
26
|
+
label: 'Town',
|
|
27
|
+
type: 'text'
|
|
28
|
+
};
|
|
29
|
+
var COMPONENT_CITY = {
|
|
30
|
+
id: 'city',
|
|
31
|
+
fieldId: 'city',
|
|
32
|
+
label: 'City',
|
|
33
|
+
type: 'text'
|
|
34
|
+
};
|
|
35
|
+
var COMPONENT_POSTCODE = {
|
|
36
|
+
id: 'postCode',
|
|
37
|
+
fieldId: 'postCode',
|
|
38
|
+
label: 'postCode',
|
|
39
|
+
type: 'text'
|
|
40
|
+
};
|
|
41
|
+
var PAGE = {
|
|
42
|
+
components: [COMPONENT_ADDRESS, COMPONENT_TOWN, COMPONENT_CITY, COMPONENT_POSTCODE],
|
|
43
|
+
id: 'addressDetails',
|
|
44
|
+
fieldId: 'UK address',
|
|
45
|
+
groups: [{
|
|
46
|
+
id: 'address',
|
|
47
|
+
label: 'Address details',
|
|
48
|
+
components: ['firstLineOfTheAddress', 'town', 'city', 'postCode']
|
|
49
|
+
}],
|
|
50
|
+
name: 'address-details',
|
|
51
|
+
title: 'Address details',
|
|
52
|
+
formData: {
|
|
53
|
+
firstLineOfTheAddress: '10 Downing Street',
|
|
54
|
+
town: 'City of Westminster',
|
|
55
|
+
city: 'London',
|
|
56
|
+
postCode: 'SW1A 2AA'
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
var ON_ACTION = function ON_ACTION() {};
|
|
61
|
+
|
|
62
|
+
var rows = PAGE.components.map(function (component) {
|
|
63
|
+
return (0, _getCYARow.default)(PAGE, component, ON_ACTION);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
var _render = (0, _react.render)((0, _getCYARowForGroup.default)(PAGE, PAGE.groups[0], rows, ON_ACTION).row.value),
|
|
67
|
+
container = _render.container;
|
|
68
|
+
|
|
69
|
+
expect(container.childNodes.length).toEqual(4);
|
|
70
|
+
var addressValues = container.childNodes;
|
|
71
|
+
expect(addressValues[0].childNodes[0].textContent).toEqual('10 Downing Street');
|
|
72
|
+
expect(addressValues[1].childNodes[0].textContent).toEqual('City of Westminster');
|
|
73
|
+
expect(addressValues[2].childNodes[0].textContent).toEqual('London');
|
|
74
|
+
expect(addressValues[3].childNodes[0].textContent).toEqual('SW1A 2AA');
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -11,6 +11,8 @@ var _FormPage = _interopRequireDefault(require("../FormPage"));
|
|
|
11
11
|
|
|
12
12
|
var _getCYARow = _interopRequireDefault(require("./getCYARow"));
|
|
13
13
|
|
|
14
|
+
var _getCYARowForGroup2 = _interopRequireDefault(require("./getCYARowForGroup"));
|
|
15
|
+
|
|
14
16
|
var _getCYARowsForContainer = _interopRequireDefault(require("./getCYARowsForContainer"));
|
|
15
17
|
|
|
16
18
|
var _showComponentCYA = _interopRequireDefault(require("./showComponentCYA"));
|
|
@@ -21,15 +23,17 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
21
23
|
|
|
22
24
|
/**
|
|
23
25
|
* Gets an array of row objects, each configured appropriately for a Check your answers component.
|
|
24
|
-
*
|
|
26
|
+
*
|
|
25
27
|
* @param {object} page The page to show components for.
|
|
26
28
|
* @param {Function} onAction A function to invoke if the change link on any row is clicked.
|
|
27
|
-
*
|
|
29
|
+
*
|
|
28
30
|
* @returns An array of configuration objects for Check your answers rows.
|
|
29
31
|
*/
|
|
30
32
|
var getCYARowsForPage = function getCYARowsForPage(page, onAction) {
|
|
31
33
|
if (_FormPage.default.show(page, page.formData)) {
|
|
32
|
-
|
|
34
|
+
var _page$groups;
|
|
35
|
+
|
|
36
|
+
var rows = page.components.filter(function (c) {
|
|
33
37
|
return (0, _showComponentCYA.default)(c, page.formData);
|
|
34
38
|
}).flatMap(function (component) {
|
|
35
39
|
if (component.type === _models.ComponentTypes.CONTAINER) {
|
|
@@ -38,6 +42,28 @@ var getCYARowsForPage = function getCYARowsForPage(page, onAction) {
|
|
|
38
42
|
|
|
39
43
|
return (0, _getCYARow.default)(page, component, onAction);
|
|
40
44
|
});
|
|
45
|
+
|
|
46
|
+
if (((_page$groups = page.groups) === null || _page$groups === void 0 ? void 0 : _page$groups.length) > 0) {
|
|
47
|
+
page.groups.forEach(function (group) {
|
|
48
|
+
var _getCYARowForGroup = (0, _getCYARowForGroup2.default)(page, group, rows, onAction),
|
|
49
|
+
row = _getCYARowForGroup.row,
|
|
50
|
+
insertAt = _getCYARowForGroup.insertAt;
|
|
51
|
+
|
|
52
|
+
if (insertAt > -1) {
|
|
53
|
+
rows.splice(insertAt, 0, row);
|
|
54
|
+
} else {
|
|
55
|
+
rows.push(row);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
var allReplacedIds = page.groups.flatMap(function (g) {
|
|
59
|
+
return g.components;
|
|
60
|
+
});
|
|
61
|
+
return rows.filter(function (r) {
|
|
62
|
+
return !allReplacedIds.includes(r.id);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return rows;
|
|
41
67
|
}
|
|
42
68
|
|
|
43
69
|
return [];
|