@ukhomeoffice/cop-react-form-renderer 6.6.1 → 6.11.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.
- package/dist/components/CheckYourAnswers/Answer.js +11 -5
- package/dist/components/CheckYourAnswers/Answer.test.js +67 -14
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +9 -5
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +156 -64
- package/dist/components/CollectionSummary/CollectionSummary.js +20 -3
- package/dist/components/CollectionSummary/CollectionSummary.test.js +66 -20
- package/dist/components/CollectionSummary/RenderListView.js +2 -2
- package/dist/components/CollectionSummary/SummaryCard.js +17 -6
- package/dist/components/CollectionSummary/SummaryCard.test.js +94 -37
- package/dist/components/CollectionSummary/SummaryCardDetails.js +78 -34
- package/dist/components/CollectionSummary/SummaryCardDetails.scss +9 -0
- package/dist/components/CollectionSummary/SummaryCardDetails.test.js +206 -10
- package/dist/components/FormComponent/Container.js +2 -1
- package/dist/components/FormComponent/Container.test.js +69 -0
- package/dist/components/FormComponent/helpers/getComponentFieldSet.js +1 -1
- package/dist/components/FormRenderer/FormRenderer.js +1 -0
- package/dist/components/SummaryList/SummaryList.js +8 -0
- package/dist/components/SummaryList/SummaryList.scss +15 -0
- package/dist/components/SummaryList/SummaryList.test.js +67 -7
- package/dist/components/SummaryList/SummaryListHeadingRowWithAction.js +53 -0
- package/dist/components/SummaryList/SummaryListHeadingRowWithAction.scss +38 -0
- package/dist/components/TaskList/TaskList.js +22 -5
- package/dist/components/TaskList/TaskList.scss +24 -0
- package/dist/components/TaskList/TaskList.test.js +160 -16
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +27 -12
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +145 -0
- package/dist/utils/CheckYourAnswers/{getComponentRowForCYA.js → getSummaryListRowForDetails.js} +10 -5
- package/dist/utils/CheckYourAnswers/getSummaryListRowForDetails.test.js +56 -0
- package/dist/utils/CollectionPage/getQuickEditPage.js +2 -1
- package/dist/utils/CollectionPage/getQuickEditPage.test.js +8 -0
- package/dist/utils/CollectionPage/mergeCollectionPages.js +10 -1
- package/dist/utils/CollectionPage/mergeCollectionPages.test.js +6 -6
- package/dist/utils/Component/elevateNestedComponents.js +2 -1
- package/dist/utils/Component/elevateNestedComponents.test.js +38 -0
- package/dist/utils/Component/optionIsSelected.js +5 -0
- package/dist/utils/Component/optionIsSelected.test.js +26 -0
- package/dist/utils/Operate/getLength.js +50 -0
- package/dist/utils/Operate/getLength.test.js +89 -0
- package/dist/utils/Operate/runPageOperations.js +2 -0
- package/dist/utils/Validate/validateComponent.js +7 -2
- package/dist/utils/Validate/validateComponent.test.js +31 -0
- package/dist/utils/Validate/validateTime.js +8 -0
- package/dist/utils/Validate/validateTime.test.js +46 -0
- package/package.json +1 -1
- package/dist/utils/CheckYourAnswers/getComponentRowForCYA.test.js +0 -41
|
@@ -12,7 +12,7 @@ var _models = require("../../models");
|
|
|
12
12
|
var _Task = _interopRequireDefault(require("./Task"));
|
|
13
13
|
var _showComponent = _interopRequireDefault(require("../../utils/Component/showComponent"));
|
|
14
14
|
require("./TaskList.scss");
|
|
15
|
-
var _excluded = ["id", "refTitle", "refNumber", "notes", "incompleteTitle", "sections", "fieldId", "onTaskAction", "classBlock", "classModifiers", "className", "formData"];
|
|
15
|
+
var _excluded = ["id", "refTitle", "refNumber", "notes", "incompleteTitle", "showCompletionOverview", "sections", "fieldId", "onTaskAction", "classBlock", "classModifiers", "className", "formData", "annotations"];
|
|
16
16
|
/* eslint-disable import/no-duplicates */
|
|
17
17
|
// Global Imports
|
|
18
18
|
// Local Imports
|
|
@@ -36,6 +36,7 @@ var TaskList = function TaskList(_ref) {
|
|
|
36
36
|
refNumber = _ref.refNumber,
|
|
37
37
|
notes = _ref.notes,
|
|
38
38
|
incompleteTitle = _ref.incompleteTitle,
|
|
39
|
+
showCompletionOverview = _ref.showCompletionOverview,
|
|
39
40
|
sections = _ref.sections,
|
|
40
41
|
fieldId = _ref.fieldId,
|
|
41
42
|
onTaskAction = _ref.onTaskAction,
|
|
@@ -43,6 +44,7 @@ var TaskList = function TaskList(_ref) {
|
|
|
43
44
|
classModifiers = _ref.classModifiers,
|
|
44
45
|
className = _ref.className,
|
|
45
46
|
formData = _ref.formData,
|
|
47
|
+
annotations = _ref.annotations,
|
|
46
48
|
attrs = _objectWithoutProperties(_ref, _excluded);
|
|
47
49
|
var classes = _copReactComponents.Utils.classBuilder(classBlock, classModifiers, className);
|
|
48
50
|
var cleanedHtmlAttrs = _copReactComponents.Utils.cleanHtmlAttributes(attrs);
|
|
@@ -78,11 +80,19 @@ var TaskList = function TaskList(_ref) {
|
|
|
78
80
|
className: "tasklist-summary"
|
|
79
81
|
}, "".concat(refTitle))), /*#__PURE__*/_react.default.createElement("p", {
|
|
80
82
|
className: "govuk-body govuk-!-font-weight-regular"
|
|
81
|
-
}, "".concat(refNumber))),
|
|
83
|
+
}, "".concat(refNumber))), annotations.length > 0 && annotations.map(function (annotation) {
|
|
84
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
85
|
+
className: classes('annotation')
|
|
86
|
+
}, /*#__PURE__*/_react.default.createElement("p", {
|
|
87
|
+
className: "".concat(classes('annotation-key'), " govuk-body")
|
|
88
|
+
}, _copReactComponents.Utils.interpolateString(annotation.key, formData)), /*#__PURE__*/_react.default.createElement("p", {
|
|
89
|
+
className: "".concat(classes('annotation-value'), " govuk-body")
|
|
90
|
+
}, _copReactComponents.Utils.interpolateString(annotation.value, formData)));
|
|
91
|
+
}), showCompletionOverview && totalSections !== completeSections && /*#__PURE__*/_react.default.createElement("p", {
|
|
82
92
|
className: "govuk-body govuk-!-margin-bottom-0"
|
|
83
93
|
}, /*#__PURE__*/_react.default.createElement("strong", {
|
|
84
94
|
className: "tasklist-summary"
|
|
85
|
-
}, incompleteTitle)), /*#__PURE__*/_react.default.createElement("p", {
|
|
95
|
+
}, incompleteTitle)), showCompletionOverview && /*#__PURE__*/_react.default.createElement("p", {
|
|
86
96
|
className: "govuk-body govuk-!-margin-bottom-7"
|
|
87
97
|
}, "You have completed ".concat(completeSections, " of ").concat(totalSections, " sections")), notesTitle && notesText && (0, _showComponent.default)(notes, formData) && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("p", {
|
|
88
98
|
className: "govuk-body govuk-!-margin-bottom-0"
|
|
@@ -121,6 +131,7 @@ TaskList.propTypes = {
|
|
|
121
131
|
formData: _propTypes.default.shape({}),
|
|
122
132
|
id: _propTypes.default.string,
|
|
123
133
|
incompleteTitle: _propTypes.default.string,
|
|
134
|
+
showCompletionOverview: _propTypes.default.bool,
|
|
124
135
|
notes: _propTypes.default.shape({
|
|
125
136
|
title: _propTypes.default.string,
|
|
126
137
|
text: _propTypes.default.string
|
|
@@ -139,7 +150,11 @@ TaskList.propTypes = {
|
|
|
139
150
|
firstPage: _propTypes.default.string,
|
|
140
151
|
alwaysShowFirstPage: _propTypes.default.bool
|
|
141
152
|
})).isRequired
|
|
142
|
-
})).isRequired
|
|
153
|
+
})).isRequired,
|
|
154
|
+
annotations: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
155
|
+
key: _propTypes.default.string,
|
|
156
|
+
value: _propTypes.default.string
|
|
157
|
+
}))
|
|
143
158
|
};
|
|
144
159
|
TaskList.defaultProps = {
|
|
145
160
|
classBlock: DEFAULT_CLASS,
|
|
@@ -149,9 +164,11 @@ TaskList.defaultProps = {
|
|
|
149
164
|
formData: {},
|
|
150
165
|
id: '',
|
|
151
166
|
incompleteTitle: DEFAULT_INCOMPLETE_TITLE,
|
|
167
|
+
showCompletionOverview: true,
|
|
152
168
|
notes: {},
|
|
153
169
|
onTaskAction: undefined,
|
|
154
170
|
refNumber: undefined,
|
|
155
|
-
refTitle: undefined
|
|
171
|
+
refTitle: undefined,
|
|
172
|
+
annotations: []
|
|
156
173
|
};
|
|
157
174
|
var _default = exports.default = TaskList;
|
|
@@ -58,6 +58,30 @@
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
.hods-task-list__annotation {
|
|
62
|
+
display: flex;
|
|
63
|
+
flex-flow: row wrap;
|
|
64
|
+
margin-bottom: govuk-spacing(2);
|
|
65
|
+
|
|
66
|
+
.hods-task-list__annotation-key {
|
|
67
|
+
font-weight: bold;
|
|
68
|
+
margin-top: 0;
|
|
69
|
+
margin-bottom: 0;
|
|
70
|
+
margin-right: govuk-spacing(1)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.hods-task-list__annotation-value {
|
|
74
|
+
font-weight: normal;
|
|
75
|
+
margin-top: 0;
|
|
76
|
+
margin-bottom: 0;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.hods-task-list__annotation:last-of-type {
|
|
82
|
+
margin-bottom: govuk-spacing(7)
|
|
83
|
+
}
|
|
84
|
+
|
|
61
85
|
.hods-task-list__task-name {
|
|
62
86
|
display: block;
|
|
63
87
|
cursor: auto;
|
|
@@ -101,6 +101,150 @@ describe('components', function () {
|
|
|
101
101
|
expect(subSectionTwoLabel.textContent).toEqual('This is the label for your extra tasks');
|
|
102
102
|
expect(subSectionTwoList.childNodes.length).toEqual(3);
|
|
103
103
|
});
|
|
104
|
+
it('should not render the incomplete title and message when showCompletionOverview is false', function () {
|
|
105
|
+
var COP_REF = '123';
|
|
106
|
+
var REF_TITLE = 'COP reference number';
|
|
107
|
+
var sections = [{
|
|
108
|
+
name: 'These are your tasks',
|
|
109
|
+
label: 'This is the label for your first tasks',
|
|
110
|
+
tasks: [{
|
|
111
|
+
name: 'Nice task',
|
|
112
|
+
state: 'complete',
|
|
113
|
+
pages: ['pageOne']
|
|
114
|
+
}, {
|
|
115
|
+
name: 'Ok task',
|
|
116
|
+
state: 'inProgress',
|
|
117
|
+
pages: ['pageTwo']
|
|
118
|
+
}, {
|
|
119
|
+
name: 'Terrible task',
|
|
120
|
+
state: 'notStarted',
|
|
121
|
+
pages: ['pageThree']
|
|
122
|
+
}]
|
|
123
|
+
}, {
|
|
124
|
+
name: 'These are your extra bonus tasks',
|
|
125
|
+
label: 'This is the label for your extra tasks',
|
|
126
|
+
tasks: [{
|
|
127
|
+
name: 'Nice task',
|
|
128
|
+
state: 'complete',
|
|
129
|
+
pages: ['pageFour']
|
|
130
|
+
}, {
|
|
131
|
+
name: 'Ok task',
|
|
132
|
+
state: 'cannotStartYet',
|
|
133
|
+
pages: ['pageFive']
|
|
134
|
+
}, {
|
|
135
|
+
name: 'Terrible task',
|
|
136
|
+
state: 'cannotStartYet',
|
|
137
|
+
pages: ['pageSix']
|
|
138
|
+
}]
|
|
139
|
+
}];
|
|
140
|
+
var _render2 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_TaskList.default, {
|
|
141
|
+
refNumber: COP_REF,
|
|
142
|
+
refTitle: REF_TITLE,
|
|
143
|
+
sections: sections,
|
|
144
|
+
showCompletionOverview: false
|
|
145
|
+
})),
|
|
146
|
+
container = _render2.container;
|
|
147
|
+
var childNodes = container.childNodes;
|
|
148
|
+
expect(childNodes.length).toEqual(1);
|
|
149
|
+
expect(childNodes[0].childNodes.length).toEqual(8); // Without incomplete heading and message.
|
|
150
|
+
|
|
151
|
+
var _childNodes$0$childNo2 = _slicedToArray(childNodes[0].childNodes, 8),
|
|
152
|
+
referenceHeading = _childNodes$0$childNo2[0],
|
|
153
|
+
referenceNumber = _childNodes$0$childNo2[1],
|
|
154
|
+
subSectionOneHeading = _childNodes$0$childNo2[2],
|
|
155
|
+
subSectionOneLabel = _childNodes$0$childNo2[3],
|
|
156
|
+
subSectionOneList = _childNodes$0$childNo2[4],
|
|
157
|
+
subSectionTwoHeading = _childNodes$0$childNo2[5],
|
|
158
|
+
subSectionTwoLabel = _childNodes$0$childNo2[6],
|
|
159
|
+
subSectionTwoList = _childNodes$0$childNo2[7];
|
|
160
|
+
expect(referenceHeading).toMatchObject({
|
|
161
|
+
tagName: 'P',
|
|
162
|
+
textContent: 'COP reference number'
|
|
163
|
+
});
|
|
164
|
+
expect(referenceNumber).toMatchObject({
|
|
165
|
+
tagName: 'P',
|
|
166
|
+
textContent: '123'
|
|
167
|
+
});
|
|
168
|
+
expect(subSectionOneHeading).toMatchObject({
|
|
169
|
+
tagName: 'H2',
|
|
170
|
+
textContent: '1. These are your tasks'
|
|
171
|
+
});
|
|
172
|
+
expect(subSectionOneLabel.textContent).toEqual('This is the label for your first tasks');
|
|
173
|
+
expect(subSectionOneList.childNodes.length).toEqual(3);
|
|
174
|
+
expect(subSectionTwoHeading).toMatchObject({
|
|
175
|
+
tagName: 'H2',
|
|
176
|
+
textContent: '2. These are your extra bonus tasks'
|
|
177
|
+
});
|
|
178
|
+
expect(subSectionTwoLabel.textContent).toEqual('This is the label for your extra tasks');
|
|
179
|
+
expect(subSectionTwoList.childNodes.length).toEqual(3);
|
|
180
|
+
});
|
|
181
|
+
it('should render any provided annotations', function () {
|
|
182
|
+
var COP_REF = '123';
|
|
183
|
+
var REF_TITLE = 'COP reference number';
|
|
184
|
+
var sections = [{
|
|
185
|
+
name: 'These are your tasks',
|
|
186
|
+
label: 'This is the label for your first tasks',
|
|
187
|
+
tasks: [{
|
|
188
|
+
name: 'Nice task',
|
|
189
|
+
state: 'complete',
|
|
190
|
+
pages: ['pageOne']
|
|
191
|
+
}, {
|
|
192
|
+
name: 'Ok task',
|
|
193
|
+
state: 'inProgress',
|
|
194
|
+
pages: ['pageTwo']
|
|
195
|
+
}, {
|
|
196
|
+
name: 'Terrible task',
|
|
197
|
+
state: 'notStarted',
|
|
198
|
+
pages: ['pageThree']
|
|
199
|
+
}]
|
|
200
|
+
}, {
|
|
201
|
+
name: 'These are your extra bonus tasks',
|
|
202
|
+
label: 'This is the label for your extra tasks',
|
|
203
|
+
tasks: [{
|
|
204
|
+
name: 'Nice task',
|
|
205
|
+
state: 'complete',
|
|
206
|
+
pages: ['pageFour']
|
|
207
|
+
}, {
|
|
208
|
+
name: 'Ok task',
|
|
209
|
+
state: 'cannotStartYet',
|
|
210
|
+
pages: ['pageFive']
|
|
211
|
+
}, {
|
|
212
|
+
name: 'Terrible task',
|
|
213
|
+
state: 'cannotStartYet',
|
|
214
|
+
pages: ['pageSix']
|
|
215
|
+
}]
|
|
216
|
+
}];
|
|
217
|
+
var FORM_DATA = {
|
|
218
|
+
port: {
|
|
219
|
+
name: 'Heathrow Airport'
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
var ANNOTATIONS = [{
|
|
223
|
+
key: 'Port',
|
|
224
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
225
|
+
value: '${port.name}'
|
|
226
|
+
}];
|
|
227
|
+
var _render3 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_TaskList.default, {
|
|
228
|
+
refNumber: COP_REF,
|
|
229
|
+
refTitle: REF_TITLE,
|
|
230
|
+
sections: sections,
|
|
231
|
+
annotations: ANNOTATIONS,
|
|
232
|
+
formData: FORM_DATA
|
|
233
|
+
})),
|
|
234
|
+
container = _render3.container;
|
|
235
|
+
var childNodes = container.childNodes;
|
|
236
|
+
expect(childNodes.length).toEqual(1);
|
|
237
|
+
expect(childNodes[0].childNodes.length).toEqual(11);
|
|
238
|
+
var annotation = childNodes[0].childNodes[2];
|
|
239
|
+
expect(annotation.children[0]).toMatchObject({
|
|
240
|
+
tagName: 'P',
|
|
241
|
+
textContent: 'Port'
|
|
242
|
+
});
|
|
243
|
+
expect(annotation.childNodes[1]).toMatchObject({
|
|
244
|
+
tagName: 'P',
|
|
245
|
+
textContent: 'Heathrow Airport'
|
|
246
|
+
});
|
|
247
|
+
});
|
|
104
248
|
it('should not show incomplete title if form is complete', function () {
|
|
105
249
|
var COP_REF = '123';
|
|
106
250
|
var REF_TITLE = 'COP reference number';
|
|
@@ -135,18 +279,18 @@ describe('components', function () {
|
|
|
135
279
|
pages: ['pageSix']
|
|
136
280
|
}]
|
|
137
281
|
}];
|
|
138
|
-
var
|
|
282
|
+
var _render4 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_TaskList.default, {
|
|
139
283
|
refNumber: COP_REF,
|
|
140
284
|
refTitle: REF_TITLE,
|
|
141
285
|
sections: sections
|
|
142
286
|
})),
|
|
143
|
-
container =
|
|
287
|
+
container = _render4.container;
|
|
144
288
|
var childNodes = container.childNodes;
|
|
145
289
|
expect(childNodes[0].childNodes.length).toEqual(7);
|
|
146
|
-
var _childNodes$0$
|
|
147
|
-
referenceHeading = _childNodes$0$
|
|
148
|
-
referenceNumber = _childNodes$0$
|
|
149
|
-
numComplete = _childNodes$0$
|
|
290
|
+
var _childNodes$0$childNo3 = _slicedToArray(childNodes[0].childNodes, 3),
|
|
291
|
+
referenceHeading = _childNodes$0$childNo3[0],
|
|
292
|
+
referenceNumber = _childNodes$0$childNo3[1],
|
|
293
|
+
numComplete = _childNodes$0$childNo3[2];
|
|
150
294
|
expect(referenceHeading).toMatchObject({
|
|
151
295
|
tagName: 'P',
|
|
152
296
|
textContent: 'COP reference number'
|
|
@@ -179,12 +323,12 @@ describe('components', function () {
|
|
|
179
323
|
pages: ['pageThree']
|
|
180
324
|
}]
|
|
181
325
|
}];
|
|
182
|
-
var
|
|
326
|
+
var _render5 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_TaskList.default, {
|
|
183
327
|
refNumber: COP_REF,
|
|
184
328
|
refTitle: REF_TITLE,
|
|
185
329
|
sections: sections
|
|
186
330
|
})),
|
|
187
|
-
container =
|
|
331
|
+
container = _render5.container;
|
|
188
332
|
var childNodes = container.childNodes;
|
|
189
333
|
var subSectionOne = childNodes[0].childNodes[4];
|
|
190
334
|
expect(subSectionOne.childNodes[0].textContent).toEqual('');
|
|
@@ -223,11 +367,11 @@ describe('components', function () {
|
|
|
223
367
|
pages: ['pageSix']
|
|
224
368
|
}]
|
|
225
369
|
}];
|
|
226
|
-
var
|
|
370
|
+
var _render6 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_TaskList.default, {
|
|
227
371
|
refNumber: COP_REF,
|
|
228
372
|
sections: sections
|
|
229
373
|
})),
|
|
230
|
-
container =
|
|
374
|
+
container = _render6.container;
|
|
231
375
|
var childNodes = container.childNodes;
|
|
232
376
|
expect(childNodes.length).toEqual(1);
|
|
233
377
|
expect(childNodes[0].childNodes.length).toEqual(6);
|
|
@@ -273,12 +417,12 @@ describe('components', function () {
|
|
|
273
417
|
pages: ['pageSix']
|
|
274
418
|
}]
|
|
275
419
|
}];
|
|
276
|
-
var
|
|
420
|
+
var _render7 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_TaskList.default, {
|
|
277
421
|
refNumber: COP_REF,
|
|
278
422
|
sections: sections,
|
|
279
423
|
incompleteTitle: INCOMPLETE_TITLE
|
|
280
424
|
})),
|
|
281
|
-
container =
|
|
425
|
+
container = _render7.container;
|
|
282
426
|
var childNodes = container.childNodes;
|
|
283
427
|
// The first child is now the incomplete text.
|
|
284
428
|
var incompleteForm = childNodes[0].childNodes[0];
|
|
@@ -319,12 +463,12 @@ describe('components', function () {
|
|
|
319
463
|
pages: ['pageSix']
|
|
320
464
|
}]
|
|
321
465
|
}];
|
|
322
|
-
var
|
|
466
|
+
var _render8 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_TaskList.default, {
|
|
323
467
|
refNumber: COP_REF,
|
|
324
468
|
sections: sections,
|
|
325
469
|
incompleteTitle: INCOMPLETE_TITLE
|
|
326
470
|
})),
|
|
327
|
-
container =
|
|
471
|
+
container = _render8.container;
|
|
328
472
|
var childNodes = container.childNodes;
|
|
329
473
|
expect(childNodes.length).toEqual(1);
|
|
330
474
|
var children = childNodes[0].childNodes;
|
|
@@ -357,13 +501,13 @@ describe('components', function () {
|
|
|
357
501
|
pages: ['pageThree']
|
|
358
502
|
}]
|
|
359
503
|
}];
|
|
360
|
-
var
|
|
504
|
+
var _render9 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_TaskList.default, {
|
|
361
505
|
refNumber: COP_REF,
|
|
362
506
|
refTitle: REF_TITLE,
|
|
363
507
|
sections: sections,
|
|
364
508
|
onTaskAction: ON_CLICK
|
|
365
509
|
})),
|
|
366
|
-
container =
|
|
510
|
+
container = _render9.container;
|
|
367
511
|
var taskList = container.childNodes[0].childNodes[5].childNodes;
|
|
368
512
|
var firstTask = taskList[0].childNodes[0].childNodes[0];
|
|
369
513
|
var secondTask = taskList[1].childNodes[0].childNodes[0];
|
|
@@ -56,7 +56,7 @@ var getTitleRowForItem = function getTitleRowForItem(page, item, pageId, labelCo
|
|
|
56
56
|
size: page.collection.titleSize || 's'
|
|
57
57
|
};
|
|
58
58
|
};
|
|
59
|
-
var getHeadingRow = function getHeadingRow(config, pageId, labelCount) {
|
|
59
|
+
var getHeadingRow = function getHeadingRow(config, pageId, labelCount, changeAction, item) {
|
|
60
60
|
if (config.text === '') {
|
|
61
61
|
return null;
|
|
62
62
|
}
|
|
@@ -64,19 +64,27 @@ var getHeadingRow = function getHeadingRow(config, pageId, labelCount) {
|
|
|
64
64
|
pageId: pageId,
|
|
65
65
|
fieldId: "heading".concat(labelCount),
|
|
66
66
|
full_path: "heading".concat(labelCount),
|
|
67
|
-
key: config.text,
|
|
68
|
-
type: 'heading',
|
|
69
|
-
size: config.size || 's'
|
|
67
|
+
key: _copReactComponents.Utils.interpolateString(config.text, item),
|
|
68
|
+
type: changeAction === null ? 'heading' : 'headingWithAction',
|
|
69
|
+
size: config.size || 's',
|
|
70
|
+
action: changeAction === null ? null : {
|
|
71
|
+
onAction: changeAction,
|
|
72
|
+
label: 'Change'
|
|
73
|
+
}
|
|
70
74
|
};
|
|
71
75
|
};
|
|
72
|
-
var getCollectionNameHeading = function getCollectionNameHeading(page, titleName) {
|
|
76
|
+
var getCollectionNameHeading = function getCollectionNameHeading(page, titleName, config, changeAction) {
|
|
73
77
|
return {
|
|
74
78
|
pageId: page.id,
|
|
75
79
|
fieldId: "".concat(page.collection.name, "Title"),
|
|
76
80
|
full_path: "".concat(page.collection.name, "Title"),
|
|
77
|
-
key: titleName.charAt(0).toUpperCase() + titleName.slice(1),
|
|
78
|
-
type: 'heading',
|
|
79
|
-
size: 'm'
|
|
81
|
+
key: (config === null || config === void 0 ? void 0 : config.text) || titleName.charAt(0).toUpperCase() + titleName.slice(1),
|
|
82
|
+
type: changeAction == null ? 'heading' : 'headingWithAction',
|
|
83
|
+
size: (config === null || config === void 0 ? void 0 : config.size) || 'm',
|
|
84
|
+
action: changeAction === null ? null : {
|
|
85
|
+
onAction: changeAction,
|
|
86
|
+
label: 'Change'
|
|
87
|
+
}
|
|
80
88
|
};
|
|
81
89
|
};
|
|
82
90
|
var getActionRows = function getActionRows(page, item, onAction, labelCount) {
|
|
@@ -152,13 +160,16 @@ var getCYARowsForChildPages = function getCYARowsForChildPages(childPages, item,
|
|
|
152
160
|
// to be done here as the show_when checks could rely upon item-level
|
|
153
161
|
// data.
|
|
154
162
|
if ((0, _showFormPageCYA.default)(childPage, _objectSpread(_objectSpread({}, childPage.formData), item))) {
|
|
163
|
+
var changeAction = getChangeActionForPage(childPage, onAction, activeIds);
|
|
155
164
|
if (childPage.collection.heading) {
|
|
156
|
-
var
|
|
165
|
+
var headingAction = childPage.collection.heading.changeLink ? changeAction : null;
|
|
166
|
+
var headingRow = getHeadingRow(childPage.collection.heading, childPage.id, labelCount, headingAction, item);
|
|
157
167
|
rows = rows.concat(headingRow);
|
|
158
168
|
}
|
|
159
169
|
var container = getContainerForPage(childPage, item, labelCount, fullPath);
|
|
160
|
-
var
|
|
161
|
-
|
|
170
|
+
var containerRows = (0, _getCYARowsForContainer.default)(_objectSpread(_objectSpread({}, childPage), {}, {
|
|
171
|
+
formData: _objectSpread(_objectSpread({}, childPage.formData), item)
|
|
172
|
+
}), container, _objectSpread(_objectSpread({}, childPage.formData), item), changeAction, fnOverride);
|
|
162
173
|
rows = rows.concat(containerRows);
|
|
163
174
|
}
|
|
164
175
|
}
|
|
@@ -186,7 +197,11 @@ var getCYARowsForCollectionPage = function getCYARowsForCollectionPage(page, onA
|
|
|
186
197
|
}
|
|
187
198
|
var rows = [];
|
|
188
199
|
if (!page.collection.hideNameFromCYA) {
|
|
189
|
-
|
|
200
|
+
var _page$collection$coll;
|
|
201
|
+
var headingChangeAction = (_page$collection$coll = page.collection.collectionHeading) !== null && _page$collection$coll !== void 0 && _page$collection$coll.changeLinkPage ? getChangeActionForPage({
|
|
202
|
+
id: page.collection.collectionHeading.changeLinkPage
|
|
203
|
+
}, onAction, activeIds) : null;
|
|
204
|
+
rows.push(getCollectionNameHeading(page, collectionName, page.collection.collectionHeading, headingChangeAction));
|
|
190
205
|
}
|
|
191
206
|
var itemIndex = 0;
|
|
192
207
|
var result = Array.isArray(page.collection.onlyShowActiveEntryOnCYA) ? (0, _meetsAllConditions.default)(page.collection.onlyShowActiveEntryOnCYA, data) : page.collection.onlyShowActiveEntryOnCYA;
|
|
@@ -415,6 +415,75 @@ describe('utils.CheckYourAnswers.getCYARowsForCollectionPage', function () {
|
|
|
415
415
|
key: 'Test text'
|
|
416
416
|
});
|
|
417
417
|
});
|
|
418
|
+
it('should allow interpolation of custom headings', function () {
|
|
419
|
+
var FORM_DATA = {
|
|
420
|
+
collection: [{
|
|
421
|
+
id: '01',
|
|
422
|
+
testText: 'value'
|
|
423
|
+
}]
|
|
424
|
+
};
|
|
425
|
+
var PAGE = _objectSpread(_objectSpread({}, MASTER_PAGE), {}, {
|
|
426
|
+
formData: FORM_DATA,
|
|
427
|
+
childPages: [_objectSpread(_objectSpread({}, PAGES[0]), {}, {
|
|
428
|
+
collection: _objectSpread(_objectSpread({}, PAGES[0].collection), {}, {
|
|
429
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
430
|
+
heading: {
|
|
431
|
+
size: 'm',
|
|
432
|
+
text: 'interpolated text: ${testText}'
|
|
433
|
+
}
|
|
434
|
+
})
|
|
435
|
+
})]
|
|
436
|
+
});
|
|
437
|
+
var ROWS = (0, _getCYARowsForCollectionPage.default)(PAGE, null, null, FORM_DATA);
|
|
438
|
+
expect(ROWS.length).toEqual(7);
|
|
439
|
+
expect(ROWS[0]).toMatchObject({
|
|
440
|
+
type: 'heading',
|
|
441
|
+
key: 'Collection'
|
|
442
|
+
});
|
|
443
|
+
expect(ROWS[1]).toMatchObject({
|
|
444
|
+
type: 'heading',
|
|
445
|
+
key: 'Collection entry 1'
|
|
446
|
+
});
|
|
447
|
+
expect(ROWS[2].action.label).toEqual('Change');
|
|
448
|
+
expect(ROWS[3].action.label).toEqual('custom remove label');
|
|
449
|
+
expect(ROWS[4].action.label).toEqual('custom change label');
|
|
450
|
+
expect(ROWS[5]).toMatchObject({
|
|
451
|
+
type: 'heading',
|
|
452
|
+
key: 'interpolated text: value',
|
|
453
|
+
size: 'm'
|
|
454
|
+
});
|
|
455
|
+
expect(ROWS[6]).toMatchObject({
|
|
456
|
+
value: 'value',
|
|
457
|
+
key: 'Test text'
|
|
458
|
+
});
|
|
459
|
+
});
|
|
460
|
+
it('should alow configuration of collection name headings', function () {
|
|
461
|
+
var FORM_DATA = {
|
|
462
|
+
collection: [{
|
|
463
|
+
id: '01',
|
|
464
|
+
testText: 'value'
|
|
465
|
+
}]
|
|
466
|
+
};
|
|
467
|
+
var PAGE = _objectSpread(_objectSpread({}, MASTER_PAGE), {}, {
|
|
468
|
+
formData: FORM_DATA,
|
|
469
|
+
collection: _objectSpread(_objectSpread({}, MASTER_PAGE.collection), {}, {
|
|
470
|
+
collectionHeading: {
|
|
471
|
+
text: 'Custom collection heading',
|
|
472
|
+
size: 'm',
|
|
473
|
+
changeLinkPage: PAGES[0].id
|
|
474
|
+
}
|
|
475
|
+
}),
|
|
476
|
+
childPages: [_objectSpread(_objectSpread({}, PAGES[0]), {}, {
|
|
477
|
+
collection: _objectSpread({}, PAGES[0].collection)
|
|
478
|
+
})]
|
|
479
|
+
});
|
|
480
|
+
var ROWS = (0, _getCYARowsForCollectionPage.default)(PAGE, null, null, FORM_DATA);
|
|
481
|
+
expect(ROWS.length).toEqual(6);
|
|
482
|
+
expect(ROWS[0]).toMatchObject({
|
|
483
|
+
type: 'headingWithAction',
|
|
484
|
+
key: 'Custom collection heading'
|
|
485
|
+
});
|
|
486
|
+
});
|
|
418
487
|
it('should default to a title size of small if one is not specified', function () {
|
|
419
488
|
var FORM_DATA = {
|
|
420
489
|
collection: [{
|
|
@@ -612,4 +681,80 @@ describe('utils.CheckYourAnswers.getCYARowsForCollectionPage', function () {
|
|
|
612
681
|
key: 'Test text'
|
|
613
682
|
});
|
|
614
683
|
});
|
|
684
|
+
it('should create rows for the Collection component correctly', function () {
|
|
685
|
+
var FORM_DATA = {
|
|
686
|
+
collection: [{
|
|
687
|
+
id: '01',
|
|
688
|
+
testCollection: [{
|
|
689
|
+
testText: 'collection value'
|
|
690
|
+
}],
|
|
691
|
+
otherComp: 'one'
|
|
692
|
+
}]
|
|
693
|
+
};
|
|
694
|
+
var COLLECTION_COMP = {
|
|
695
|
+
id: 'testCollection',
|
|
696
|
+
fieldId: 'testCollection',
|
|
697
|
+
label: 'Test collection',
|
|
698
|
+
type: 'collection',
|
|
699
|
+
item: [{
|
|
700
|
+
id: 'testText',
|
|
701
|
+
fieldId: 'testText',
|
|
702
|
+
type: 'text',
|
|
703
|
+
label: 'Some nice text'
|
|
704
|
+
}],
|
|
705
|
+
show_when: [{
|
|
706
|
+
field: 'otherComp',
|
|
707
|
+
op: 'eq',
|
|
708
|
+
value: 'one'
|
|
709
|
+
}]
|
|
710
|
+
};
|
|
711
|
+
var MASTER_PAGE_WITH_COLLECTION = {
|
|
712
|
+
id: 'page1',
|
|
713
|
+
collection: {
|
|
714
|
+
name: 'collection',
|
|
715
|
+
labels: {
|
|
716
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
717
|
+
item: 'Collection entry ${index}'
|
|
718
|
+
},
|
|
719
|
+
actions: [{
|
|
720
|
+
type: 'change'
|
|
721
|
+
}, {
|
|
722
|
+
type: 'remove',
|
|
723
|
+
label: 'custom remove label'
|
|
724
|
+
}, {
|
|
725
|
+
type: 'change',
|
|
726
|
+
label: 'custom change label',
|
|
727
|
+
page: 'confirmDelete'
|
|
728
|
+
}]
|
|
729
|
+
},
|
|
730
|
+
childPages: [{
|
|
731
|
+
id: 'page1',
|
|
732
|
+
collection: {
|
|
733
|
+
name: 'collection'
|
|
734
|
+
},
|
|
735
|
+
components: [COLLECTION_COMP]
|
|
736
|
+
}],
|
|
737
|
+
formData: FORM_DATA
|
|
738
|
+
};
|
|
739
|
+
var ROWS = (0, _getCYARowsForCollectionPage.default)(MASTER_PAGE_WITH_COLLECTION, null, null, FORM_DATA);
|
|
740
|
+
expect(ROWS.length).toEqual(7); // Title row + component row for each item
|
|
741
|
+
expect(ROWS[0]).toMatchObject({
|
|
742
|
+
type: 'heading',
|
|
743
|
+
key: 'Collection'
|
|
744
|
+
});
|
|
745
|
+
expect(ROWS[1]).toMatchObject({
|
|
746
|
+
type: 'heading',
|
|
747
|
+
key: 'Collection entry 1'
|
|
748
|
+
});
|
|
749
|
+
expect(ROWS[2].action.label).toEqual('Change');
|
|
750
|
+
expect(ROWS[3].action.label).toEqual('custom remove label');
|
|
751
|
+
expect(ROWS[4].action.label).toEqual('custom change label');
|
|
752
|
+
expect(ROWS[5]).toMatchObject({
|
|
753
|
+
key: 'Item 1'
|
|
754
|
+
});
|
|
755
|
+
expect(ROWS[6]).toMatchObject({
|
|
756
|
+
value: 'collection value',
|
|
757
|
+
key: 'Some nice text'
|
|
758
|
+
});
|
|
759
|
+
});
|
|
615
760
|
});
|
package/dist/utils/CheckYourAnswers/{getComponentRowForCYA.js → getSummaryListRowForDetails.js}
RENAMED
|
@@ -7,6 +7,7 @@ exports.default = void 0;
|
|
|
7
7
|
var _react = _interopRequireDefault(require("react"));
|
|
8
8
|
var _Answer = _interopRequireDefault(require("../../components/CheckYourAnswers/Answer"));
|
|
9
9
|
var _SummaryListRow = _interopRequireDefault(require("../../components/SummaryList/SummaryListRow"));
|
|
10
|
+
var _SummaryListTitleRow = _interopRequireDefault(require("../../components/SummaryList/SummaryListTitleRow"));
|
|
10
11
|
var _getCYARow = _interopRequireDefault(require("./getCYARow"));
|
|
11
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
13
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
@@ -15,23 +16,27 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
15
16
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
16
17
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
17
18
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } // Local imports
|
|
18
|
-
var
|
|
19
|
+
var getSummaryListRowForDetails = function getSummaryListRowForDetails(page, component, customClasses, entryData, optionalFieldPlaceholder) {
|
|
19
20
|
var modifiedPage = _objectSpread(_objectSpread({}, page), {}, {
|
|
20
21
|
formData: _objectSpread(_objectSpread({}, page.formData), entryData)
|
|
21
22
|
});
|
|
22
23
|
var row = (0, _getCYARow.default)(modifiedPage, component);
|
|
23
|
-
return /*#__PURE__*/_react.default.createElement(
|
|
24
|
+
return component.type === 'title' ? /*#__PURE__*/_react.default.createElement(_SummaryListTitleRow.default, {
|
|
25
|
+
title: component.key,
|
|
26
|
+
classes: customClasses
|
|
27
|
+
}) : /*#__PURE__*/_react.default.createElement(_SummaryListRow.default, {
|
|
24
28
|
key: "".concat(row.fieldId),
|
|
25
29
|
row: {
|
|
26
30
|
key: row.key,
|
|
27
31
|
value: /*#__PURE__*/_react.default.createElement(_Answer.default, {
|
|
28
|
-
value: row.value,
|
|
32
|
+
value: row.value || component.value,
|
|
29
33
|
component: row.component,
|
|
30
|
-
formData: modifiedPage.formData
|
|
34
|
+
formData: modifiedPage.formData,
|
|
35
|
+
placeholder: optionalFieldPlaceholder
|
|
31
36
|
}),
|
|
32
37
|
required: row.required
|
|
33
38
|
},
|
|
34
39
|
classes: customClasses
|
|
35
40
|
});
|
|
36
41
|
};
|
|
37
|
-
var _default = exports.default =
|
|
42
|
+
var _default = exports.default = getSummaryListRowForDetails;
|