@ukhomeoffice/cop-react-form-renderer 6.0.2-peter → 6.0.5-peter
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/CollectionPage/CollectionPage.js +2 -2
- package/dist/components/CollectionSummary/CollectionSummary.js +51 -6
- package/dist/components/CollectionSummary/CollectionSummary.test.js +30 -0
- package/dist/components/CollectionSummary/Confirmation.scss +12 -0
- package/dist/components/CollectionSummary/RenderListView.js +3 -21
- package/dist/components/CollectionSummary/RenderListView.scss +7 -0
- package/dist/components/CollectionSummary/RenderListView.test.js +20 -8
- package/dist/components/CollectionSummary/SummaryCard.scss +4 -6
- package/dist/components/CollectionSummary/SummaryCardDetails.js +5 -10
- package/dist/components/CollectionSummary/SummaryCardDetails.scss +27 -17
- package/dist/components/CollectionSummary/SummaryCardDetails.test.js +2 -2
- package/dist/components/FormComponent/FormComponent.js +1 -0
- package/dist/components/FormRenderer/helpers/clearOutUncompletedRoutes.js +14 -0
- package/dist/components/FormRenderer/onPageAction.js +6 -5
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +4 -2
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +79 -0
- package/dist/utils/CheckYourAnswers/getComponentRowForCYA.js +37 -0
- package/dist/utils/CheckYourAnswers/getComponentRowForCYA.test.js +41 -0
- package/dist/utils/CollectionPage/addCollectionPageEntry.js +4 -2
- package/dist/utils/CollectionPage/addCollectionPageEntry.test.js +20 -0
- package/package.json +1 -1
|
@@ -29,7 +29,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } // Global
|
|
|
29
29
|
// Styles
|
|
30
30
|
var DEFAULT_CLASS = exports.DEFAULT_CLASS = _FormPage2.DEFAULT_CLASS;
|
|
31
31
|
var CollectionPage = function CollectionPage(_ref) {
|
|
32
|
-
var _page$collection;
|
|
32
|
+
var _page$collection, _objectSpread4;
|
|
33
33
|
var page = _ref.page,
|
|
34
34
|
onCollectionChange = _ref.onCollectionChange,
|
|
35
35
|
onAction = _ref.onAction,
|
|
@@ -120,7 +120,7 @@ var CollectionPage = function CollectionPage(_ref) {
|
|
|
120
120
|
}
|
|
121
121
|
return /*#__PURE__*/_react.default.createElement(_FormPage.default, {
|
|
122
122
|
page: _objectSpread(_objectSpread({}, page), {}, {
|
|
123
|
-
formData: _objectSpread(_objectSpread(_objectSpread({}, page.formData), data[activeIndex]), {},
|
|
123
|
+
formData: _objectSpread(_objectSpread(_objectSpread({}, page.formData), data[activeIndex]), {}, (_objectSpread4 = {}, _defineProperty(_objectSpread4, "".concat(currentCollectionName, "ActiveIndex"), activeIndex), _defineProperty(_objectSpread4, "".concat(currentCollectionName, "NumberedIndex"), typeof activeIndex === 'number' ? activeIndex + 1 : null), _objectSpread4)),
|
|
124
124
|
components: page.components.map(function (component) {
|
|
125
125
|
return _objectSpread(_objectSpread({}, component), {}, {
|
|
126
126
|
pageCollection: _objectSpread({}, page.collection)
|
|
@@ -7,10 +7,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.default = exports.DEFAULT_ADD_BUTTON_LABEL = void 0;
|
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _hooks = require("../../hooks");
|
|
10
11
|
var _PageAction = require("../../models/PageAction");
|
|
11
12
|
var _utils = _interopRequireDefault(require("../../utils"));
|
|
13
|
+
var _getCYARow = _interopRequireDefault(require("../../utils/CheckYourAnswers/getCYARow"));
|
|
14
|
+
var _elevateNestedComponents = _interopRequireDefault(require("../../utils/Component/elevateNestedComponents"));
|
|
15
|
+
var _Answer = _interopRequireDefault(require("../CheckYourAnswers/Answer"));
|
|
12
16
|
var _ActionButton = _interopRequireDefault(require("../PageActions/ActionButton"));
|
|
13
|
-
var _hooks = require("../../hooks");
|
|
14
17
|
var _Confirmation = _interopRequireDefault(require("./Confirmation"));
|
|
15
18
|
var _SummaryCard = _interopRequireDefault(require("./SummaryCard"));
|
|
16
19
|
var _SummaryCardValidationContext = _interopRequireDefault(require("./SummaryCardValidationContext"));
|
|
@@ -46,7 +49,7 @@ var DEFAULT_ADD_BUTTON_LABEL = exports.DEFAULT_ADD_BUTTON_LABEL = 'Add';
|
|
|
46
49
|
// errors local to the Quick Edit page.
|
|
47
50
|
|
|
48
51
|
var CollectionSummary = function CollectionSummary(_ref) {
|
|
49
|
-
var _config$confirmation, _config$confirmation2;
|
|
52
|
+
var _config$confirmation, _config$confirmation2, _config$confirmation3;
|
|
50
53
|
var config = _ref.config,
|
|
51
54
|
formData = _ref.formData,
|
|
52
55
|
onAction = _ref.onAction,
|
|
@@ -83,6 +86,17 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
83
86
|
return currentPath;
|
|
84
87
|
}, "");
|
|
85
88
|
}, [pages]);
|
|
89
|
+
var allComponents = (0, _react.useMemo)(function () {
|
|
90
|
+
if (config.card.listView) {
|
|
91
|
+
var _masterPage$childPage;
|
|
92
|
+
var components = (_masterPage$childPage = masterPage.childPages) === null || _masterPage$childPage === void 0 ? void 0 : _masterPage$childPage.reduce(function (acc, page) {
|
|
93
|
+
var elevatedComponents = (0, _elevateNestedComponents.default)(page.components, _objectSpread(_objectSpread({}, formData), entryToDelete));
|
|
94
|
+
return acc.concat(elevatedComponents);
|
|
95
|
+
}, []);
|
|
96
|
+
return components || [];
|
|
97
|
+
}
|
|
98
|
+
return [];
|
|
99
|
+
}, [masterPage, formData, entryToDelete, config.card.listView]);
|
|
86
100
|
var validateEntries = function validateEntries() {
|
|
87
101
|
var stored = [];
|
|
88
102
|
// We only clear errors if it's not empty to avoid
|
|
@@ -181,6 +195,23 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
181
195
|
setEntryToDelete(null);
|
|
182
196
|
validateEntries();
|
|
183
197
|
};
|
|
198
|
+
var renderFieldValue = function renderFieldValue(field) {
|
|
199
|
+
var component = allComponents.find(function (c) {
|
|
200
|
+
return c.fieldId === field;
|
|
201
|
+
});
|
|
202
|
+
if (!component) return null;
|
|
203
|
+
var row = (0, _getCYARow.default)(_objectSpread(_objectSpread({}, masterPage), {}, {
|
|
204
|
+
formData: _objectSpread(_objectSpread({}, formData), entryToDelete)
|
|
205
|
+
}), component);
|
|
206
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
207
|
+
key: field,
|
|
208
|
+
className: "confirmation-field-value"
|
|
209
|
+
}, /*#__PURE__*/_react.default.createElement(_Answer.default, {
|
|
210
|
+
value: row.value,
|
|
211
|
+
component: row.component,
|
|
212
|
+
formData: row.formData
|
|
213
|
+
}));
|
|
214
|
+
};
|
|
184
215
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
185
216
|
id: config.fieldId
|
|
186
217
|
}, entryToDelete && /*#__PURE__*/_react.default.createElement(_Confirmation.default, {
|
|
@@ -191,7 +222,9 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
191
222
|
onCancel: function onCancel() {
|
|
192
223
|
return setEntryToDelete(null);
|
|
193
224
|
}
|
|
194
|
-
}, /*#__PURE__*/_react.default.createElement(
|
|
225
|
+
}, config.card.listView ? /*#__PURE__*/_react.default.createElement("div", {
|
|
226
|
+
className: "confirmation-content"
|
|
227
|
+
}, (_config$confirmation3 = config.confirmation) === null || _config$confirmation3 === void 0 ? void 0 : _config$confirmation3.displayFields.map(renderFieldValue)) : /*#__PURE__*/_react.default.createElement(_SummaryCard.default, {
|
|
195
228
|
id: "".concat(config.fieldId, ".confirmationChild"),
|
|
196
229
|
entryData: entryToDelete,
|
|
197
230
|
config: config.card ? _objectSpread(_objectSpread({}, config.card), {}, {
|
|
@@ -200,7 +233,7 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
200
233
|
masterPage: masterPage,
|
|
201
234
|
classModifiers: "nested",
|
|
202
235
|
hideDetails: true
|
|
203
|
-
})), config.addButton && /*#__PURE__*/_react.default.createElement(_ActionButton.default, {
|
|
236
|
+
})), !config.card.listView && config.addButton && /*#__PURE__*/_react.default.createElement(_ActionButton.default, {
|
|
204
237
|
id: "".concat(config.fieldId, ".addButton"),
|
|
205
238
|
action: {
|
|
206
239
|
collection: config.collectionName,
|
|
@@ -244,6 +277,16 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
244
277
|
return e.entryId === entry.id;
|
|
245
278
|
}).length > 0
|
|
246
279
|
}));
|
|
280
|
+
}), config.card.listView && config.addButton && /*#__PURE__*/_react.default.createElement(_ActionButton.default, {
|
|
281
|
+
id: "".concat(config.fieldId, ".addButton"),
|
|
282
|
+
action: {
|
|
283
|
+
collection: config.collectionName,
|
|
284
|
+
label: config.addButton.label || DEFAULT_ADD_BUTTON_LABEL,
|
|
285
|
+
page: config.addButton.page,
|
|
286
|
+
type: _PageAction.PageActionTypes.COLLECTION_ADD,
|
|
287
|
+
classModifiers: ['secondary']
|
|
288
|
+
},
|
|
289
|
+
onAction: onAction
|
|
247
290
|
}));
|
|
248
291
|
};
|
|
249
292
|
CollectionSummary.propTypes = {
|
|
@@ -261,7 +304,8 @@ CollectionSummary.propTypes = {
|
|
|
261
304
|
details: _propTypes.default.string,
|
|
262
305
|
duplicateAction: _propTypes.default.shape({
|
|
263
306
|
fieldsToIgnore: _propTypes.default.arrayOf(_propTypes.default.string)
|
|
264
|
-
})
|
|
307
|
+
}),
|
|
308
|
+
listView: _propTypes.default.bool
|
|
265
309
|
}),
|
|
266
310
|
errorCard: _propTypes.default.shape({
|
|
267
311
|
banners: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.shape({})])),
|
|
@@ -273,7 +317,8 @@ CollectionSummary.propTypes = {
|
|
|
273
317
|
}),
|
|
274
318
|
confirmation: _propTypes.default.shape({
|
|
275
319
|
message: _propTypes.default.string,
|
|
276
|
-
label: _propTypes.default.string
|
|
320
|
+
label: _propTypes.default.string,
|
|
321
|
+
displayFields: _propTypes.default.arrayOf(_propTypes.default.string)
|
|
277
322
|
}),
|
|
278
323
|
childCollections: _propTypes.default.arrayOf(_propTypes.default.string)
|
|
279
324
|
}).isRequired,
|
|
@@ -283,5 +283,35 @@ describe('components.CollectionSummary.CollectionSummary', function () {
|
|
|
283
283
|
var roleAttribute = confirmation.getAttribute('role');
|
|
284
284
|
expect(roleAttribute).toEqual('alert');
|
|
285
285
|
});
|
|
286
|
+
it('should correctly render field values in confirmation view', function () {
|
|
287
|
+
var listViewConfig = _objectSpread(_objectSpread({}, CONFIG), {}, {
|
|
288
|
+
card: _objectSpread(_objectSpread({}, CONFIG.card), {}, {
|
|
289
|
+
listView: true
|
|
290
|
+
}),
|
|
291
|
+
confirmation: {
|
|
292
|
+
displayFields: ['testText']
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
var _renderWithValidation9 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
|
|
296
|
+
config: listViewConfig,
|
|
297
|
+
formData: FORM_DATA,
|
|
298
|
+
onAction: ON_ACTION,
|
|
299
|
+
pages: PAGES
|
|
300
|
+
})),
|
|
301
|
+
container = _renderWithValidation9.container,
|
|
302
|
+
getByText = _renderWithValidation9.getByText;
|
|
303
|
+
var summary = checkSetup(container);
|
|
304
|
+
expect(summary.children.length).toEqual(2);
|
|
305
|
+
var card = summary.children[0];
|
|
306
|
+
var deleteButton = card.querySelector('.govuk-summary-card__actions li:last-child button');
|
|
307
|
+
_react2.fireEvent.click(deleteButton);
|
|
308
|
+
var confirmation = container.querySelector(".".concat(_Confirmation.DEFAULT_CLASS));
|
|
309
|
+
expect(confirmation).toBeTruthy();
|
|
310
|
+
listViewConfig.confirmation.displayFields.forEach(function (field) {
|
|
311
|
+
var fieldValue = FORM_DATA.testCollection[0][field];
|
|
312
|
+
var fieldElement = getByText(fieldValue);
|
|
313
|
+
expect(fieldElement).not.toBeNull();
|
|
314
|
+
});
|
|
315
|
+
});
|
|
286
316
|
});
|
|
287
317
|
});
|
|
@@ -11,4 +11,16 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
|
|
|
11
11
|
@extend .hods-button--warning;
|
|
12
12
|
margin-right: govuk-spacing(2);
|
|
13
13
|
}
|
|
14
|
+
|
|
15
|
+
.confirmation-content {
|
|
16
|
+
margin-bottom: govuk-spacing(6);
|
|
17
|
+
|
|
18
|
+
.hods-form-container .govuk-form-group {
|
|
19
|
+
margin-bottom: 0px;
|
|
20
|
+
|
|
21
|
+
label {
|
|
22
|
+
display: none;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
14
26
|
}
|
|
@@ -8,8 +8,7 @@ var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
9
|
var _react = _interopRequireDefault(require("react"));
|
|
10
10
|
var _utils = _interopRequireDefault(require("../../utils"));
|
|
11
|
-
var
|
|
12
|
-
var _Answer = _interopRequireDefault(require("../CheckYourAnswers/Answer"));
|
|
11
|
+
var _getComponentRowForCYA = _interopRequireDefault(require("../../utils/CheckYourAnswers/getComponentRowForCYA"));
|
|
13
12
|
require("./RenderListView.scss");
|
|
14
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
14
|
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); }
|
|
@@ -85,31 +84,14 @@ var RenderListView = function RenderListView(_ref) {
|
|
|
85
84
|
}).flat().filter(Boolean);
|
|
86
85
|
return (_childPage$summaryLay = childPage.summaryLayout) === null || _childPage$summaryLay === void 0 || (_childPage$summaryLay = _childPage$summaryLay.sections) === null || _childPage$summaryLay === void 0 ? void 0 : _childPage$summaryLay.flatMap(function (section) {
|
|
87
86
|
if (section.fields) {
|
|
88
|
-
|
|
89
|
-
return Object.prototype.hasOwnProperty.call(entryData, fieldId);
|
|
90
|
-
});
|
|
91
|
-
return fieldsToRender.map(function (fieldId) {
|
|
87
|
+
return section.fields.flatMap(function (fieldId) {
|
|
92
88
|
var component = elevatedComponents.find(function (comp) {
|
|
93
89
|
return comp.fieldId === fieldId;
|
|
94
90
|
});
|
|
95
91
|
if (!component) {
|
|
96
92
|
return null;
|
|
97
93
|
}
|
|
98
|
-
return
|
|
99
|
-
key: fieldId,
|
|
100
|
-
row: {
|
|
101
|
-
key: component.label,
|
|
102
|
-
value: _copReactComponents.Utils.interpolateString(entryData[component.fieldId], entryData) || /*#__PURE__*/_react.default.createElement(_Answer.default, {
|
|
103
|
-
value: entryData[component.fieldId],
|
|
104
|
-
component: component,
|
|
105
|
-
formData: component.formData
|
|
106
|
-
}),
|
|
107
|
-
required: component.required
|
|
108
|
-
},
|
|
109
|
-
classes: function classes(element) {
|
|
110
|
-
return listClass(element);
|
|
111
|
-
}
|
|
112
|
-
});
|
|
94
|
+
return (0, _getComponentRowForCYA.default)(childPage, component, listClass, entryData);
|
|
113
95
|
});
|
|
114
96
|
}
|
|
115
97
|
return null;
|
|
@@ -83,6 +83,13 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
|
|
|
83
83
|
@include govuk-media-query($until: tablet) {
|
|
84
84
|
margin-bottom: govuk-spacing(3);
|
|
85
85
|
}
|
|
86
|
+
.hods-form-container .govuk-form-group {
|
|
87
|
+
margin-bottom: 0px;
|
|
88
|
+
|
|
89
|
+
label {
|
|
90
|
+
display: none;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
86
93
|
}
|
|
87
94
|
|
|
88
95
|
.govuk-summary-list__value > p {
|
|
@@ -16,8 +16,8 @@ describe('components.CollectionSummary.RenderListView', function () {
|
|
|
16
16
|
item1: 'Value 1',
|
|
17
17
|
item2: 'Value 2',
|
|
18
18
|
item3: {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
label: 'Value 3',
|
|
20
|
+
value: 'Value 3'
|
|
21
21
|
},
|
|
22
22
|
index: 0
|
|
23
23
|
};
|
|
@@ -92,6 +92,15 @@ describe('components.CollectionSummary.RenderListView', function () {
|
|
|
92
92
|
beforeEach(function () {
|
|
93
93
|
onDeleteArgs = [];
|
|
94
94
|
});
|
|
95
|
+
var getComponentRow = function getComponentRow() {
|
|
96
|
+
return /*#__PURE__*/_react2.default.createElement("div", {
|
|
97
|
+
className: "govuk-summary-list__row"
|
|
98
|
+
}, /*#__PURE__*/_react2.default.createElement("dt", {
|
|
99
|
+
className: "govuk-summary-list__key"
|
|
100
|
+
}, "Test Key"), /*#__PURE__*/_react2.default.createElement("dd", {
|
|
101
|
+
className: "govuk-summary-list__value"
|
|
102
|
+
}, /*#__PURE__*/_react2.default.createElement("div", null, "Test Value")));
|
|
103
|
+
};
|
|
95
104
|
|
|
96
105
|
// Setup function to check rendered elements
|
|
97
106
|
var checkSetup = function checkSetup(container) {
|
|
@@ -107,7 +116,8 @@ describe('components.CollectionSummary.RenderListView', function () {
|
|
|
107
116
|
config: CONFIG,
|
|
108
117
|
onChange: ON_CHANGE,
|
|
109
118
|
onDelete: ON_DELETE,
|
|
110
|
-
masterPage: MASTER_PAGE
|
|
119
|
+
masterPage: MASTER_PAGE,
|
|
120
|
+
getComponentRow: getComponentRow
|
|
111
121
|
})),
|
|
112
122
|
container = _renderWithValidation.container;
|
|
113
123
|
var listViewDiv = checkSetup(container);
|
|
@@ -126,19 +136,19 @@ describe('components.CollectionSummary.RenderListView', function () {
|
|
|
126
136
|
var firstRowKey = rows[0].querySelector('.govuk-summary-list__key');
|
|
127
137
|
var firstRowValue = rows[0].querySelector('.govuk-summary-list__value');
|
|
128
138
|
expect(firstRowKey.textContent).toEqual('Item 1');
|
|
129
|
-
expect(firstRowValue.textContent).toEqual(
|
|
139
|
+
expect(firstRowValue.textContent).toEqual('Value 1');
|
|
130
140
|
|
|
131
141
|
// Check the second row
|
|
132
142
|
var secondRowKey = rows[1].querySelector('.govuk-summary-list__key');
|
|
133
143
|
var secondRowValue = rows[1].querySelector('.govuk-summary-list__value');
|
|
134
144
|
expect(secondRowKey.textContent).toEqual('Item 2 (optional)');
|
|
135
|
-
expect(secondRowValue.textContent).toEqual(
|
|
145
|
+
expect(secondRowValue.textContent).toEqual('Value 2');
|
|
136
146
|
|
|
137
147
|
// Check the third row
|
|
138
148
|
var thirdRowKey = rows[2].querySelector('.govuk-summary-list__key');
|
|
139
149
|
var thirdRowValue = rows[2].querySelector('.govuk-summary-list__value');
|
|
140
150
|
expect(thirdRowKey.textContent).toEqual('Item 3');
|
|
141
|
-
expect(thirdRowValue.textContent).toEqual('Value
|
|
151
|
+
expect(thirdRowValue.textContent).toEqual('Value 3');
|
|
142
152
|
});
|
|
143
153
|
it('should render the index correctly in the title', function () {
|
|
144
154
|
var _renderWithValidation2 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_RenderListView.default, {
|
|
@@ -147,7 +157,8 @@ describe('components.CollectionSummary.RenderListView', function () {
|
|
|
147
157
|
config: CONFIG,
|
|
148
158
|
onChange: ON_CHANGE,
|
|
149
159
|
onDelete: ON_DELETE,
|
|
150
|
-
masterPage: MASTER_PAGE
|
|
160
|
+
masterPage: MASTER_PAGE,
|
|
161
|
+
getComponentRow: getComponentRow
|
|
151
162
|
})),
|
|
152
163
|
container = _renderWithValidation2.container;
|
|
153
164
|
var listViewDiv = checkSetup(container);
|
|
@@ -175,7 +186,8 @@ describe('components.CollectionSummary.RenderListView', function () {
|
|
|
175
186
|
config: CONFIG,
|
|
176
187
|
onChange: ON_CHANGE,
|
|
177
188
|
onDelete: ON_DELETE,
|
|
178
|
-
masterPage: MASTER_PAGE
|
|
189
|
+
masterPage: MASTER_PAGE,
|
|
190
|
+
getComponentRow: getComponentRow
|
|
179
191
|
})),
|
|
180
192
|
container = _renderWithValidation3.container;
|
|
181
193
|
var listViewDiv = container.querySelector('.govuk-summary-card');
|
|
@@ -6,12 +6,6 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
|
|
|
6
6
|
width: 100% !important;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
.govuk-form-group:has(.hods-form-summary-card) {
|
|
10
|
-
.govuk-form-group:last-of-type {
|
|
11
|
-
margin-left: govuk-spacing(3);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
9
|
.hods-form-summary-card {
|
|
16
10
|
box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
|
|
17
11
|
border: 1px solid #E5E4E2;
|
|
@@ -88,6 +82,10 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
|
|
|
88
82
|
.details.hods-details {
|
|
89
83
|
margin-bottom: 0;
|
|
90
84
|
}
|
|
85
|
+
|
|
86
|
+
.hods-form-container .govuk-form-group label{
|
|
87
|
+
display: none;
|
|
88
|
+
}
|
|
91
89
|
}
|
|
92
90
|
}
|
|
93
91
|
|
|
@@ -7,7 +7,7 @@ exports.default = exports.DEFAULT_CLASS = void 0;
|
|
|
7
7
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
var _utils = _interopRequireDefault(require("../../utils"));
|
|
10
|
-
var
|
|
10
|
+
var _getComponentRowForCYA = _interopRequireDefault(require("../../utils/CheckYourAnswers/getComponentRowForCYA"));
|
|
11
11
|
require("./SummaryCardDetails.scss");
|
|
12
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
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; }
|
|
@@ -81,18 +81,13 @@ var SummaryCardDetails = function SummaryCardDetails(_ref) {
|
|
|
81
81
|
var component = allPageComponents.find(function (comp) {
|
|
82
82
|
return comp.fieldId === fieldId;
|
|
83
83
|
});
|
|
84
|
+
if (!component) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
84
87
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
85
88
|
key: fieldId,
|
|
86
89
|
className: classes('field')
|
|
87
|
-
},
|
|
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
|
-
}));
|
|
90
|
+
}, (0, _getComponentRowForCYA.default)(childPage, component, classes, entryData));
|
|
96
91
|
})));
|
|
97
92
|
});
|
|
98
93
|
}).filter(function (e) {
|
|
@@ -7,34 +7,44 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
.hods-form-summary-card-details {
|
|
10
|
-
&
|
|
11
|
-
|
|
10
|
+
&__row {
|
|
11
|
+
margin-left: govuk-spacing(5);
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
margin: govuk-spacing(2) 0 govuk-spacing(6) 0;
|
|
13
|
+
.hods-button-group{
|
|
14
|
+
display: none;
|
|
16
15
|
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
&__key {
|
|
19
|
+
font-weight: bold;
|
|
20
|
+
margin: govuk-spacing(2) 0 govuk-spacing(1) 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
&__value {
|
|
24
|
+
margin: 0;
|
|
25
|
+
|
|
26
|
+
.hods-form-container .govuk-form-group {
|
|
27
|
+
margin-bottom: 0px;
|
|
28
|
+
|
|
29
|
+
label {
|
|
30
|
+
display: none;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
&__section {
|
|
36
|
+
border-bottom: 2px solid #E9EBED;
|
|
17
37
|
|
|
18
38
|
&-content {
|
|
19
39
|
display: flex;
|
|
20
40
|
flex-wrap: wrap;
|
|
21
41
|
gap: govuk-spacing(2);
|
|
22
42
|
|
|
23
|
-
.hods-form-summary-
|
|
43
|
+
.hods-form-summary-card__field {
|
|
24
44
|
box-sizing: border-box;
|
|
25
45
|
margin-bottom: govuk-spacing(4);
|
|
26
46
|
|
|
27
|
-
.
|
|
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){
|
|
47
|
+
.hods-form-summary-card__row div:has(img){
|
|
38
48
|
display: flex;
|
|
39
49
|
flex-wrap: wrap;
|
|
40
50
|
|
|
@@ -313,7 +313,7 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
313
313
|
var childSectionTitles = getByTextContent(container, 'Hidden Title');
|
|
314
314
|
expect(childSectionTitles).toBeUndefined(); // Individual section title for child collections should be hidden.
|
|
315
315
|
|
|
316
|
-
var childFields = container.querySelectorAll(".".concat(classes('
|
|
317
|
-
expect(childFields.length).toEqual(
|
|
316
|
+
var childFields = container.querySelectorAll(".".concat(classes('section')));
|
|
317
|
+
expect(childFields.length).toEqual(2); // One for each entry in the child collection.
|
|
318
318
|
});
|
|
319
319
|
});
|
|
@@ -7,6 +7,7 @@ exports.default = void 0;
|
|
|
7
7
|
var _showComponent = _interopRequireDefault(require("../../../utils/Component/showComponent"));
|
|
8
8
|
var _mergeCollectionPages = _interopRequireDefault(require("../../../utils/CollectionPage/mergeCollectionPages"));
|
|
9
9
|
var _deleteNodeByPath = _interopRequireDefault(require("./deleteNodeByPath"));
|
|
10
|
+
var _optionIsSelected = _interopRequireDefault(require("../../../utils/Component/optionIsSelected"));
|
|
10
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
12
|
/* eslint-disable no-param-reassign */
|
|
12
13
|
|
|
@@ -18,6 +19,19 @@ var recurseCheckForHiddenComponents = function recurseCheckForHiddenComponents(c
|
|
|
18
19
|
(_component$components = component.components) === null || _component$components === void 0 || _component$components.forEach(function (c) {
|
|
19
20
|
recurseCheckForHiddenComponents(c, formData, path, candidateComponentForDeletion);
|
|
20
21
|
});
|
|
22
|
+
} else if ((0, _showComponent.default)(component, formData)) {
|
|
23
|
+
var _component$data;
|
|
24
|
+
if (component !== null && component !== void 0 && (_component$data = component.data) !== null && _component$data !== void 0 && _component$data.options) {
|
|
25
|
+
var _component$data2;
|
|
26
|
+
component === null || component === void 0 || (_component$data2 = component.data) === null || _component$data2 === void 0 || (_component$data2 = _component$data2.options) === null || _component$data2 === void 0 || _component$data2.forEach(function (option) {
|
|
27
|
+
if (!(0, _optionIsSelected.default)(formData[component.id], option) && option.nested) {
|
|
28
|
+
option.nested.forEach(function (nested) {
|
|
29
|
+
path = nested.fieldId;
|
|
30
|
+
candidateComponentForDeletion.set(path, component);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
21
35
|
} else if (!(0, _showComponent.default)(component, formData)) {
|
|
22
36
|
candidateComponentForDeletion.set(path, component);
|
|
23
37
|
}
|
|
@@ -56,7 +56,6 @@ var onPageAction = function onPageAction(action, patch, patchLabel, hooks, data,
|
|
|
56
56
|
_handlers.default.navigate(action, pageId, onPageChange);
|
|
57
57
|
setSubmitting(false);
|
|
58
58
|
} else {
|
|
59
|
-
var baseData = _objectSpread(_objectSpread(_objectSpread({}, data), patch), formState.page.formData);
|
|
60
59
|
var pageUpdate = function pageUpdate(next) {
|
|
61
60
|
return onPageChange(_helpers.default.getNextPageId(type, pages, pageId, action, next));
|
|
62
61
|
};
|
|
@@ -108,12 +107,14 @@ var onPageAction = function onPageAction(action, patch, patchLabel, hooks, data,
|
|
|
108
107
|
setData(submissionData);
|
|
109
108
|
}
|
|
110
109
|
;
|
|
110
|
+
var formPagesAndComponents = {
|
|
111
|
+
pages: pages,
|
|
112
|
+
components: components
|
|
113
|
+
};
|
|
111
114
|
if (action.type === _models.PageAction.TYPES.SUBMIT) {
|
|
112
|
-
_helpers.default.clearOutUncompletedRoutes(
|
|
113
|
-
pages: pages,
|
|
114
|
-
components: components
|
|
115
|
-
}, submissionData);
|
|
115
|
+
_helpers.default.clearOutUncompletedRoutes(formPagesAndComponents, submissionData);
|
|
116
116
|
}
|
|
117
|
+
|
|
117
118
|
// In case of hub-and-spoke if patchLabel has changed then
|
|
118
119
|
// save name and value to variables for call to onSubmit hook
|
|
119
120
|
var changedFieldName;
|
|
@@ -7,6 +7,7 @@ exports.default = void 0;
|
|
|
7
7
|
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
8
8
|
var _models = require("../../models");
|
|
9
9
|
var _addShowWhen = _interopRequireDefault(require("../Component/addShowWhen"));
|
|
10
|
+
var _meetsAllConditions = _interopRequireDefault(require("../Condition/meetsAllConditions"));
|
|
10
11
|
var _showFormPageCYA = _interopRequireDefault(require("../FormPage/showFormPageCYA"));
|
|
11
12
|
var _getCYACollectionDeleteAction = _interopRequireDefault(require("./getCYACollectionDeleteAction"));
|
|
12
13
|
var _getCYACollectionChangeAction = _interopRequireDefault(require("./getCYACollectionChangeAction"));
|
|
@@ -157,7 +158,7 @@ var getCYARowsForChildPages = function getCYARowsForChildPages(childPages, item,
|
|
|
157
158
|
}
|
|
158
159
|
var container = getContainerForPage(childPage, item, labelCount, fullPath);
|
|
159
160
|
var rowChangeAction = getChangeActionForPage(childPage, onAction, activeIds);
|
|
160
|
-
var containerRows = (0, _getCYARowsForContainer.default)(childPage, container, item, rowChangeAction, fnOverride);
|
|
161
|
+
var containerRows = (0, _getCYARowsForContainer.default)(childPage, container, _objectSpread(_objectSpread({}, childPage.formData), item), rowChangeAction, fnOverride);
|
|
161
162
|
rows = rows.concat(containerRows);
|
|
162
163
|
}
|
|
163
164
|
}
|
|
@@ -188,7 +189,8 @@ var getCYARowsForCollectionPage = function getCYARowsForCollectionPage(page, onA
|
|
|
188
189
|
rows.push(getCollectionNameHeading(page, collectionName));
|
|
189
190
|
}
|
|
190
191
|
var itemIndex = 0;
|
|
191
|
-
|
|
192
|
+
var result = Array.isArray(page.collection.onlyShowActiveEntryOnCYA) ? (0, _meetsAllConditions.default)(page.collection.onlyShowActiveEntryOnCYA, data) : page.collection.onlyShowActiveEntryOnCYA;
|
|
193
|
+
if (result) {
|
|
192
194
|
var activeEntry = collectionData.find(function (entry, index) {
|
|
193
195
|
itemIndex = index;
|
|
194
196
|
return entry.id === activeId;
|
|
@@ -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',
|
|
@@ -209,6 +244,50 @@ describe('utils.CheckYourAnswers.getCYARowsForCollectionPage', function () {
|
|
|
209
244
|
key: 'Test date'
|
|
210
245
|
});
|
|
211
246
|
});
|
|
247
|
+
it('should return correctly formatted rows for only the active entry when page.collection.onlyShowActiveEntryOnCYA is an array', function () {
|
|
248
|
+
var FORM_DATA = {
|
|
249
|
+
text: 'blue',
|
|
250
|
+
collectionActiveId: '02',
|
|
251
|
+
collection: [{
|
|
252
|
+
id: '01',
|
|
253
|
+
testText: 'value'
|
|
254
|
+
}, {
|
|
255
|
+
id: '02',
|
|
256
|
+
testText: 'value'
|
|
257
|
+
}]
|
|
258
|
+
};
|
|
259
|
+
var PAGE = _objectSpread(_objectSpread({}, MASTER_PAGE), {}, {
|
|
260
|
+
collection: _objectSpread(_objectSpread({}, MASTER_PAGE.collection), {}, {
|
|
261
|
+
onlyShowActiveEntryOnCYA: [{
|
|
262
|
+
field: 'text',
|
|
263
|
+
op: 'eq',
|
|
264
|
+
value: 'blue'
|
|
265
|
+
}]
|
|
266
|
+
}),
|
|
267
|
+
formData: FORM_DATA
|
|
268
|
+
});
|
|
269
|
+
var ROWS = (0, _getCYARowsForCollectionPage.default)(PAGE, null, null, FORM_DATA);
|
|
270
|
+
expect(ROWS.length).toEqual(7); // Title row + component row for only the active item.
|
|
271
|
+
expect(ROWS[0]).toMatchObject({
|
|
272
|
+
type: 'heading',
|
|
273
|
+
key: 'Collection'
|
|
274
|
+
});
|
|
275
|
+
expect(ROWS[1]).toMatchObject({
|
|
276
|
+
type: 'heading',
|
|
277
|
+
key: 'Collection entry 2'
|
|
278
|
+
});
|
|
279
|
+
expect(ROWS[2].action.label).toEqual('Change');
|
|
280
|
+
expect(ROWS[3].action.label).toEqual('custom remove label');
|
|
281
|
+
expect(ROWS[4].action.label).toEqual('custom change label');
|
|
282
|
+
expect(ROWS[5]).toMatchObject({
|
|
283
|
+
value: 'value',
|
|
284
|
+
key: 'Test text'
|
|
285
|
+
});
|
|
286
|
+
expect(ROWS[6]).toMatchObject({
|
|
287
|
+
value: '',
|
|
288
|
+
key: 'Test date'
|
|
289
|
+
});
|
|
290
|
+
});
|
|
212
291
|
it('should exclude components that should not be shown', function () {
|
|
213
292
|
var FD = {
|
|
214
293
|
collection: [{
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _Answer = _interopRequireDefault(require("../../components/CheckYourAnswers/Answer"));
|
|
9
|
+
var _SummaryListRow = _interopRequireDefault(require("../../components/SummaryList/SummaryListRow"));
|
|
10
|
+
var _getCYARow = _interopRequireDefault(require("./getCYARow"));
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
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); }
|
|
13
|
+
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; }
|
|
14
|
+
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; }
|
|
15
|
+
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
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
17
|
+
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 getComponentRowForCYA = function getComponentRowForCYA(page, component, customClasses, entryData) {
|
|
19
|
+
var modifiedPage = _objectSpread(_objectSpread({}, page), {}, {
|
|
20
|
+
formData: _objectSpread(_objectSpread({}, page.formData), entryData)
|
|
21
|
+
});
|
|
22
|
+
var row = (0, _getCYARow.default)(modifiedPage, component);
|
|
23
|
+
return /*#__PURE__*/_react.default.createElement(_SummaryListRow.default, {
|
|
24
|
+
key: "".concat(row.fieldId),
|
|
25
|
+
row: {
|
|
26
|
+
key: row.key,
|
|
27
|
+
value: /*#__PURE__*/_react.default.createElement(_Answer.default, {
|
|
28
|
+
value: row.value,
|
|
29
|
+
component: row.component,
|
|
30
|
+
formData: modifiedPage.formData
|
|
31
|
+
}),
|
|
32
|
+
required: row.required
|
|
33
|
+
},
|
|
34
|
+
classes: customClasses
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
var _default = exports.default = getComponentRowForCYA;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _getCYARowsForPage = _interopRequireDefault(require("./getCYARowsForPage"));
|
|
4
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
5
|
+
describe('utils.CheckYourAnswers.getCYARowsForPage', function () {
|
|
6
|
+
var COMPONENT_A = {
|
|
7
|
+
type: 'text',
|
|
8
|
+
id: 'a',
|
|
9
|
+
fieldId: 'a',
|
|
10
|
+
label: 'Alpha'
|
|
11
|
+
};
|
|
12
|
+
var COMPONENT_B = {
|
|
13
|
+
type: 'text',
|
|
14
|
+
id: 'b',
|
|
15
|
+
fieldId: 'b',
|
|
16
|
+
label: 'Bravo'
|
|
17
|
+
};
|
|
18
|
+
var PAGE = {
|
|
19
|
+
id: 'page',
|
|
20
|
+
components: [COMPONENT_A, COMPONENT_B],
|
|
21
|
+
formData: {
|
|
22
|
+
a: 'Alpha Value',
|
|
23
|
+
b: 'Bravo Value'
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var ON_ACTION = function ON_ACTION() {};
|
|
27
|
+
it('should get rows for a page with readonly text components', function () {
|
|
28
|
+
var rows = (0, _getCYARowsForPage.default)(PAGE, ON_ACTION);
|
|
29
|
+
expect(rows.length).toEqual(2);
|
|
30
|
+
expect(rows[0]).toEqual(expect.objectContaining({
|
|
31
|
+
fieldId: COMPONENT_A.fieldId,
|
|
32
|
+
key: COMPONENT_A.label,
|
|
33
|
+
value: 'Alpha Value'
|
|
34
|
+
}));
|
|
35
|
+
expect(rows[1]).toEqual(expect.objectContaining({
|
|
36
|
+
fieldId: COMPONENT_B.fieldId,
|
|
37
|
+
key: COMPONENT_B.label,
|
|
38
|
+
value: 'Bravo Value'
|
|
39
|
+
}));
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
/* eslint-disable no-param-reassign */
|
|
7
8
|
/**
|
|
8
9
|
* This function effectively adds a new entry to a page collection by
|
|
9
10
|
* invalidating the current active ID for that collection.
|
|
@@ -15,7 +16,8 @@ exports.default = void 0;
|
|
|
15
16
|
* @param {object} formData The top level formData object.
|
|
16
17
|
*/
|
|
17
18
|
var addCollectionPageEntry = function addCollectionPageEntry(collectionName, formData) {
|
|
18
|
-
|
|
19
|
-
formData["".concat(
|
|
19
|
+
var fieldName = collectionName.split('.').pop();
|
|
20
|
+
formData["".concat(fieldName, "ActiveId")] = '0';
|
|
21
|
+
formData["".concat(fieldName, "NumberedIndex")] = Number(formData["".concat(fieldName, "ActiveId")]) + 1;
|
|
20
22
|
};
|
|
21
23
|
var _default = exports.default = addCollectionPageEntry;
|
|
@@ -13,4 +13,24 @@ describe('Utils.CollectionPage.addCollectionPageEntry', function () {
|
|
|
13
13
|
(0, _addCollectionPageEntry.default)('parent.child.grandchild', FORM_DATA);
|
|
14
14
|
expect(FORM_DATA.grandchildActiveId).toBeTruthy();
|
|
15
15
|
});
|
|
16
|
+
it('should correctly set the active ID for a top-level collection', function () {
|
|
17
|
+
var FORM_DATA = {};
|
|
18
|
+
(0, _addCollectionPageEntry.default)('testCollection', FORM_DATA);
|
|
19
|
+
expect(FORM_DATA.testCollectionActiveId).toBe('0');
|
|
20
|
+
});
|
|
21
|
+
it('should correctly set the active ID for a nested collection', function () {
|
|
22
|
+
var FORM_DATA = {};
|
|
23
|
+
(0, _addCollectionPageEntry.default)('parent.child.grandchild', FORM_DATA);
|
|
24
|
+
expect(FORM_DATA.grandchildActiveId).toBe('0');
|
|
25
|
+
});
|
|
26
|
+
it('should correctly increment the numbered index for a top-level collection', function () {
|
|
27
|
+
var FORM_DATA = {};
|
|
28
|
+
(0, _addCollectionPageEntry.default)('testCollection', FORM_DATA);
|
|
29
|
+
expect(FORM_DATA.testCollectionNumberedIndex).toBe(1);
|
|
30
|
+
});
|
|
31
|
+
it('should correctly increment the numbered index for a nested collection', function () {
|
|
32
|
+
var FORM_DATA = {};
|
|
33
|
+
(0, _addCollectionPageEntry.default)('parent.child.grandchild', FORM_DATA);
|
|
34
|
+
expect(FORM_DATA.grandchildNumberedIndex).toBe(1);
|
|
35
|
+
});
|
|
16
36
|
});
|