@ukhomeoffice/cop-react-form-renderer 5.58.1 → 5.59.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -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"));
|
|
@@ -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;
|
|
@@ -244,6 +244,50 @@ describe('utils.CheckYourAnswers.getCYARowsForCollectionPage', function () {
|
|
|
244
244
|
key: 'Test date'
|
|
245
245
|
});
|
|
246
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
|
+
});
|
|
247
291
|
it('should exclude components that should not be shown', function () {
|
|
248
292
|
var FD = {
|
|
249
293
|
collection: [{
|