@ukhomeoffice/cop-react-form-renderer 5.56.3 → 5.58.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/CollectionSummary/CollectionSummary.js +21 -6
- package/dist/components/CollectionSummary/SummaryCard.js +10 -39
- package/dist/components/CollectionSummary/SummaryCard.scss +0 -145
- package/dist/components/CollectionSummary/SummaryCard.test.js +0 -243
- package/dist/components/CollectionSummary/SummaryCardDetails.js +117 -0
- package/dist/components/CollectionSummary/SummaryCardDetails.scss +158 -0
- package/dist/components/CollectionSummary/SummaryCardDetails.test.js +319 -0
- package/dist/components/FormComponent/FormComponent.js +1 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +1 -1
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +35 -0
- package/dist/utils/CollectionPage/mergeCollectionPages.js +14 -5
- package/dist/utils/CollectionPage/mergeCollectionPages.test.js +48 -1
- package/package.json +1 -1
|
@@ -64,11 +64,24 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
64
64
|
return _utils.default.CollectionPage.getData(config.collectionName, formData) || [];
|
|
65
65
|
}, [formData]);
|
|
66
66
|
var masterPage = (0, _react.useMemo)(function () {
|
|
67
|
-
var
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
var collectionNameParts = config.collectionName.split('.');
|
|
68
|
+
var childPages = _utils.default.CollectionPage.mergePages(pages || []) || [];
|
|
69
|
+
return collectionNameParts.reduce(function (acc, current, index) {
|
|
70
|
+
var _childPages$find;
|
|
71
|
+
var currentPath = index === 0 ? "".concat(acc).concat(current) : "".concat(acc, ".").concat(current);
|
|
72
|
+
if (index === collectionNameParts.length - 1) {
|
|
73
|
+
var _childPages;
|
|
74
|
+
return ((_childPages = childPages) === null || _childPages === void 0 ? void 0 : _childPages.find(function (p) {
|
|
75
|
+
var _p$collection;
|
|
76
|
+
return ((_p$collection = p.collection) === null || _p$collection === void 0 ? void 0 : _p$collection.name) === currentPath;
|
|
77
|
+
})) || null;
|
|
78
|
+
}
|
|
79
|
+
childPages = ((_childPages$find = childPages.find(function (p) {
|
|
80
|
+
var _p$collection2;
|
|
81
|
+
return ((_p$collection2 = p.collection) === null || _p$collection2 === void 0 ? void 0 : _p$collection2.name) === currentPath;
|
|
82
|
+
})) === null || _childPages$find === void 0 ? void 0 : _childPages$find.childPages) || null;
|
|
83
|
+
return currentPath;
|
|
84
|
+
}, "");
|
|
72
85
|
}, [pages]);
|
|
73
86
|
var validateEntries = function validateEntries() {
|
|
74
87
|
var stored = [];
|
|
@@ -224,6 +237,7 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
224
237
|
return onChange(target);
|
|
225
238
|
},
|
|
226
239
|
parentCollectionName: config.collectionName.split('.').shift(),
|
|
240
|
+
childCollections: config.childCollections || [],
|
|
227
241
|
formData: formData,
|
|
228
242
|
classModifiers: entry === entryToDelete ? ['deleting-summary-card'] : [''],
|
|
229
243
|
inError: errors.filter(function (e) {
|
|
@@ -260,7 +274,8 @@ CollectionSummary.propTypes = {
|
|
|
260
274
|
confirmation: _propTypes.default.shape({
|
|
261
275
|
message: _propTypes.default.string,
|
|
262
276
|
label: _propTypes.default.string
|
|
263
|
-
})
|
|
277
|
+
}),
|
|
278
|
+
childCollections: _propTypes.default.arrayOf(_propTypes.default.string)
|
|
264
279
|
}).isRequired,
|
|
265
280
|
onAction: _propTypes.default.func,
|
|
266
281
|
onChange: _propTypes.default.func,
|
|
@@ -11,10 +11,10 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
11
11
|
var _utils = _interopRequireDefault(require("../../utils"));
|
|
12
12
|
var _getQuickEditPage = _interopRequireDefault(require("../../utils/CollectionPage/getQuickEditPage"));
|
|
13
13
|
var _hooks = require("../../hooks");
|
|
14
|
-
var _FormComponent = _interopRequireDefault(require("../FormComponent"));
|
|
15
14
|
var _FormPage = _interopRequireDefault(require("../FormPage"));
|
|
16
15
|
var _BannerStrip = _interopRequireDefault(require("./BannerStrip"));
|
|
17
16
|
var _RenderListView = _interopRequireDefault(require("./RenderListView"));
|
|
17
|
+
var _SummaryCardDetails = _interopRequireDefault(require("./SummaryCardDetails"));
|
|
18
18
|
require("./SummaryCard.scss");
|
|
19
19
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
20
20
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -44,7 +44,7 @@ var DEFAULT_DUPLICATE_BUTTON_LABEL = exports.DEFAULT_DUPLICATE_BUTTON_LABEL = 'D
|
|
|
44
44
|
var DEFAULT_DETAILS_TITLE = exports.DEFAULT_DETAILS_TITLE = 'Full details';
|
|
45
45
|
var DEFAULT_CHANGE_BUTTON_CLASS = exports.DEFAULT_CHANGE_BUTTON_CLASS = 'secondary';
|
|
46
46
|
var SummaryCard = function SummaryCard(_ref) {
|
|
47
|
-
var _config$changeAction2, _config$changeAction3, _config$deleteAction, _config$duplicateActi
|
|
47
|
+
var _config$changeAction2, _config$changeAction3, _config$deleteAction, _config$duplicateActi;
|
|
48
48
|
var id = _ref.id,
|
|
49
49
|
entryData = _ref.entryData,
|
|
50
50
|
config = _ref.config,
|
|
@@ -54,6 +54,7 @@ var SummaryCard = function SummaryCard(_ref) {
|
|
|
54
54
|
onDuplicate = _ref.onDuplicate,
|
|
55
55
|
onQuickEdit = _ref.onQuickEdit,
|
|
56
56
|
parentCollectionName = _ref.parentCollectionName,
|
|
57
|
+
childCollections = _ref.childCollections,
|
|
57
58
|
formData = _ref.formData,
|
|
58
59
|
masterPage = _ref.masterPage,
|
|
59
60
|
hideDetails = _ref.hideDetails,
|
|
@@ -203,43 +204,11 @@ var SummaryCard = function SummaryCard(_ref) {
|
|
|
203
204
|
}, !hideDetails && /*#__PURE__*/_react.default.createElement(_copReactComponents.Details, {
|
|
204
205
|
summary: config.detailsTitle || DEFAULT_DETAILS_TITLE,
|
|
205
206
|
className: "details"
|
|
206
|
-
},
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
return (_childPage$summaryLay = childPage.summaryLayout) === null || _childPage$summaryLay === void 0 ? void 0 : _childPage$summaryLay.sections.map(function (section) {
|
|
212
|
-
var _section$fields;
|
|
213
|
-
if (section.show_when && !_utils.default.Condition.meetsAll(section.show_when, _objectSpread(_objectSpread({}, formData), entryData))) {
|
|
214
|
-
return null;
|
|
215
|
-
}
|
|
216
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
217
|
-
key: section.title,
|
|
218
|
-
className: classes('section')
|
|
219
|
-
}, /*#__PURE__*/_react.default.createElement("h3", {
|
|
220
|
-
className: classes('section-title')
|
|
221
|
-
}, section.title), /*#__PURE__*/_react.default.createElement("div", {
|
|
222
|
-
className: classes('section-content', "columns-".concat(section.columns))
|
|
223
|
-
}, (_section$fields = section.fields) === null || _section$fields === void 0 ? void 0 : _section$fields.map(function (fieldId) {
|
|
224
|
-
var component = allPageComponents.find(function (comp) {
|
|
225
|
-
return comp.fieldId === fieldId;
|
|
226
|
-
});
|
|
227
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
228
|
-
key: fieldId,
|
|
229
|
-
className: classes('field')
|
|
230
|
-
}, /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
231
|
-
component: _objectSpread(_objectSpread({}, component), {}, {
|
|
232
|
-
hint: ''
|
|
233
|
-
}),
|
|
234
|
-
value: entryData[component === null || component === void 0 ? void 0 : component.fieldId],
|
|
235
|
-
formData: entryData,
|
|
236
|
-
wrap: true,
|
|
237
|
-
readonly: true
|
|
238
|
-
}));
|
|
239
|
-
})));
|
|
240
|
-
});
|
|
241
|
-
}).filter(function (e) {
|
|
242
|
-
return !!e;
|
|
207
|
+
}, /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
|
|
208
|
+
masterPage: masterPage,
|
|
209
|
+
childCollections: childCollections,
|
|
210
|
+
formData: formData,
|
|
211
|
+
entryData: entryData
|
|
243
212
|
}))));
|
|
244
213
|
};
|
|
245
214
|
SummaryCard.propTypes = {
|
|
@@ -282,6 +251,7 @@ SummaryCard.propTypes = {
|
|
|
282
251
|
onDuplicate: _propTypes.default.func,
|
|
283
252
|
onQuickEdit: _propTypes.default.func,
|
|
284
253
|
parentCollectionName: _propTypes.default.string.isRequired,
|
|
254
|
+
childCollections: _propTypes.default.arrayOf(_propTypes.default.string),
|
|
285
255
|
formData: _propTypes.default.shape({}).isRequired,
|
|
286
256
|
hideDetails: _propTypes.default.bool,
|
|
287
257
|
inError: _propTypes.default.bool
|
|
@@ -292,6 +262,7 @@ SummaryCard.defaultProps = {
|
|
|
292
262
|
onDelete: null,
|
|
293
263
|
onDuplicate: null,
|
|
294
264
|
onQuickEdit: null,
|
|
265
|
+
childCollections: [],
|
|
295
266
|
hideDetails: false,
|
|
296
267
|
inError: false
|
|
297
268
|
};
|
|
@@ -89,111 +89,6 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
|
|
|
89
89
|
margin-bottom: 0;
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
-
|
|
93
|
-
&__section {
|
|
94
|
-
border-bottom: 2px solid #E9EBED;
|
|
95
|
-
|
|
96
|
-
&-title {
|
|
97
|
-
font-weight: bold;
|
|
98
|
-
margin: govuk-spacing(2) 0 govuk-spacing(6) 0;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
&-content {
|
|
102
|
-
display: flex;
|
|
103
|
-
flex-wrap: wrap;
|
|
104
|
-
gap: govuk-spacing(2);
|
|
105
|
-
|
|
106
|
-
.hods-form-summary-card__field {
|
|
107
|
-
box-sizing: border-box;
|
|
108
|
-
margin-bottom: govuk-spacing(4);
|
|
109
|
-
|
|
110
|
-
.govuk-label,
|
|
111
|
-
.govuk-fieldset__legend {
|
|
112
|
-
font-weight: bold;
|
|
113
|
-
margin-bottom: govuk-spacing(1) !important;
|
|
114
|
-
|
|
115
|
-
&::after {
|
|
116
|
-
content: " :";
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
div.govuk-form-group div:has(img){
|
|
121
|
-
display: flex;
|
|
122
|
-
flex-wrap: wrap;
|
|
123
|
-
|
|
124
|
-
.hods-readonly.hods-readonly--success {
|
|
125
|
-
font-size: 0;
|
|
126
|
-
line-height: 0;
|
|
127
|
-
|
|
128
|
-
.cop-upload-preview__thumb {
|
|
129
|
-
display: inline-block;
|
|
130
|
-
margin-right: govuk-spacing(1);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
&--columns-1,
|
|
138
|
-
&--columns-2,
|
|
139
|
-
&--columns-3 {
|
|
140
|
-
position: relative;
|
|
141
|
-
margin-bottom: govuk-spacing(1);
|
|
142
|
-
|
|
143
|
-
&::before {
|
|
144
|
-
content: "";
|
|
145
|
-
position: absolute;
|
|
146
|
-
top: 0;
|
|
147
|
-
width: 2px;
|
|
148
|
-
height: 100%;
|
|
149
|
-
background-color: #E9EBED;
|
|
150
|
-
left: 0;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
&--columns-2 {
|
|
155
|
-
&::after {
|
|
156
|
-
content: "";
|
|
157
|
-
position: absolute;
|
|
158
|
-
top: 0;
|
|
159
|
-
width: 2px;
|
|
160
|
-
height: 100%;
|
|
161
|
-
background-color: #E9EBED;
|
|
162
|
-
left: 50%;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
.hods-form-summary-card__field {
|
|
166
|
-
flex: 0 0 calc(50% - 10px);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
&--columns-3 {
|
|
171
|
-
&::after {
|
|
172
|
-
content: "";
|
|
173
|
-
position: absolute;
|
|
174
|
-
top: 0;
|
|
175
|
-
left: 33.333%;
|
|
176
|
-
width: 2px;
|
|
177
|
-
height: 100%;
|
|
178
|
-
background-color: #E9EBED;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
.hods-form-summary-card__field {
|
|
182
|
-
flex: 0 0 calc(33.333% - 10px);
|
|
183
|
-
|
|
184
|
-
&:nth-child(2)::after {
|
|
185
|
-
content: "";
|
|
186
|
-
position: absolute;
|
|
187
|
-
top: 0;
|
|
188
|
-
right: 33.333%;
|
|
189
|
-
width: 2px;
|
|
190
|
-
height: 100%;
|
|
191
|
-
background-color: #E9EBED;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
92
|
}
|
|
198
93
|
|
|
199
94
|
@media (max-width: 640px) {
|
|
@@ -210,45 +105,5 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
|
|
|
210
105
|
margin-top: govuk-spacing(2);
|
|
211
106
|
}
|
|
212
107
|
}
|
|
213
|
-
|
|
214
|
-
&__section {
|
|
215
|
-
&-content {
|
|
216
|
-
display: block;
|
|
217
|
-
|
|
218
|
-
.hods-form-summary-card__field {
|
|
219
|
-
width: 100%;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
.hods-form-summary-card__field:nth-child(2)::after {
|
|
223
|
-
display: none;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
&--columns-2,
|
|
227
|
-
&--columns-3 {
|
|
228
|
-
position: relative;
|
|
229
|
-
margin-bottom: govuk-spacing(1);
|
|
230
|
-
|
|
231
|
-
&::before {
|
|
232
|
-
content: '';
|
|
233
|
-
position: absolute;
|
|
234
|
-
top: 0;
|
|
235
|
-
width: 2px;
|
|
236
|
-
height: 100%;
|
|
237
|
-
background-color: #A9A9A9;
|
|
238
|
-
left: 0;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
&::after {
|
|
242
|
-
display: none;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
&--columns-3 {
|
|
247
|
-
.hods-form-summary-card__field:nth-child(2)::after {
|
|
248
|
-
content: none;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
108
|
}
|
|
254
109
|
}
|
|
@@ -1366,247 +1366,4 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
1366
1366
|
expect(detailsComponent).toBeNull();
|
|
1367
1367
|
});
|
|
1368
1368
|
});
|
|
1369
|
-
describe('SummaryLayout config behavior', function () {
|
|
1370
|
-
it('should render sections and fields based on summaryLayout config', function () {
|
|
1371
|
-
var CHILD_PAGES = [{
|
|
1372
|
-
summaryLayout: {
|
|
1373
|
-
sections: [{
|
|
1374
|
-
title: 'Section 1',
|
|
1375
|
-
columns: 2,
|
|
1376
|
-
fields: ['fieldA', 'fieldB']
|
|
1377
|
-
}, {
|
|
1378
|
-
title: 'Section 2',
|
|
1379
|
-
columns: 1,
|
|
1380
|
-
fields: ['fieldC']
|
|
1381
|
-
}]
|
|
1382
|
-
},
|
|
1383
|
-
components: [{
|
|
1384
|
-
fieldId: 'fieldA'
|
|
1385
|
-
}, {
|
|
1386
|
-
fieldId: 'fieldB'
|
|
1387
|
-
}, {
|
|
1388
|
-
fieldId: 'fieldC'
|
|
1389
|
-
}]
|
|
1390
|
-
}];
|
|
1391
|
-
var CONFIG = {
|
|
1392
|
-
title: 'Title'
|
|
1393
|
-
};
|
|
1394
|
-
var _renderWithValidation36 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
|
|
1395
|
-
id: ID,
|
|
1396
|
-
entryData: ENTRY,
|
|
1397
|
-
config: CONFIG,
|
|
1398
|
-
parentCollectionName: "parent",
|
|
1399
|
-
pages: CHILD_PAGES,
|
|
1400
|
-
formData: {},
|
|
1401
|
-
masterPage: {
|
|
1402
|
-
childPages: CHILD_PAGES
|
|
1403
|
-
}
|
|
1404
|
-
})),
|
|
1405
|
-
container = _renderWithValidation36.container;
|
|
1406
|
-
|
|
1407
|
-
// Function to find an element by its text content
|
|
1408
|
-
function getByTextContent(parent, text) {
|
|
1409
|
-
return Array.from(parent.getElementsByClassName(classes('section-title'))).find(function (el) {
|
|
1410
|
-
return el.textContent === text;
|
|
1411
|
-
});
|
|
1412
|
-
}
|
|
1413
|
-
|
|
1414
|
-
// Check for section titles
|
|
1415
|
-
var section1Title = getByTextContent(container, 'Section 1');
|
|
1416
|
-
var section2Title = getByTextContent(container, 'Section 2');
|
|
1417
|
-
expect(section1Title).not.toBeUndefined();
|
|
1418
|
-
expect(section2Title).not.toBeUndefined();
|
|
1419
|
-
var section1Content = section1Title.parentNode.querySelector(".".concat(classes('section-content')));
|
|
1420
|
-
expect(section1Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(2);
|
|
1421
|
-
var section2Content = section2Title.parentNode.querySelector(".".concat(classes('section-content')));
|
|
1422
|
-
expect(section2Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(1);
|
|
1423
|
-
});
|
|
1424
|
-
it('should render sections if they have show_when checks and pass them', function () {
|
|
1425
|
-
var CHILD_PAGES = [{
|
|
1426
|
-
summaryLayout: {
|
|
1427
|
-
sections: [{
|
|
1428
|
-
title: 'Section 1',
|
|
1429
|
-
columns: 2,
|
|
1430
|
-
fields: ['fieldA', 'fieldB'],
|
|
1431
|
-
show_when: [{
|
|
1432
|
-
field: 'showSection1',
|
|
1433
|
-
op: "=",
|
|
1434
|
-
value: true
|
|
1435
|
-
}]
|
|
1436
|
-
}, {
|
|
1437
|
-
title: 'Section 2',
|
|
1438
|
-
columns: 1,
|
|
1439
|
-
fields: ['fieldC']
|
|
1440
|
-
}]
|
|
1441
|
-
},
|
|
1442
|
-
components: [{
|
|
1443
|
-
fieldId: 'fieldA'
|
|
1444
|
-
}, {
|
|
1445
|
-
fieldId: 'fieldB'
|
|
1446
|
-
}, {
|
|
1447
|
-
fieldId: 'fieldC'
|
|
1448
|
-
}]
|
|
1449
|
-
}];
|
|
1450
|
-
var CONFIG = {
|
|
1451
|
-
title: 'Title'
|
|
1452
|
-
};
|
|
1453
|
-
var CUSTOM_ENTRY = _objectSpread(_objectSpread({}, ENTRY), {}, {
|
|
1454
|
-
showSection1: true
|
|
1455
|
-
});
|
|
1456
|
-
var _renderWithValidation37 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
|
|
1457
|
-
id: ID,
|
|
1458
|
-
entryData: CUSTOM_ENTRY,
|
|
1459
|
-
config: CONFIG,
|
|
1460
|
-
parentCollectionName: "parent",
|
|
1461
|
-
pages: CHILD_PAGES,
|
|
1462
|
-
formData: {},
|
|
1463
|
-
masterPage: {
|
|
1464
|
-
childPages: CHILD_PAGES
|
|
1465
|
-
}
|
|
1466
|
-
})),
|
|
1467
|
-
container = _renderWithValidation37.container;
|
|
1468
|
-
|
|
1469
|
-
// Function to find an element by its text content
|
|
1470
|
-
function getByTextContent(parent, text) {
|
|
1471
|
-
return Array.from(parent.getElementsByClassName(classes('section-title'))).find(function (el) {
|
|
1472
|
-
return el.textContent === text;
|
|
1473
|
-
});
|
|
1474
|
-
}
|
|
1475
|
-
|
|
1476
|
-
// Check for section titles
|
|
1477
|
-
var section1Title = getByTextContent(container, 'Section 1');
|
|
1478
|
-
var section2Title = getByTextContent(container, 'Section 2');
|
|
1479
|
-
expect(section1Title).not.toBeUndefined();
|
|
1480
|
-
expect(section2Title).not.toBeUndefined();
|
|
1481
|
-
var section1Content = section1Title.parentNode.querySelector(".".concat(classes('section-content')));
|
|
1482
|
-
expect(section1Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(2);
|
|
1483
|
-
var section2Content = section2Title.parentNode.querySelector(".".concat(classes('section-content')));
|
|
1484
|
-
expect(section2Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(1);
|
|
1485
|
-
});
|
|
1486
|
-
it('should not render sections if they have show_when checks and fail them', function () {
|
|
1487
|
-
var CHILD_PAGES = [{
|
|
1488
|
-
summaryLayout: {
|
|
1489
|
-
sections: [{
|
|
1490
|
-
title: 'Section 1',
|
|
1491
|
-
columns: 2,
|
|
1492
|
-
fields: ['fieldA', 'fieldB'],
|
|
1493
|
-
show_when: [{
|
|
1494
|
-
field: 'showSection1',
|
|
1495
|
-
op: "=",
|
|
1496
|
-
value: true
|
|
1497
|
-
}]
|
|
1498
|
-
}, {
|
|
1499
|
-
title: 'Section 2',
|
|
1500
|
-
columns: 1,
|
|
1501
|
-
fields: ['fieldC']
|
|
1502
|
-
}]
|
|
1503
|
-
},
|
|
1504
|
-
components: [{
|
|
1505
|
-
fieldId: 'fieldA'
|
|
1506
|
-
}, {
|
|
1507
|
-
fieldId: 'fieldB'
|
|
1508
|
-
}, {
|
|
1509
|
-
fieldId: 'fieldC'
|
|
1510
|
-
}]
|
|
1511
|
-
}];
|
|
1512
|
-
var CONFIG = {
|
|
1513
|
-
title: 'Title'
|
|
1514
|
-
};
|
|
1515
|
-
var CUSTOM_ENTRY = _objectSpread(_objectSpread({}, ENTRY), {}, {
|
|
1516
|
-
showSection1: false
|
|
1517
|
-
});
|
|
1518
|
-
var _renderWithValidation38 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
|
|
1519
|
-
id: ID,
|
|
1520
|
-
entryData: CUSTOM_ENTRY,
|
|
1521
|
-
config: CONFIG,
|
|
1522
|
-
parentCollectionName: "parent",
|
|
1523
|
-
pages: CHILD_PAGES,
|
|
1524
|
-
formData: {},
|
|
1525
|
-
masterPage: {
|
|
1526
|
-
childPages: CHILD_PAGES
|
|
1527
|
-
}
|
|
1528
|
-
})),
|
|
1529
|
-
container = _renderWithValidation38.container;
|
|
1530
|
-
|
|
1531
|
-
// Function to find an element by its text content
|
|
1532
|
-
function getByTextContent(parent, text) {
|
|
1533
|
-
return Array.from(parent.getElementsByClassName(classes('section-title'))).find(function (el) {
|
|
1534
|
-
return el.textContent === text;
|
|
1535
|
-
});
|
|
1536
|
-
}
|
|
1537
|
-
|
|
1538
|
-
// Check for section titles
|
|
1539
|
-
var section1Title = getByTextContent(container, 'Section 1');
|
|
1540
|
-
var section2Title = getByTextContent(container, 'Section 2');
|
|
1541
|
-
expect(section1Title).toBeUndefined();
|
|
1542
|
-
expect(section2Title).not.toBeUndefined();
|
|
1543
|
-
var section2Content = section2Title.parentNode.querySelector(".".concat(classes('section-content')));
|
|
1544
|
-
expect(section2Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(1);
|
|
1545
|
-
});
|
|
1546
|
-
it('should not render sections on pages that fail show_when checks', function () {
|
|
1547
|
-
var CHILD_PAGES = [{
|
|
1548
|
-
show_when: [{
|
|
1549
|
-
field: 'testField',
|
|
1550
|
-
op: '=',
|
|
1551
|
-
value: true
|
|
1552
|
-
}],
|
|
1553
|
-
summaryLayout: {
|
|
1554
|
-
sections: [{
|
|
1555
|
-
title: 'Section 1',
|
|
1556
|
-
columns: 2,
|
|
1557
|
-
fields: ['fieldA', 'fieldB'],
|
|
1558
|
-
show_when: [{
|
|
1559
|
-
field: 'showSection1',
|
|
1560
|
-
op: "=",
|
|
1561
|
-
value: true
|
|
1562
|
-
}]
|
|
1563
|
-
}, {
|
|
1564
|
-
title: 'Section 2',
|
|
1565
|
-
columns: 1,
|
|
1566
|
-
fields: ['fieldC']
|
|
1567
|
-
}]
|
|
1568
|
-
},
|
|
1569
|
-
components: [{
|
|
1570
|
-
fieldId: 'fieldA'
|
|
1571
|
-
}, {
|
|
1572
|
-
fieldId: 'fieldB'
|
|
1573
|
-
}, {
|
|
1574
|
-
fieldId: 'fieldC'
|
|
1575
|
-
}]
|
|
1576
|
-
}];
|
|
1577
|
-
var CONFIG = {
|
|
1578
|
-
title: 'Title'
|
|
1579
|
-
};
|
|
1580
|
-
var CUSTOM_ENTRY = _objectSpread(_objectSpread({}, ENTRY), {}, {
|
|
1581
|
-
showSection1: false
|
|
1582
|
-
});
|
|
1583
|
-
var _renderWithValidation39 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
|
|
1584
|
-
id: ID,
|
|
1585
|
-
entryData: CUSTOM_ENTRY,
|
|
1586
|
-
config: CONFIG,
|
|
1587
|
-
parentCollectionName: "parent",
|
|
1588
|
-
pages: CHILD_PAGES,
|
|
1589
|
-
formData: {
|
|
1590
|
-
testField: false
|
|
1591
|
-
},
|
|
1592
|
-
masterPage: {
|
|
1593
|
-
childPages: CHILD_PAGES
|
|
1594
|
-
}
|
|
1595
|
-
})),
|
|
1596
|
-
container = _renderWithValidation39.container;
|
|
1597
|
-
|
|
1598
|
-
// Function to find an element by its text content
|
|
1599
|
-
function getByTextContent(parent, text) {
|
|
1600
|
-
return Array.from(parent.getElementsByClassName(classes('section-title'))).find(function (el) {
|
|
1601
|
-
return el.textContent === text;
|
|
1602
|
-
});
|
|
1603
|
-
}
|
|
1604
|
-
|
|
1605
|
-
// Check for section titles
|
|
1606
|
-
var section1Title = getByTextContent(container, 'Section 1');
|
|
1607
|
-
var section2Title = getByTextContent(container, 'Section 2');
|
|
1608
|
-
expect(section1Title).toBeUndefined();
|
|
1609
|
-
expect(section2Title).toBeUndefined();
|
|
1610
|
-
});
|
|
1611
|
-
});
|
|
1612
1369
|
});
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.DEFAULT_CLASS = void 0;
|
|
7
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _utils = _interopRequireDefault(require("../../utils"));
|
|
10
|
+
var _FormComponent = _interopRequireDefault(require("../FormComponent"));
|
|
11
|
+
require("./SummaryCardDetails.scss");
|
|
12
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
13
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
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); }
|
|
16
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
17
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
18
|
+
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; }
|
|
19
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
20
|
+
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); } // Global imports.
|
|
21
|
+
// Local imports.
|
|
22
|
+
// Styles.
|
|
23
|
+
var DEFAULT_CLASS = exports.DEFAULT_CLASS = 'hods-form-summary-card-details';
|
|
24
|
+
var SummaryCardDetails = function SummaryCardDetails(_ref) {
|
|
25
|
+
var _masterPage$childPage;
|
|
26
|
+
var masterPage = _ref.masterPage,
|
|
27
|
+
childCollections = _ref.childCollections,
|
|
28
|
+
formData = _ref.formData,
|
|
29
|
+
entryData = _ref.entryData,
|
|
30
|
+
classModifiers = _ref.classModifiers,
|
|
31
|
+
hideChildSectionTitles = _ref.hideChildSectionTitles;
|
|
32
|
+
var classes = _utils.default.classBuilder(DEFAULT_CLASS, classModifiers);
|
|
33
|
+
var childMasterPages = (0, _react.useMemo)(function () {
|
|
34
|
+
return childCollections.map(function (childName) {
|
|
35
|
+
return masterPage.childPages.find(function (page) {
|
|
36
|
+
var _page$collection;
|
|
37
|
+
return ((_page$collection = page.collection) === null || _page$collection === void 0 ? void 0 : _page$collection.name) === childName;
|
|
38
|
+
});
|
|
39
|
+
}).filter(function (e) {
|
|
40
|
+
return !!e;
|
|
41
|
+
});
|
|
42
|
+
}, [masterPage, childCollections]);
|
|
43
|
+
return (masterPage === null || masterPage === void 0 || (_masterPage$childPage = masterPage.childPages) === null || _masterPage$childPage === void 0 ? void 0 : _masterPage$childPage.filter(function (p) {
|
|
44
|
+
return _utils.default.FormPage.show(p, _objectSpread(_objectSpread({}, formData), entryData));
|
|
45
|
+
}).map(function (childPage) {
|
|
46
|
+
var _childPage$summaryLay;
|
|
47
|
+
var allPageComponents = _utils.default.Component.elevateNested(childPage === null || childPage === void 0 ? void 0 : childPage.components, entryData);
|
|
48
|
+
return (_childPage$summaryLay = childPage.summaryLayout) === null || _childPage$summaryLay === void 0 ? void 0 : _childPage$summaryLay.sections.map(function (section) {
|
|
49
|
+
var _section$fields;
|
|
50
|
+
if (section.show_when && !_utils.default.Condition.meetsAll(section.show_when, _objectSpread(_objectSpread({}, formData), entryData))) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
if (section.type === 'childCollection') {
|
|
54
|
+
var childMasterPage = childMasterPages.find(function (p) {
|
|
55
|
+
return p.collection.name === section.collectionName;
|
|
56
|
+
});
|
|
57
|
+
var childFormData = entryData[section.collectionName.split('.').pop()] || [];
|
|
58
|
+
if (childMasterPage && childFormData.length > 0) {
|
|
59
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("h3", {
|
|
60
|
+
className: classes('section-title')
|
|
61
|
+
}, section.title), childFormData.map(function (entry) {
|
|
62
|
+
return /*#__PURE__*/_react.default.createElement(SummaryCardDetails, {
|
|
63
|
+
masterPage: childMasterPage,
|
|
64
|
+
childMasterPages: [],
|
|
65
|
+
formData: _objectSpread(_objectSpread(_objectSpread({}, formData), entryData), entry),
|
|
66
|
+
entryData: entry,
|
|
67
|
+
hideChildSectionTitles: true
|
|
68
|
+
});
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
74
|
+
key: section.title,
|
|
75
|
+
className: classes('section')
|
|
76
|
+
}, !hideChildSectionTitles && /*#__PURE__*/_react.default.createElement("h3", {
|
|
77
|
+
className: classes('section-title')
|
|
78
|
+
}, section.title), /*#__PURE__*/_react.default.createElement("div", {
|
|
79
|
+
className: classes('section-content', "columns-".concat(section.columns))
|
|
80
|
+
}, (_section$fields = section.fields) === null || _section$fields === void 0 ? void 0 : _section$fields.map(function (fieldId) {
|
|
81
|
+
var component = allPageComponents.find(function (comp) {
|
|
82
|
+
return comp.fieldId === fieldId;
|
|
83
|
+
});
|
|
84
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
85
|
+
key: fieldId,
|
|
86
|
+
className: classes('field')
|
|
87
|
+
}, /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
88
|
+
component: _objectSpread(_objectSpread({}, component), {}, {
|
|
89
|
+
hint: ''
|
|
90
|
+
}),
|
|
91
|
+
value: entryData[component === null || component === void 0 ? void 0 : component.fieldId],
|
|
92
|
+
formData: entryData,
|
|
93
|
+
wrap: true,
|
|
94
|
+
readonly: true
|
|
95
|
+
}));
|
|
96
|
+
})));
|
|
97
|
+
});
|
|
98
|
+
}).filter(function (e) {
|
|
99
|
+
return !!e;
|
|
100
|
+
})) || null;
|
|
101
|
+
};
|
|
102
|
+
SummaryCardDetails.propTypes = {
|
|
103
|
+
childCollections: _propTypes.default.arrayOf(_propTypes.default.string),
|
|
104
|
+
masterPage: _propTypes.default.shape({
|
|
105
|
+
childPages: _propTypes.default.arrayOf(_propTypes.default.shape({})).isRequired
|
|
106
|
+
}).isRequired,
|
|
107
|
+
formData: _propTypes.default.shape({}).isRequired,
|
|
108
|
+
entryData: _propTypes.default.shape({}).isRequired,
|
|
109
|
+
classModifiers: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
|
|
110
|
+
hideChildSectionTitles: _propTypes.default.bool
|
|
111
|
+
};
|
|
112
|
+
SummaryCardDetails.defaultProps = {
|
|
113
|
+
childCollections: [],
|
|
114
|
+
classModifiers: null,
|
|
115
|
+
hideChildSectionTitles: false
|
|
116
|
+
};
|
|
117
|
+
var _default = exports.default = SummaryCardDetails;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
$govuk-font-family: 'Roboto', arial, sans-serif;
|
|
2
|
+
|
|
3
|
+
@import "node_modules/govuk-frontend/govuk/_base";
|
|
4
|
+
|
|
5
|
+
.govuk-grid-column-two-thirds:has(.hods-form-summary-card-details) {
|
|
6
|
+
width: 100% !important;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.hods-form-summary-card-details {
|
|
10
|
+
&__section {
|
|
11
|
+
border-bottom: 2px solid #E9EBED;
|
|
12
|
+
|
|
13
|
+
&-title {
|
|
14
|
+
font-weight: bold;
|
|
15
|
+
margin: govuk-spacing(2) 0 govuk-spacing(6) 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
&-content {
|
|
19
|
+
display: flex;
|
|
20
|
+
flex-wrap: wrap;
|
|
21
|
+
gap: govuk-spacing(2);
|
|
22
|
+
|
|
23
|
+
.hods-form-summary-card-details__field {
|
|
24
|
+
box-sizing: border-box;
|
|
25
|
+
margin-bottom: govuk-spacing(4);
|
|
26
|
+
|
|
27
|
+
.govuk-label,
|
|
28
|
+
.govuk-fieldset__legend {
|
|
29
|
+
font-weight: bold;
|
|
30
|
+
margin-bottom: govuk-spacing(1) !important;
|
|
31
|
+
|
|
32
|
+
&::after {
|
|
33
|
+
content: " :";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
div.govuk-form-group div:has(img){
|
|
38
|
+
display: flex;
|
|
39
|
+
flex-wrap: wrap;
|
|
40
|
+
|
|
41
|
+
.hods-readonly.hods-readonly--success {
|
|
42
|
+
font-size: 0;
|
|
43
|
+
line-height: 0;
|
|
44
|
+
|
|
45
|
+
.cop-upload-preview__thumb {
|
|
46
|
+
display: inline-block;
|
|
47
|
+
margin-right: govuk-spacing(1);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
&--columns-1,
|
|
55
|
+
&--columns-2,
|
|
56
|
+
&--columns-3 {
|
|
57
|
+
position: relative;
|
|
58
|
+
margin-bottom: govuk-spacing(1);
|
|
59
|
+
|
|
60
|
+
&::before {
|
|
61
|
+
content: "";
|
|
62
|
+
position: absolute;
|
|
63
|
+
top: 0;
|
|
64
|
+
width: 2px;
|
|
65
|
+
height: 100%;
|
|
66
|
+
background-color: #E9EBED;
|
|
67
|
+
left: 0;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
&--columns-2 {
|
|
72
|
+
&::after {
|
|
73
|
+
content: "";
|
|
74
|
+
position: absolute;
|
|
75
|
+
top: 0;
|
|
76
|
+
width: 2px;
|
|
77
|
+
height: 100%;
|
|
78
|
+
background-color: #E9EBED;
|
|
79
|
+
left: 50%;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.hods-form-summary-card-details__field {
|
|
83
|
+
flex: 0 0 calc(50% - 10px);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
&--columns-3 {
|
|
88
|
+
&::after {
|
|
89
|
+
content: "";
|
|
90
|
+
position: absolute;
|
|
91
|
+
top: 0;
|
|
92
|
+
left: 33.333%;
|
|
93
|
+
width: 2px;
|
|
94
|
+
height: 100%;
|
|
95
|
+
background-color: #E9EBED;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.hods-form-summary-card-details__field {
|
|
99
|
+
flex: 0 0 calc(33.333% - 10px);
|
|
100
|
+
|
|
101
|
+
&:nth-child(2)::after {
|
|
102
|
+
content: "";
|
|
103
|
+
position: absolute;
|
|
104
|
+
top: 0;
|
|
105
|
+
right: 33.333%;
|
|
106
|
+
width: 2px;
|
|
107
|
+
height: 100%;
|
|
108
|
+
background-color: #E9EBED;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
@media (max-width: 640px) {
|
|
117
|
+
.hods-form-summary-card-details {
|
|
118
|
+
&__section {
|
|
119
|
+
&-content {
|
|
120
|
+
display: block;
|
|
121
|
+
|
|
122
|
+
.hods-form-summary-card-details__field {
|
|
123
|
+
width: 100%;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.hods-form-summary-card-details__field:nth-child(2)::after {
|
|
127
|
+
display: none;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
&--columns-2,
|
|
131
|
+
&--columns-3 {
|
|
132
|
+
position: relative;
|
|
133
|
+
margin-bottom: govuk-spacing(1);
|
|
134
|
+
|
|
135
|
+
&::before {
|
|
136
|
+
content: '';
|
|
137
|
+
position: absolute;
|
|
138
|
+
top: 0;
|
|
139
|
+
width: 2px;
|
|
140
|
+
height: 100%;
|
|
141
|
+
background-color: #A9A9A9;
|
|
142
|
+
left: 0;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
&::after {
|
|
146
|
+
display: none;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
&--columns-3 {
|
|
151
|
+
.hods-form-summary-card-details__field:nth-child(2)::after {
|
|
152
|
+
content: none;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _react = _interopRequireDefault(require("react"));
|
|
4
|
+
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
5
|
+
var _setupTests = require("../../setupTests");
|
|
6
|
+
var _SummaryCardDetails = _interopRequireWildcard(require("./SummaryCardDetails"));
|
|
7
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
8
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
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); }
|
|
11
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
12
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
13
|
+
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; }
|
|
14
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
15
|
+
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); } // Global imports.
|
|
16
|
+
// Local imports.
|
|
17
|
+
describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
18
|
+
var classes = _copReactComponents.Utils.classBuilder(_SummaryCardDetails.DEFAULT_CLASS, [], '');
|
|
19
|
+
var ENTRY = {
|
|
20
|
+
id: '001',
|
|
21
|
+
bannerText: 'A banner',
|
|
22
|
+
titleText: 'A title',
|
|
23
|
+
detailsText: 'Some details',
|
|
24
|
+
index: 0,
|
|
25
|
+
summaryText: 'Full details',
|
|
26
|
+
childCollection: [{
|
|
27
|
+
id: '001',
|
|
28
|
+
childField1: 'alpha',
|
|
29
|
+
childField2: 'bravo'
|
|
30
|
+
}, {
|
|
31
|
+
id: '002',
|
|
32
|
+
childField1: 'alpha',
|
|
33
|
+
childField2: 'bravo'
|
|
34
|
+
}]
|
|
35
|
+
};
|
|
36
|
+
it('should render sections and fields based on summaryLayout config', function () {
|
|
37
|
+
var CHILD_PAGES = [{
|
|
38
|
+
summaryLayout: {
|
|
39
|
+
sections: [{
|
|
40
|
+
title: 'Section 1',
|
|
41
|
+
columns: 2,
|
|
42
|
+
fields: ['fieldA', 'fieldB']
|
|
43
|
+
}, {
|
|
44
|
+
title: 'Section 2',
|
|
45
|
+
columns: 1,
|
|
46
|
+
fields: ['fieldC']
|
|
47
|
+
}]
|
|
48
|
+
},
|
|
49
|
+
components: [{
|
|
50
|
+
fieldId: 'fieldA'
|
|
51
|
+
}, {
|
|
52
|
+
fieldId: 'fieldB'
|
|
53
|
+
}, {
|
|
54
|
+
fieldId: 'fieldC'
|
|
55
|
+
}]
|
|
56
|
+
}];
|
|
57
|
+
var MASTER_PAGE = {
|
|
58
|
+
childPages: CHILD_PAGES
|
|
59
|
+
};
|
|
60
|
+
var _renderWithValidation = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
|
|
61
|
+
masterPage: MASTER_PAGE,
|
|
62
|
+
childMasterPages: [],
|
|
63
|
+
formData: {},
|
|
64
|
+
entryData: ENTRY
|
|
65
|
+
})),
|
|
66
|
+
container = _renderWithValidation.container;
|
|
67
|
+
|
|
68
|
+
// Function to find an element by its text content
|
|
69
|
+
function getByTextContent(parent, text) {
|
|
70
|
+
return Array.from(parent.getElementsByClassName(classes('section-title'))).find(function (el) {
|
|
71
|
+
return el.textContent === text;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Check for section titles
|
|
76
|
+
var section1Title = getByTextContent(container, 'Section 1');
|
|
77
|
+
var section2Title = getByTextContent(container, 'Section 2');
|
|
78
|
+
expect(section1Title).not.toBeUndefined();
|
|
79
|
+
expect(section2Title).not.toBeUndefined();
|
|
80
|
+
var section1Content = section1Title.parentNode.querySelector(".".concat(classes('section-content')));
|
|
81
|
+
expect(section1Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(2);
|
|
82
|
+
var section2Content = section2Title.parentNode.querySelector(".".concat(classes('section-content')));
|
|
83
|
+
expect(section2Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(1);
|
|
84
|
+
});
|
|
85
|
+
it('should render sections if they have show_when checks and pass them', function () {
|
|
86
|
+
var CHILD_PAGES = [{
|
|
87
|
+
summaryLayout: {
|
|
88
|
+
sections: [{
|
|
89
|
+
title: 'Section 1',
|
|
90
|
+
columns: 2,
|
|
91
|
+
fields: ['fieldA', 'fieldB'],
|
|
92
|
+
show_when: [{
|
|
93
|
+
field: 'showSection1',
|
|
94
|
+
op: "=",
|
|
95
|
+
value: true
|
|
96
|
+
}]
|
|
97
|
+
}, {
|
|
98
|
+
title: 'Section 2',
|
|
99
|
+
columns: 1,
|
|
100
|
+
fields: ['fieldC']
|
|
101
|
+
}]
|
|
102
|
+
},
|
|
103
|
+
components: [{
|
|
104
|
+
fieldId: 'fieldA'
|
|
105
|
+
}, {
|
|
106
|
+
fieldId: 'fieldB'
|
|
107
|
+
}, {
|
|
108
|
+
fieldId: 'fieldC'
|
|
109
|
+
}]
|
|
110
|
+
}];
|
|
111
|
+
var MASTER_PAGE = {
|
|
112
|
+
childPages: CHILD_PAGES
|
|
113
|
+
};
|
|
114
|
+
var CUSTOM_ENTRY = _objectSpread(_objectSpread({}, ENTRY), {}, {
|
|
115
|
+
showSection1: true
|
|
116
|
+
});
|
|
117
|
+
var _renderWithValidation2 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
|
|
118
|
+
masterPage: MASTER_PAGE,
|
|
119
|
+
childMasterPages: [],
|
|
120
|
+
formData: {},
|
|
121
|
+
entryData: CUSTOM_ENTRY
|
|
122
|
+
})),
|
|
123
|
+
container = _renderWithValidation2.container;
|
|
124
|
+
|
|
125
|
+
// Function to find an element by its text content
|
|
126
|
+
function getByTextContent(parent, text) {
|
|
127
|
+
return Array.from(parent.getElementsByClassName(classes('section-title'))).find(function (el) {
|
|
128
|
+
return el.textContent === text;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Check for section titles
|
|
133
|
+
var section1Title = getByTextContent(container, 'Section 1');
|
|
134
|
+
var section2Title = getByTextContent(container, 'Section 2');
|
|
135
|
+
expect(section1Title).not.toBeUndefined();
|
|
136
|
+
expect(section2Title).not.toBeUndefined();
|
|
137
|
+
var section1Content = section1Title.parentNode.querySelector(".".concat(classes('section-content')));
|
|
138
|
+
expect(section1Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(2);
|
|
139
|
+
var section2Content = section2Title.parentNode.querySelector(".".concat(classes('section-content')));
|
|
140
|
+
expect(section2Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(1);
|
|
141
|
+
});
|
|
142
|
+
it('should not render sections if they have show_when checks and fail them', function () {
|
|
143
|
+
var CHILD_PAGES = [{
|
|
144
|
+
summaryLayout: {
|
|
145
|
+
sections: [{
|
|
146
|
+
title: 'Section 1',
|
|
147
|
+
columns: 2,
|
|
148
|
+
fields: ['fieldA', 'fieldB'],
|
|
149
|
+
show_when: [{
|
|
150
|
+
field: 'showSection1',
|
|
151
|
+
op: "=",
|
|
152
|
+
value: true
|
|
153
|
+
}]
|
|
154
|
+
}, {
|
|
155
|
+
title: 'Section 2',
|
|
156
|
+
columns: 1,
|
|
157
|
+
fields: ['fieldC']
|
|
158
|
+
}]
|
|
159
|
+
},
|
|
160
|
+
components: [{
|
|
161
|
+
fieldId: 'fieldA'
|
|
162
|
+
}, {
|
|
163
|
+
fieldId: 'fieldB'
|
|
164
|
+
}, {
|
|
165
|
+
fieldId: 'fieldC'
|
|
166
|
+
}]
|
|
167
|
+
}];
|
|
168
|
+
var MASTER_PAGE = {
|
|
169
|
+
childPages: CHILD_PAGES
|
|
170
|
+
};
|
|
171
|
+
var CUSTOM_ENTRY = _objectSpread(_objectSpread({}, ENTRY), {}, {
|
|
172
|
+
showSection1: false
|
|
173
|
+
});
|
|
174
|
+
var _renderWithValidation3 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
|
|
175
|
+
masterPage: MASTER_PAGE,
|
|
176
|
+
childMasterPages: [],
|
|
177
|
+
formData: {},
|
|
178
|
+
entryData: CUSTOM_ENTRY
|
|
179
|
+
})),
|
|
180
|
+
container = _renderWithValidation3.container;
|
|
181
|
+
|
|
182
|
+
// Function to find an element by its text content
|
|
183
|
+
function getByTextContent(parent, text) {
|
|
184
|
+
return Array.from(parent.getElementsByClassName(classes('section-title'))).find(function (el) {
|
|
185
|
+
return el.textContent === text;
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Check for section titles
|
|
190
|
+
var section1Title = getByTextContent(container, 'Section 1');
|
|
191
|
+
var section2Title = getByTextContent(container, 'Section 2');
|
|
192
|
+
expect(section1Title).toBeUndefined();
|
|
193
|
+
expect(section2Title).not.toBeUndefined();
|
|
194
|
+
var section2Content = section2Title.parentNode.querySelector(".".concat(classes('section-content')));
|
|
195
|
+
expect(section2Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(1);
|
|
196
|
+
});
|
|
197
|
+
it('should not render sections on pages that fail show_when checks', function () {
|
|
198
|
+
var CHILD_PAGES = [{
|
|
199
|
+
show_when: [{
|
|
200
|
+
field: 'testField',
|
|
201
|
+
op: '=',
|
|
202
|
+
value: true
|
|
203
|
+
}],
|
|
204
|
+
summaryLayout: {
|
|
205
|
+
sections: [{
|
|
206
|
+
title: 'Section 1',
|
|
207
|
+
columns: 2,
|
|
208
|
+
fields: ['fieldA', 'fieldB'],
|
|
209
|
+
show_when: [{
|
|
210
|
+
field: 'showSection1',
|
|
211
|
+
op: "=",
|
|
212
|
+
value: true
|
|
213
|
+
}]
|
|
214
|
+
}, {
|
|
215
|
+
title: 'Section 2',
|
|
216
|
+
columns: 1,
|
|
217
|
+
fields: ['fieldC']
|
|
218
|
+
}]
|
|
219
|
+
},
|
|
220
|
+
components: [{
|
|
221
|
+
fieldId: 'fieldA'
|
|
222
|
+
}, {
|
|
223
|
+
fieldId: 'fieldB'
|
|
224
|
+
}, {
|
|
225
|
+
fieldId: 'fieldC'
|
|
226
|
+
}]
|
|
227
|
+
}];
|
|
228
|
+
var MASTER_PAGE = {
|
|
229
|
+
childPages: CHILD_PAGES
|
|
230
|
+
};
|
|
231
|
+
var CUSTOM_ENTRY = _objectSpread(_objectSpread({}, ENTRY), {}, {
|
|
232
|
+
showSection1: false
|
|
233
|
+
});
|
|
234
|
+
var _renderWithValidation4 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
|
|
235
|
+
masterPage: MASTER_PAGE,
|
|
236
|
+
childMasterPages: [],
|
|
237
|
+
formData: {
|
|
238
|
+
testField: false
|
|
239
|
+
},
|
|
240
|
+
entryData: CUSTOM_ENTRY
|
|
241
|
+
})),
|
|
242
|
+
container = _renderWithValidation4.container;
|
|
243
|
+
|
|
244
|
+
// Function to find an element by its text content
|
|
245
|
+
function getByTextContent(parent, text) {
|
|
246
|
+
return Array.from(parent.getElementsByClassName(classes('section-title'))).find(function (el) {
|
|
247
|
+
return el.textContent === text;
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Check for section titles
|
|
252
|
+
var section1Title = getByTextContent(container, 'Section 1');
|
|
253
|
+
var section2Title = getByTextContent(container, 'Section 2');
|
|
254
|
+
expect(section1Title).toBeUndefined();
|
|
255
|
+
expect(section2Title).toBeUndefined();
|
|
256
|
+
});
|
|
257
|
+
it('should render child collections', function () {
|
|
258
|
+
var CHILD_MASTER_PAGES = [{
|
|
259
|
+
collection: {
|
|
260
|
+
name: 'childCollection'
|
|
261
|
+
},
|
|
262
|
+
childPages: [{
|
|
263
|
+
components: [{
|
|
264
|
+
fieldId: 'childField1'
|
|
265
|
+
}, {
|
|
266
|
+
fieldId: 'childField2'
|
|
267
|
+
}],
|
|
268
|
+
summaryLayout: {
|
|
269
|
+
sections: [{
|
|
270
|
+
title: 'Hidden Title',
|
|
271
|
+
columns: 2,
|
|
272
|
+
fields: ['childfield1', 'childfield2']
|
|
273
|
+
}]
|
|
274
|
+
}
|
|
275
|
+
}]
|
|
276
|
+
}];
|
|
277
|
+
var CHILD_PAGES = [{
|
|
278
|
+
summaryLayout: {
|
|
279
|
+
sections: [{
|
|
280
|
+
type: 'childCollection',
|
|
281
|
+
collectionName: 'childCollection',
|
|
282
|
+
title: 'Children'
|
|
283
|
+
}]
|
|
284
|
+
},
|
|
285
|
+
components: [{
|
|
286
|
+
fieldId: 'fieldA'
|
|
287
|
+
}, {
|
|
288
|
+
fieldId: 'fieldB'
|
|
289
|
+
}, {
|
|
290
|
+
fieldId: 'fieldC'
|
|
291
|
+
}]
|
|
292
|
+
}];
|
|
293
|
+
var MASTER_PAGE = {
|
|
294
|
+
childPages: [].concat(CHILD_PAGES, CHILD_MASTER_PAGES)
|
|
295
|
+
};
|
|
296
|
+
var CHILD_COLLECTIONS = ['childCollection'];
|
|
297
|
+
var _renderWithValidation5 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
|
|
298
|
+
masterPage: MASTER_PAGE,
|
|
299
|
+
childCollections: CHILD_COLLECTIONS,
|
|
300
|
+
formData: {},
|
|
301
|
+
entryData: ENTRY
|
|
302
|
+
})),
|
|
303
|
+
container = _renderWithValidation5.container;
|
|
304
|
+
|
|
305
|
+
// Function to find an element by its text content
|
|
306
|
+
function getByTextContent(parent, text) {
|
|
307
|
+
return Array.from(parent.getElementsByClassName(classes('section-title'))).find(function (el) {
|
|
308
|
+
return el.textContent === text;
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
var childCollectionSectionTitle = getByTextContent(container, 'Children');
|
|
312
|
+
expect(childCollectionSectionTitle).not.toBeUndefined();
|
|
313
|
+
var childSectionTitles = getByTextContent(container, 'Hidden Title');
|
|
314
|
+
expect(childSectionTitles).toBeUndefined(); // Individual section title for child collections should be hidden.
|
|
315
|
+
|
|
316
|
+
var childFields = container.querySelectorAll(".".concat(classes('field')));
|
|
317
|
+
expect(childFields.length).toEqual(4); // Two for each entry in the child collection.
|
|
318
|
+
});
|
|
319
|
+
});
|
|
@@ -157,7 +157,7 @@ var getCYARowsForChildPages = function getCYARowsForChildPages(childPages, item,
|
|
|
157
157
|
}
|
|
158
158
|
var container = getContainerForPage(childPage, item, labelCount, fullPath);
|
|
159
159
|
var rowChangeAction = getChangeActionForPage(childPage, onAction, activeIds);
|
|
160
|
-
var containerRows = (0, _getCYARowsForContainer.default)(childPage, container, item, rowChangeAction, fnOverride);
|
|
160
|
+
var containerRows = (0, _getCYARowsForContainer.default)(childPage, container, _objectSpread(_objectSpread({}, childPage.formData), item), rowChangeAction, fnOverride);
|
|
161
161
|
rows = rows.concat(containerRows);
|
|
162
162
|
}
|
|
163
163
|
}
|
|
@@ -170,6 +170,41 @@ describe('utils.CheckYourAnswers.getCYARowsForCollectionPage', function () {
|
|
|
170
170
|
key: 'Test date'
|
|
171
171
|
});
|
|
172
172
|
});
|
|
173
|
+
it('should use values from top-level formData if they don\'t exist in the item', function () {
|
|
174
|
+
var FORM_DATA = {
|
|
175
|
+
testText: 'value',
|
|
176
|
+
collection: [{
|
|
177
|
+
id: '01'
|
|
178
|
+
}]
|
|
179
|
+
};
|
|
180
|
+
var PAGE = _objectSpread(_objectSpread({}, MASTER_PAGE), {}, {
|
|
181
|
+
childPages: [_objectSpread(_objectSpread({}, PAGES[0]), {}, {
|
|
182
|
+
formData: FORM_DATA
|
|
183
|
+
}), PAGES[1]],
|
|
184
|
+
formData: FORM_DATA
|
|
185
|
+
});
|
|
186
|
+
var ROWS = (0, _getCYARowsForCollectionPage.default)(PAGE, null, null, FORM_DATA);
|
|
187
|
+
expect(ROWS.length).toEqual(7); // Title row + component row for each item
|
|
188
|
+
expect(ROWS[0]).toMatchObject({
|
|
189
|
+
type: 'heading',
|
|
190
|
+
key: 'Collection'
|
|
191
|
+
});
|
|
192
|
+
expect(ROWS[1]).toMatchObject({
|
|
193
|
+
type: 'heading',
|
|
194
|
+
key: 'Collection entry 1'
|
|
195
|
+
});
|
|
196
|
+
expect(ROWS[2].action.label).toEqual('Change');
|
|
197
|
+
expect(ROWS[3].action.label).toEqual('custom remove label');
|
|
198
|
+
expect(ROWS[4].action.label).toEqual('custom change label');
|
|
199
|
+
expect(ROWS[5]).toMatchObject({
|
|
200
|
+
value: 'value',
|
|
201
|
+
key: 'Test text'
|
|
202
|
+
});
|
|
203
|
+
expect(ROWS[6]).toMatchObject({
|
|
204
|
+
value: '',
|
|
205
|
+
key: 'Test date'
|
|
206
|
+
});
|
|
207
|
+
});
|
|
173
208
|
it('should return correctly formatted rows for only the active entry when page.collection.onlyShowActiveEntryOnCYA is defined', function () {
|
|
174
209
|
var FORM_DATA = {
|
|
175
210
|
collectionActiveId: '02',
|
|
@@ -84,7 +84,7 @@ var nestUnderParent = function nestUnderParent(childPage, masterPages) {
|
|
|
84
84
|
*/
|
|
85
85
|
var mergeCollectionPages = function mergeCollectionPages(pages) {
|
|
86
86
|
var masterPages = {};
|
|
87
|
-
|
|
87
|
+
var pagesWithMasters = pages.map(function (page) {
|
|
88
88
|
var _page$collection;
|
|
89
89
|
if (page !== null && page !== void 0 && (_page$collection = page.collection) !== null && _page$collection !== void 0 && _page$collection.name) {
|
|
90
90
|
if (!masterPages[page.collection.name]) {
|
|
@@ -92,10 +92,7 @@ var mergeCollectionPages = function mergeCollectionPages(pages) {
|
|
|
92
92
|
// we kick one off using this page as a template.
|
|
93
93
|
var newMasterPage = createMasterPage(page);
|
|
94
94
|
masterPages[page.collection.name] = newMasterPage;
|
|
95
|
-
|
|
96
|
-
// if so then nest it under the parent master page and remove from
|
|
97
|
-
// the pages array. If not then treat it as a top-level collection.
|
|
98
|
-
return nestUnderParent(newMasterPage, masterPages) ? null : newMasterPage;
|
|
95
|
+
return newMasterPage;
|
|
99
96
|
}
|
|
100
97
|
// If a master page already exists for this collection.name
|
|
101
98
|
// then we just merge this page into it and remove this page
|
|
@@ -107,5 +104,17 @@ var mergeCollectionPages = function mergeCollectionPages(pages) {
|
|
|
107
104
|
}).filter(function (page) {
|
|
108
105
|
return !!page;
|
|
109
106
|
});
|
|
107
|
+
// We nest any child master pages under their parents here to
|
|
108
|
+
// ensure that all parent master pages have been created by the
|
|
109
|
+
// above code first.
|
|
110
|
+
return pagesWithMasters.map(function (page) {
|
|
111
|
+
var _page$collection2;
|
|
112
|
+
if ((_page$collection2 = page.collection) !== null && _page$collection2 !== void 0 && _page$collection2.masterPage) {
|
|
113
|
+
return nestUnderParent(page, masterPages) ? null : page;
|
|
114
|
+
}
|
|
115
|
+
return page;
|
|
116
|
+
}).filter(function (e) {
|
|
117
|
+
return !!e;
|
|
118
|
+
});
|
|
110
119
|
};
|
|
111
120
|
var _default = exports.default = mergeCollectionPages;
|
|
@@ -49,7 +49,7 @@ describe('utils.CollectionPage.mergeCollectionPages', function () {
|
|
|
49
49
|
childPages: PAGES
|
|
50
50
|
});
|
|
51
51
|
});
|
|
52
|
-
it('should correctly merge and
|
|
52
|
+
it('should correctly merge and nest child collection pages under their parents', function () {
|
|
53
53
|
var PAGES = [{
|
|
54
54
|
id: 'page1',
|
|
55
55
|
collection: {
|
|
@@ -95,6 +95,53 @@ describe('utils.CollectionPage.mergeCollectionPages', function () {
|
|
|
95
95
|
}]
|
|
96
96
|
});
|
|
97
97
|
});
|
|
98
|
+
it('should correctly merge and nest child collection pages under their parents, even if the child pages are created first', function () {
|
|
99
|
+
var PAGES = [{
|
|
100
|
+
id: 'page1',
|
|
101
|
+
collection: {
|
|
102
|
+
name: 'parent.child'
|
|
103
|
+
},
|
|
104
|
+
components: [TEXT_COMP]
|
|
105
|
+
}, {
|
|
106
|
+
id: 'page2',
|
|
107
|
+
collection: {
|
|
108
|
+
name: 'parent.child'
|
|
109
|
+
},
|
|
110
|
+
components: [DATE_COMP]
|
|
111
|
+
}, {
|
|
112
|
+
id: 'page3',
|
|
113
|
+
collection: {
|
|
114
|
+
name: 'parent'
|
|
115
|
+
},
|
|
116
|
+
components: [DATE_COMP]
|
|
117
|
+
}, {
|
|
118
|
+
id: 'page4',
|
|
119
|
+
collection: {
|
|
120
|
+
name: 'parent'
|
|
121
|
+
},
|
|
122
|
+
components: [DATE_COMP]
|
|
123
|
+
}];
|
|
124
|
+
var RESULT = (0, _mergeCollectionPages.default)(PAGES);
|
|
125
|
+
expect(RESULT.length).toEqual(1); // One master page for parent collection.
|
|
126
|
+
expect(RESULT[0].childPages.length).toEqual(3); // Two normal pages and the child collection's master page.
|
|
127
|
+
expect(RESULT[0]).toMatchObject({
|
|
128
|
+
id: 'page3',
|
|
129
|
+
collection: {
|
|
130
|
+
name: 'parent',
|
|
131
|
+
masterPage: true
|
|
132
|
+
},
|
|
133
|
+
formData: {},
|
|
134
|
+
childPages: [PAGES[2], PAGES[3], {
|
|
135
|
+
id: 'page1',
|
|
136
|
+
collection: {
|
|
137
|
+
name: 'parent.child',
|
|
138
|
+
masterPage: true
|
|
139
|
+
},
|
|
140
|
+
formData: {},
|
|
141
|
+
childPages: [PAGES[0], PAGES[1]]
|
|
142
|
+
}]
|
|
143
|
+
});
|
|
144
|
+
});
|
|
98
145
|
it('should leave non-collection pages unaffected', function () {
|
|
99
146
|
var PAGES = [{
|
|
100
147
|
id: 'page1',
|