@ukhomeoffice/cop-react-form-renderer 1.0.0 → 2.2.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.
- package/LICENSE +21 -0
- package/README.md +12 -0
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +16 -5
- package/dist/components/CheckYourAnswers/CheckYourAnswers.stories.mdx +199 -79
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +44 -0
- package/dist/components/FormComponent/FormComponent.js +6 -1
- package/dist/components/FormComponent/FormComponent.test.js +67 -0
- package/dist/components/FormPage/FormPage.js +8 -2
- package/dist/components/FormPage/FormPage.test.js +2 -2
- package/dist/components/FormRenderer/FormRenderer.js +43 -15
- package/dist/components/FormRenderer/FormRenderer.stories.mdx +115 -49
- package/dist/components/FormRenderer/FormRenderer.test.js +40 -0
- package/dist/components/FormRenderer/handlers/getPageId.js +1 -10
- package/dist/components/FormRenderer/handlers/getPageId.test.js +5 -31
- package/dist/components/FormRenderer/handlers/handlers.test.js +2 -2
- package/dist/components/FormRenderer/helpers/getNextPageId.js +33 -26
- package/dist/components/FormRenderer/helpers/getNextPageId.test.js +89 -7
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +27 -0
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +209 -0
- package/dist/components/FormRenderer/helpers/index.js +4 -1
- package/dist/components/PageActions/PageActions.stories.mdx +1 -1
- package/dist/components/PageActions/PageActions.test.js +2 -2
- package/dist/components/SummaryList/RowAction.js +1 -1
- package/dist/components/SummaryList/RowAction.test.js +6 -6
- package/dist/components/SummaryList/SummaryList.js +8 -5
- package/dist/components/SummaryList/SummaryList.scss +10 -2
- package/dist/components/SummaryList/SummaryList.stories.mdx +64 -10
- package/dist/components/SummaryList/SummaryList.test.js +54 -0
- package/dist/components/SummaryList/helpers/getRowActionAttributes.js +2 -2
- package/dist/components/SummaryList/helpers/getRowActionAttributes.test.js +4 -4
- package/dist/hooks/useHooks.js +5 -1
- package/dist/index.js +8 -0
- package/dist/json/areYouACivilServant.json +7 -0
- package/dist/json/firstForm.json +94 -0
- package/dist/json/grade.json +108 -0
- package/dist/json/saveAndContinue.json +98 -0
- package/dist/json/team.json +17351 -0
- package/dist/json/userProfile.data.json +14 -0
- package/dist/json/userProfile.json +276 -0
- package/dist/models/ComponentTypes.js +4 -0
- package/dist/utils/CheckYourAnswers/getCYAAction.js +24 -3
- package/dist/utils/CheckYourAnswers/getCYAAction.test.js +62 -15
- package/dist/utils/CheckYourAnswers/getCYARow.js +8 -2
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +11 -5
- package/dist/utils/Component/getComponent.js +42 -0
- package/dist/utils/Component/getComponentTests/getComponent.autocomplete.test.js +75 -0
- package/dist/utils/Component/getComponentTests/getComponent.checkboxes.test.js +129 -0
- package/dist/utils/Component/getComponentTests/getComponent.date.test.js +129 -0
- package/dist/utils/Component/getComponentTests/getComponent.email.test.js +80 -0
- package/dist/utils/Component/getComponentTests/getComponent.heading.test.js +33 -0
- package/dist/utils/Component/getComponentTests/getComponent.html.test.js +45 -0
- package/dist/utils/Component/getComponentTests/getComponent.insetText.test.js +31 -0
- package/dist/utils/Component/getComponentTests/getComponent.phoneNumber.test.js +80 -0
- package/dist/utils/Component/getComponentTests/getComponent.radios.test.js +125 -0
- package/dist/utils/Component/getComponentTests/getComponent.text.test.js +80 -0
- package/dist/utils/Component/getComponentTests/getComponent.textarea.test.js +76 -0
- package/dist/utils/Component/getComponentTests/getComponent.unknown.test.js +14 -0
- package/dist/utils/Component/isEditable.js +1 -1
- package/dist/utils/Data/refDataToOptions.js +4 -0
- package/dist/utils/Data/refDataToOptions.test.js +30 -0
- package/dist/utils/FormPage/getEditableComponents.js +28 -0
- package/dist/utils/FormPage/getEditableComponents.test.js +75 -0
- package/dist/utils/FormPage/getFormPage.js +5 -1
- package/dist/utils/FormPage/getPageActions.js +66 -0
- package/dist/utils/FormPage/getPageActions.test.js +89 -0
- package/dist/utils/FormPage/index.js +7 -1
- package/dist/utils/FormPage/showFormPage.js +81 -0
- package/dist/utils/FormPage/showFormPage.test.js +131 -0
- package/dist/utils/Validate/validateComponent.js +5 -3
- package/dist/utils/Validate/validateRequired.js +11 -0
- package/dist/utils/Validate/validateRequired.test.js +12 -0
- package/package.json +9 -5
- package/dist/utils/Component/getComponent.test.js +0 -361
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"urls": {
|
|
3
|
+
"refData": "/ref-data"
|
|
4
|
+
},
|
|
5
|
+
"currentUser": {
|
|
6
|
+
"givenName": "John",
|
|
7
|
+
"familyName": "Smith"
|
|
8
|
+
},
|
|
9
|
+
"areYouACivilServant": "yes",
|
|
10
|
+
"userDetails": {
|
|
11
|
+
"linemanagerEmail": "line.manager@digital.homeoffice.gov.uk",
|
|
12
|
+
"delegateEmails": "del.egate@digital.homeoffice.gov.uk"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,276 @@
|
|
|
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": "text",
|
|
13
|
+
"readonly": true,
|
|
14
|
+
"source": {
|
|
15
|
+
"field": "currentUser.givenName"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"id": "surname",
|
|
20
|
+
"fieldId": "surname",
|
|
21
|
+
"label": "Last name",
|
|
22
|
+
"type": "text",
|
|
23
|
+
"readonly": true,
|
|
24
|
+
"source": {
|
|
25
|
+
"field": "currentUser.familyName"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"id": "areYouACivilServant",
|
|
30
|
+
"fieldId": "areYouACivilServant",
|
|
31
|
+
"label": "Are you a civil servant?",
|
|
32
|
+
"type": "radios",
|
|
33
|
+
"required": true,
|
|
34
|
+
"data": {
|
|
35
|
+
"url": "${urls.refData}/areYouACivilServant"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"id": "staffGradeId",
|
|
40
|
+
"fieldId": "staffGradeId",
|
|
41
|
+
"label": "Grade",
|
|
42
|
+
"hint": "We use this to assign you tasks",
|
|
43
|
+
"type": "radios",
|
|
44
|
+
"required": true,
|
|
45
|
+
"data": {
|
|
46
|
+
"url": "${urls.refData}/grade"
|
|
47
|
+
},
|
|
48
|
+
"source": {
|
|
49
|
+
"field": "userDetails.gradeid"
|
|
50
|
+
},
|
|
51
|
+
"show_when": {
|
|
52
|
+
"field": "areYouACivilServant",
|
|
53
|
+
"op": "eq",
|
|
54
|
+
"value": "yes"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"id": "team",
|
|
59
|
+
"fieldId": "team",
|
|
60
|
+
"label": "Team",
|
|
61
|
+
"hint": "We use this to assign you tasks",
|
|
62
|
+
"type": "autocomplete",
|
|
63
|
+
"required": true,
|
|
64
|
+
"item": { "value": "id", "label": "name" },
|
|
65
|
+
"data": {
|
|
66
|
+
"url": "${urls.refData}/team"
|
|
67
|
+
},
|
|
68
|
+
"displayMenu": "inline",
|
|
69
|
+
"source": {
|
|
70
|
+
"field": "userDetails.defaultteam"
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"id": "linemanagerEmail",
|
|
75
|
+
"fieldId": "linemanagerEmail",
|
|
76
|
+
"label": "Line manager email",
|
|
77
|
+
"hint": "Must be a homeoffice.gov.uk or digital.homeoffice.gov.uk address",
|
|
78
|
+
"type": "email",
|
|
79
|
+
"format": {
|
|
80
|
+
"type": "lowercase",
|
|
81
|
+
"on": "submit"
|
|
82
|
+
},
|
|
83
|
+
"required": true,
|
|
84
|
+
"source": {
|
|
85
|
+
"field": "userDetails.linemanagerEmail"
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"id": "delegateEmails",
|
|
90
|
+
"fieldId": "delegateEmails",
|
|
91
|
+
"label": "Delegate email",
|
|
92
|
+
"hint": "Must be a homeoffice.gov.uk or digital.homeoffice.gov.uk address",
|
|
93
|
+
"type": "email",
|
|
94
|
+
"format": {
|
|
95
|
+
"type": "lowercase",
|
|
96
|
+
"on": "submit"
|
|
97
|
+
},
|
|
98
|
+
"required": true,
|
|
99
|
+
"source": {
|
|
100
|
+
"field": "userDetails.delegateEmails"
|
|
101
|
+
},
|
|
102
|
+
"show_when": [
|
|
103
|
+
{
|
|
104
|
+
"field": "areYouACivilServant",
|
|
105
|
+
"op": "eq",
|
|
106
|
+
"value": "yes"
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"field": "staffGradeId",
|
|
110
|
+
"op": "in",
|
|
111
|
+
"values": [
|
|
112
|
+
"373979c1-2360-46be-b712-0409ac068059",
|
|
113
|
+
"36c80dfe-0aae-455b-9445-2e1c09dcafdc",
|
|
114
|
+
"1b041cda-b151-4769-b76a-d42d67b0b960",
|
|
115
|
+
"172de41d-f7b0-4be9-b7e8-0cf4f1a1342f",
|
|
116
|
+
"39e18b45-0358-4a45-83ec-5a70b74641e8"
|
|
117
|
+
]
|
|
118
|
+
}
|
|
119
|
+
]
|
|
120
|
+
}
|
|
121
|
+
],
|
|
122
|
+
"pages": [
|
|
123
|
+
{
|
|
124
|
+
"id": "names",
|
|
125
|
+
"name": "names",
|
|
126
|
+
"components": [
|
|
127
|
+
{ "use": "firstName" },
|
|
128
|
+
{ "use": "surname" }
|
|
129
|
+
]
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
"id": "civil-servant-status",
|
|
133
|
+
"name": "civil-servant-status",
|
|
134
|
+
"title": "Are you a civil servant?",
|
|
135
|
+
"components": [
|
|
136
|
+
{
|
|
137
|
+
"use": "areYouACivilServant",
|
|
138
|
+
"label": ""
|
|
139
|
+
}
|
|
140
|
+
],
|
|
141
|
+
"actions": ["submit"],
|
|
142
|
+
"cya_link": {
|
|
143
|
+
"page": "civil-servant-status",
|
|
144
|
+
"aria_suffix": "civil servant status"
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
"id": "grade",
|
|
149
|
+
"name": "grade",
|
|
150
|
+
"title": "What's your grade?",
|
|
151
|
+
"components": [
|
|
152
|
+
{
|
|
153
|
+
"use": "staffGradeId",
|
|
154
|
+
"label": ""
|
|
155
|
+
}
|
|
156
|
+
],
|
|
157
|
+
"actions": ["submit"],
|
|
158
|
+
"cya_link": {
|
|
159
|
+
"page": "grade",
|
|
160
|
+
"aria_suffix": "grade"
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
"id": "team-name",
|
|
165
|
+
"name": "team-name",
|
|
166
|
+
"title": "What's your team name?",
|
|
167
|
+
"components": [
|
|
168
|
+
{
|
|
169
|
+
"use": "team",
|
|
170
|
+
"label": ""
|
|
171
|
+
}
|
|
172
|
+
],
|
|
173
|
+
"actions": ["submit"],
|
|
174
|
+
"cya_link": {
|
|
175
|
+
"page": "team-name",
|
|
176
|
+
"aria_suffix": "teams"
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
"id": "add-or-change-line-manager",
|
|
181
|
+
"name": "add-or-change-line-manager",
|
|
182
|
+
"title": "Add or change a line manager",
|
|
183
|
+
"components": [
|
|
184
|
+
"Your line manager will need to review some of your forms. It’s important to keep their details up-to-date.",
|
|
185
|
+
"An email will be sent to your line manager to ask if they want to approve your request to add them.",
|
|
186
|
+
{
|
|
187
|
+
"type": "inset-text",
|
|
188
|
+
"content": "The changes will show in your profile when they approve your request."
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
"type": "heading",
|
|
192
|
+
"size": "m",
|
|
193
|
+
"content": "Mandatory declarations"
|
|
194
|
+
},
|
|
195
|
+
"Mandatory declarations will not go to your line manager until they have approved your request."
|
|
196
|
+
],
|
|
197
|
+
"actions": [
|
|
198
|
+
{
|
|
199
|
+
"type": "navigate",
|
|
200
|
+
"page": "line-manager-email"
|
|
201
|
+
}
|
|
202
|
+
],
|
|
203
|
+
"show_on_cya": false
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
"id": "line-manager-email",
|
|
207
|
+
"name": "line-manager-email",
|
|
208
|
+
"title": "What’s your line manager’s email address?",
|
|
209
|
+
"components": [
|
|
210
|
+
{
|
|
211
|
+
"use": "linemanagerEmail"
|
|
212
|
+
}
|
|
213
|
+
],
|
|
214
|
+
"actions": ["submit"],
|
|
215
|
+
"cya_link": {
|
|
216
|
+
"page": "add-or-change-line-manager",
|
|
217
|
+
"aria_suffix": "line manager email address"
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
"id": "add-or-change-delegate",
|
|
222
|
+
"name": "add-or-change-delegate",
|
|
223
|
+
"title": "Add or change a delegate",
|
|
224
|
+
"components": [
|
|
225
|
+
"A delegate can review a mandatory declaration on your behalf.",
|
|
226
|
+
"An email will be sent to the delegate to ask if they want to approve your request.",
|
|
227
|
+
{
|
|
228
|
+
"type": "inset-text",
|
|
229
|
+
"content": "The changes will show in your profile when they approve your request."
|
|
230
|
+
}
|
|
231
|
+
],
|
|
232
|
+
"actions": [
|
|
233
|
+
{
|
|
234
|
+
"type": "navigate",
|
|
235
|
+
"page": "delegate-email"
|
|
236
|
+
}
|
|
237
|
+
],
|
|
238
|
+
"show_on_cya": false
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
"id": "delegate-email",
|
|
242
|
+
"name": "delegate-email",
|
|
243
|
+
"title": "What’s your delegate's email address?",
|
|
244
|
+
"components": [
|
|
245
|
+
{
|
|
246
|
+
"use": "delegateEmails",
|
|
247
|
+
"label": "Delegate email address"
|
|
248
|
+
}
|
|
249
|
+
],
|
|
250
|
+
"actions": ["submit"],
|
|
251
|
+
"cya_link": {
|
|
252
|
+
"page": "add-or-change-delegate"
|
|
253
|
+
},
|
|
254
|
+
"show_when": [
|
|
255
|
+
{
|
|
256
|
+
"field": "areYouACivilServant",
|
|
257
|
+
"op": "eq",
|
|
258
|
+
"value": "yes"
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
"field": "staffGradeId",
|
|
262
|
+
"op": "in",
|
|
263
|
+
"values": [
|
|
264
|
+
"373979c1-2360-46be-b712-0409ac068059",
|
|
265
|
+
"36c80dfe-0aae-455b-9445-2e1c09dcafdc",
|
|
266
|
+
"1b041cda-b151-4769-b76a-d42d67b0b960",
|
|
267
|
+
"172de41d-f7b0-4be9-b7e8-0cf4f1a1342f",
|
|
268
|
+
"39e18b45-0358-4a45-83ec-5a70b74641e8"
|
|
269
|
+
]
|
|
270
|
+
}
|
|
271
|
+
]
|
|
272
|
+
}
|
|
273
|
+
],
|
|
274
|
+
"hub": { "format": "CYA" },
|
|
275
|
+
"cya": { "hide_page_titles": true, "hide_actions": true }
|
|
276
|
+
}
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var TYPE_AUTOCOMPLETE = 'autocomplete';
|
|
8
|
+
var TYPE_CHECKBOXES = 'checkboxes';
|
|
9
|
+
var TYPE_DATE = 'date';
|
|
8
10
|
var TYPE_EMAIL = 'email';
|
|
9
11
|
var TYPE_HEADING = 'heading';
|
|
10
12
|
var TYPE_HTML = 'html';
|
|
@@ -15,6 +17,8 @@ var TYPE_TEXT = 'text';
|
|
|
15
17
|
var TYPE_TEXT_AREA = 'textarea';
|
|
16
18
|
var ComponentTypes = {
|
|
17
19
|
AUTOCOMPLETE: TYPE_AUTOCOMPLETE,
|
|
20
|
+
CHECKBOXES: TYPE_CHECKBOXES,
|
|
21
|
+
DATE: TYPE_DATE,
|
|
18
22
|
EMAIL: TYPE_EMAIL,
|
|
19
23
|
HEADING: TYPE_HEADING,
|
|
20
24
|
HTML: TYPE_HTML,
|
|
@@ -5,19 +5,40 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
+
var getPageFromCYALink = function getPageFromCYALink(link) {
|
|
9
|
+
if (link.page) {
|
|
10
|
+
return link.page;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
var url = link.href || link.url;
|
|
14
|
+
|
|
15
|
+
if (url) {
|
|
16
|
+
return url.split('/').pop();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return undefined;
|
|
20
|
+
};
|
|
8
21
|
/**
|
|
9
22
|
* Gets an action object, configured appropriately for a Check your answers component.
|
|
10
23
|
*
|
|
11
24
|
* @param {boolean} readonly Whether or not the component is readonly.
|
|
12
|
-
* @param {object}
|
|
25
|
+
* @param {object} page A configuration object for the page to link to.
|
|
13
26
|
* @param {Function} onAction A function to invoke if the link is clicked.
|
|
14
27
|
*
|
|
15
28
|
* @returns An action object for a Check your answers row.
|
|
29
|
+
* @description
|
|
30
|
+
* `cya_link.href` and `cya_link.url` have been deprecated in favour of `cya_link.page` but this
|
|
31
|
+
* method will convert both by taking the final part of the relative path:
|
|
32
|
+
* - `href: '/bravo'` => `page: 'bravo'`
|
|
16
33
|
*/
|
|
17
|
-
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
var getCYAAction = function getCYAAction(readonly, page, onAction) {
|
|
37
|
+
var cya_link = page === null || page === void 0 ? void 0 : page.cya_link;
|
|
38
|
+
|
|
18
39
|
if (readonly !== true && cya_link) {
|
|
19
40
|
return {
|
|
20
|
-
|
|
41
|
+
page: getPageFromCYALink(cya_link) || page.id || '#',
|
|
21
42
|
label: cya_link.label || 'Change',
|
|
22
43
|
aria_suffix: cya_link.aria_suffix,
|
|
23
44
|
onAction: onAction
|
|
@@ -8,33 +8,80 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
8
8
|
describe('utils', function () {
|
|
9
9
|
describe('CheckYourAnswers', function () {
|
|
10
10
|
describe('getCYAAction', function () {
|
|
11
|
+
var getPage = function getPage(cya_link, id) {
|
|
12
|
+
return {
|
|
13
|
+
cya_link: cya_link,
|
|
14
|
+
id: id
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
11
18
|
it('should return null if readonly', function () {
|
|
12
19
|
expect((0, _getCYAAction.default)(true, {}, function () {})).toBeNull();
|
|
13
20
|
});
|
|
14
21
|
it('should return null if there is no cya_link', function () {
|
|
15
22
|
expect((0, _getCYAAction.default)(false, null, function () {})).toBeNull();
|
|
16
23
|
});
|
|
17
|
-
it('should return a default action if the cya_link is empty', function () {
|
|
24
|
+
it('should return a default action if the cya_link is empty and the page has no id', function () {
|
|
25
|
+
var CYA_LINK = {};
|
|
26
|
+
|
|
27
|
+
var ON_ACTION = function ON_ACTION() {};
|
|
28
|
+
|
|
29
|
+
expect((0, _getCYAAction.default)(false, getPage(CYA_LINK), ON_ACTION)).toEqual({
|
|
30
|
+
page: '#',
|
|
31
|
+
label: 'Change',
|
|
32
|
+
onAction: ON_ACTION
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
it('should return a default action if the cya_link is empty but the page has an id', function () {
|
|
36
|
+
var PAGE_ID = 'page-id';
|
|
18
37
|
var CYA_LINK = {};
|
|
19
38
|
|
|
20
39
|
var ON_ACTION = function ON_ACTION() {};
|
|
21
40
|
|
|
22
|
-
expect((0, _getCYAAction.default)(false, CYA_LINK, ON_ACTION)).toEqual({
|
|
23
|
-
|
|
41
|
+
expect((0, _getCYAAction.default)(false, getPage(CYA_LINK, PAGE_ID), ON_ACTION)).toEqual({
|
|
42
|
+
page: PAGE_ID,
|
|
43
|
+
label: 'Change',
|
|
44
|
+
onAction: ON_ACTION
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
it('should use page specified in cya_link', function () {
|
|
48
|
+
var PAGE = 'alpha';
|
|
49
|
+
var CYA_LINK = {
|
|
50
|
+
page: PAGE
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
var ON_ACTION = function ON_ACTION() {};
|
|
54
|
+
|
|
55
|
+
expect((0, _getCYAAction.default)(false, getPage(CYA_LINK), ON_ACTION)).toEqual({
|
|
56
|
+
page: PAGE,
|
|
57
|
+
label: 'Change',
|
|
58
|
+
onAction: ON_ACTION
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
it('should convert an href specified in cya_link', function () {
|
|
62
|
+
var HREF = '/alpha/bravo';
|
|
63
|
+
var CYA_LINK = {
|
|
64
|
+
href: HREF
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
var ON_ACTION = function ON_ACTION() {};
|
|
68
|
+
|
|
69
|
+
expect((0, _getCYAAction.default)(false, getPage(CYA_LINK), ON_ACTION)).toEqual({
|
|
70
|
+
page: 'bravo',
|
|
24
71
|
label: 'Change',
|
|
25
72
|
onAction: ON_ACTION
|
|
26
73
|
});
|
|
27
74
|
});
|
|
28
|
-
it('should
|
|
29
|
-
var URL = '
|
|
75
|
+
it('should convert a url specified in cya_link', function () {
|
|
76
|
+
var URL = '/alpha/bravo';
|
|
30
77
|
var CYA_LINK = {
|
|
31
78
|
url: URL
|
|
32
79
|
};
|
|
33
80
|
|
|
34
81
|
var ON_ACTION = function ON_ACTION() {};
|
|
35
82
|
|
|
36
|
-
expect((0, _getCYAAction.default)(false, CYA_LINK, ON_ACTION)).toEqual({
|
|
37
|
-
|
|
83
|
+
expect((0, _getCYAAction.default)(false, getPage(CYA_LINK), ON_ACTION)).toEqual({
|
|
84
|
+
page: 'bravo',
|
|
38
85
|
label: 'Change',
|
|
39
86
|
onAction: ON_ACTION
|
|
40
87
|
});
|
|
@@ -47,8 +94,8 @@ describe('utils', function () {
|
|
|
47
94
|
|
|
48
95
|
var ON_ACTION = function ON_ACTION() {};
|
|
49
96
|
|
|
50
|
-
expect((0, _getCYAAction.default)(false, CYA_LINK, ON_ACTION)).toEqual({
|
|
51
|
-
|
|
97
|
+
expect((0, _getCYAAction.default)(false, getPage(CYA_LINK), ON_ACTION)).toEqual({
|
|
98
|
+
page: '#',
|
|
52
99
|
label: LABEL,
|
|
53
100
|
onAction: ON_ACTION
|
|
54
101
|
});
|
|
@@ -61,27 +108,27 @@ describe('utils', function () {
|
|
|
61
108
|
|
|
62
109
|
var ON_ACTION = function ON_ACTION() {};
|
|
63
110
|
|
|
64
|
-
expect((0, _getCYAAction.default)(false, CYA_LINK, ON_ACTION)).toEqual({
|
|
65
|
-
|
|
111
|
+
expect((0, _getCYAAction.default)(false, getPage(CYA_LINK), ON_ACTION)).toEqual({
|
|
112
|
+
page: '#',
|
|
66
113
|
label: 'Change',
|
|
67
114
|
aria_suffix: ARIA_SUFFIX,
|
|
68
115
|
onAction: ON_ACTION
|
|
69
116
|
});
|
|
70
117
|
});
|
|
71
118
|
it('should use all properties specified in cya_link', function () {
|
|
72
|
-
var
|
|
119
|
+
var PAGE = 'alpha';
|
|
73
120
|
var LABEL = 'Alpha Bravo Charlie';
|
|
74
121
|
var ARIA_SUFFIX = 'This is hidden text';
|
|
75
122
|
var CYA_LINK = {
|
|
76
123
|
label: LABEL,
|
|
77
|
-
|
|
124
|
+
page: PAGE,
|
|
78
125
|
aria_suffix: ARIA_SUFFIX
|
|
79
126
|
};
|
|
80
127
|
|
|
81
128
|
var ON_ACTION = function ON_ACTION() {};
|
|
82
129
|
|
|
83
|
-
expect((0, _getCYAAction.default)(false, CYA_LINK, ON_ACTION)).toEqual({
|
|
84
|
-
|
|
130
|
+
expect((0, _getCYAAction.default)(false, getPage(CYA_LINK), ON_ACTION)).toEqual({
|
|
131
|
+
page: PAGE,
|
|
85
132
|
label: LABEL,
|
|
86
133
|
aria_suffix: ARIA_SUFFIX,
|
|
87
134
|
onAction: ON_ACTION
|
|
@@ -23,13 +23,19 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
23
23
|
* @returns A configuration object for a Check your answers row.
|
|
24
24
|
*/
|
|
25
25
|
var getCYARow = function getCYARow(page, component, onAction) {
|
|
26
|
+
var value = '';
|
|
27
|
+
|
|
28
|
+
if (page.formData && component.fieldId) {
|
|
29
|
+
value = page.formData[component.fieldId];
|
|
30
|
+
}
|
|
31
|
+
|
|
26
32
|
return {
|
|
27
33
|
pageId: page.id,
|
|
28
34
|
fieldId: component.fieldId,
|
|
29
35
|
key: component.label || component.cya_label,
|
|
30
36
|
component: _Component.default.editable(component) ? component : undefined,
|
|
31
|
-
value:
|
|
32
|
-
action: (0, _getCYAAction.default)(component.readonly, page
|
|
37
|
+
value: value || '',
|
|
38
|
+
action: (0, _getCYAAction.default)(component.readonly, page, onAction)
|
|
33
39
|
};
|
|
34
40
|
};
|
|
35
41
|
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
+
var _FormPage = _interopRequireDefault(require("../FormPage"));
|
|
9
|
+
|
|
8
10
|
var _getCYARow = _interopRequireDefault(require("./getCYARow"));
|
|
9
11
|
|
|
10
12
|
var _showComponentCYA = _interopRequireDefault(require("./showComponentCYA"));
|
|
@@ -22,11 +24,15 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
22
24
|
* @returns An array of configuration objects for Check your answers rows.
|
|
23
25
|
*/
|
|
24
26
|
var getCYARowsForPage = function getCYARowsForPage(page, onAction) {
|
|
25
|
-
|
|
26
|
-
return (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
if (_FormPage.default.show(page, page.formData)) {
|
|
28
|
+
return page.components.filter(function (c) {
|
|
29
|
+
return (0, _showComponentCYA.default)(c, page.formData);
|
|
30
|
+
}).map(function (component) {
|
|
31
|
+
return (0, _getCYARow.default)(page, component, onAction);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return [];
|
|
30
36
|
};
|
|
31
37
|
|
|
32
38
|
var _default = getCYARowsForPage;
|
|
@@ -39,6 +39,24 @@ var getAutocomplete = function getAutocomplete(config) {
|
|
|
39
39
|
}));
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
+
var getCheckboxes = function getCheckboxes(config) {
|
|
43
|
+
var options = [];
|
|
44
|
+
|
|
45
|
+
_Data.default.getOptions(config, function (val) {
|
|
46
|
+
options = val;
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
var attrs = (0, _cleanAttributes.default)(config);
|
|
50
|
+
return /*#__PURE__*/_react.default.createElement(_copReactComponents.Checkboxes, _extends({}, attrs, {
|
|
51
|
+
options: options
|
|
52
|
+
}));
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
var getDate = function getDate(config) {
|
|
56
|
+
var attrs = (0, _cleanAttributes.default)(config);
|
|
57
|
+
return /*#__PURE__*/_react.default.createElement(_copReactComponents.DateInput, attrs);
|
|
58
|
+
};
|
|
59
|
+
|
|
42
60
|
var getHeading = function getHeading(config) {
|
|
43
61
|
var attrs = (0, _cleanAttributes.default)(config);
|
|
44
62
|
return /*#__PURE__*/_react.default.createElement(_copReactComponents.Heading, attrs, config.content);
|
|
@@ -102,15 +120,39 @@ var getComponentByType = function getComponentByType(config) {
|
|
|
102
120
|
case _models.ComponentTypes.RADIOS:
|
|
103
121
|
return getRadios(config);
|
|
104
122
|
|
|
123
|
+
case _models.ComponentTypes.DATE:
|
|
124
|
+
return getDate(config);
|
|
125
|
+
|
|
126
|
+
case _models.ComponentTypes.CHECKBOXES:
|
|
127
|
+
return getCheckboxes(config);
|
|
128
|
+
|
|
105
129
|
default:
|
|
106
130
|
{
|
|
107
131
|
return null;
|
|
108
132
|
}
|
|
109
133
|
}
|
|
110
134
|
};
|
|
135
|
+
/**
|
|
136
|
+
* Get a renderable component, based on a configuration object.
|
|
137
|
+
* @param {object} config The configuration object for the component.
|
|
138
|
+
* @param {boolean} wrap Indicates whether or not the component should be wrapped.
|
|
139
|
+
* @param {Function} fnOverride An optional override function for component rendering.
|
|
140
|
+
* @returns A renderable component.
|
|
141
|
+
*/
|
|
142
|
+
|
|
111
143
|
|
|
112
144
|
var getComponent = function getComponent(config) {
|
|
113
145
|
var wrap = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
146
|
+
var fnOverride = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
|
|
147
|
+
|
|
148
|
+
if (typeof fnOverride === 'function') {
|
|
149
|
+
var overrideComponent = fnOverride(config, wrap);
|
|
150
|
+
|
|
151
|
+
if (overrideComponent) {
|
|
152
|
+
return overrideComponent;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
114
156
|
var component = getComponentByType(config);
|
|
115
157
|
|
|
116
158
|
if (component && wrap && (0, _isEditable.default)(config)) {
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _react = require("@testing-library/react");
|
|
4
|
+
|
|
5
|
+
var _models = require("../../../models");
|
|
6
|
+
|
|
7
|
+
var _getComponent = _interopRequireDefault(require("../getComponent"));
|
|
8
|
+
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
|
|
11
|
+
// Global imports
|
|
12
|
+
// Local imports
|
|
13
|
+
describe('utils.Component.get', function () {
|
|
14
|
+
it('should return an appropriately rendered autocomplete component', function () {
|
|
15
|
+
var ID = 'test-id';
|
|
16
|
+
var FIELD_ID = 'field-id';
|
|
17
|
+
var LABEL = 'label';
|
|
18
|
+
var OPTIONS = [];
|
|
19
|
+
var COMPONENT = {
|
|
20
|
+
type: _models.ComponentTypes.AUTOCOMPLETE,
|
|
21
|
+
id: ID,
|
|
22
|
+
fieldId: FIELD_ID,
|
|
23
|
+
label: LABEL,
|
|
24
|
+
data: {
|
|
25
|
+
options: OPTIONS
|
|
26
|
+
},
|
|
27
|
+
'data-testid': ID
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
var _render = (0, _react.render)((0, _getComponent.default)(COMPONENT)),
|
|
31
|
+
container = _render.container;
|
|
32
|
+
|
|
33
|
+
var formGroup = (0, _react.getByTestId)(container, ID);
|
|
34
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
35
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
36
|
+
var label = undefined;
|
|
37
|
+
var autocompleteWrapper = undefined;
|
|
38
|
+
var autocomplete = undefined;
|
|
39
|
+
var autocompleteInput = undefined;
|
|
40
|
+
formGroup.childNodes.forEach(function (node) {
|
|
41
|
+
// Check if it's an element.
|
|
42
|
+
if (node instanceof Element) {
|
|
43
|
+
if (node.tagName === 'LABEL') {
|
|
44
|
+
label = node;
|
|
45
|
+
} else if (node.classList.contains('hods-autocomplete__outer-wrapper')) {
|
|
46
|
+
autocompleteWrapper = node;
|
|
47
|
+
var autocompleteInner = node.childNodes[0];
|
|
48
|
+
|
|
49
|
+
if (autocompleteInner instanceof Element) {
|
|
50
|
+
autocomplete = autocompleteInner;
|
|
51
|
+
autocomplete.childNodes.forEach(function (grandchild) {
|
|
52
|
+
if (grandchild instanceof Element) {
|
|
53
|
+
if (grandchild.tagName === 'INPUT') {
|
|
54
|
+
autocompleteInput = grandchild;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
expect(label).toBeDefined();
|
|
65
|
+
expect(label.innerHTML).toContain(LABEL);
|
|
66
|
+
expect(label.getAttribute('for')).toEqual(ID);
|
|
67
|
+
expect(autocompleteWrapper).toBeDefined();
|
|
68
|
+
expect(autocompleteWrapper.tagName).toEqual('DIV');
|
|
69
|
+
expect(autocomplete).toBeDefined();
|
|
70
|
+
expect(autocomplete.tagName).toEqual('DIV');
|
|
71
|
+
expect(autocompleteInput).toBeDefined();
|
|
72
|
+
expect(autocompleteInput.id).toEqual(ID); // TODO: Ensure that the onChange handler is fired.
|
|
73
|
+
// Not sure quite what this looks like yet so I'll address it later.
|
|
74
|
+
});
|
|
75
|
+
});
|