@ukhomeoffice/cop-react-form-renderer 5.71.1 → 5.71.2
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.
|
@@ -10,6 +10,7 @@ var _utils = _interopRequireDefault(require("../../utils"));
|
|
|
10
10
|
var _models = require("../../models");
|
|
11
11
|
var _getComponentRowForCYA = _interopRequireDefault(require("../../utils/CheckYourAnswers/getComponentRowForCYA"));
|
|
12
12
|
var _getCYARowsForContainer = _interopRequireDefault(require("../../utils/CheckYourAnswers/getCYARowsForContainer"));
|
|
13
|
+
var _showComponent = _interopRequireDefault(require("../../utils/Component/showComponent"));
|
|
13
14
|
require("./SummaryCardDetails.scss");
|
|
14
15
|
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); }
|
|
15
16
|
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; }
|
|
@@ -51,7 +52,7 @@ var SummaryCardDetails = function SummaryCardDetails(_ref) {
|
|
|
51
52
|
var component = components.find(function (comp) {
|
|
52
53
|
return comp.fieldId === fieldId;
|
|
53
54
|
});
|
|
54
|
-
if (!component) {
|
|
55
|
+
if (!component || !(0, _showComponent.default)(component, _objectSpread(_objectSpread({}, childPage.formData), entryData))) {
|
|
55
56
|
return null;
|
|
56
57
|
}
|
|
57
58
|
if (component.type === _models.ComponentTypes.CONTAINER) {
|
|
@@ -276,6 +276,65 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
276
276
|
var section2Content = section2Title.parentNode.querySelector(".".concat(classes('section-content')));
|
|
277
277
|
expect(section2Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(1);
|
|
278
278
|
});
|
|
279
|
+
it('should not render components that fail show_when checks', function () {
|
|
280
|
+
var CHILD_PAGES = [{
|
|
281
|
+
summaryLayout: {
|
|
282
|
+
sections: [{
|
|
283
|
+
title: 'Section 1',
|
|
284
|
+
columns: [{
|
|
285
|
+
fields: ['fieldA']
|
|
286
|
+
}, {
|
|
287
|
+
fields: ['fieldB']
|
|
288
|
+
}]
|
|
289
|
+
}, {
|
|
290
|
+
title: 'Section 2',
|
|
291
|
+
columns: [{
|
|
292
|
+
fields: ['fieldC']
|
|
293
|
+
}]
|
|
294
|
+
}]
|
|
295
|
+
},
|
|
296
|
+
components: [{
|
|
297
|
+
fieldId: 'fieldA'
|
|
298
|
+
}, {
|
|
299
|
+
fieldId: 'fieldB',
|
|
300
|
+
show_when: [{
|
|
301
|
+
field: 'fieldA',
|
|
302
|
+
op: '=',
|
|
303
|
+
value: 'notTheRightValue'
|
|
304
|
+
}]
|
|
305
|
+
}, {
|
|
306
|
+
fieldId: 'fieldC'
|
|
307
|
+
}]
|
|
308
|
+
}];
|
|
309
|
+
var MASTER_PAGE = {
|
|
310
|
+
childPages: CHILD_PAGES
|
|
311
|
+
};
|
|
312
|
+
var _renderWithValidation5 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
|
|
313
|
+
masterPage: MASTER_PAGE,
|
|
314
|
+
childMasterPages: [],
|
|
315
|
+
formData: {},
|
|
316
|
+
entryData: ENTRY
|
|
317
|
+
})),
|
|
318
|
+
container = _renderWithValidation5.container;
|
|
319
|
+
|
|
320
|
+
// Function to find an element by its text content
|
|
321
|
+
function getByTextContent(parent, text) {
|
|
322
|
+
return Array.from(parent.getElementsByClassName(classes('section-title'))).find(function (el) {
|
|
323
|
+
return el.textContent === text;
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// Check for section titles
|
|
328
|
+
var section1Title = getByTextContent(container, 'Section 1');
|
|
329
|
+
var section2Title = getByTextContent(container, 'Section 2');
|
|
330
|
+
expect(section1Title).not.toBeUndefined();
|
|
331
|
+
expect(section2Title).not.toBeUndefined();
|
|
332
|
+
var section1Content = section1Title.parentNode.querySelector(".".concat(classes('section-content')));
|
|
333
|
+
expect(section1Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(1); // Just Field A, Field B should be hidden.
|
|
334
|
+
|
|
335
|
+
var section2Content = section2Title.parentNode.querySelector(".".concat(classes('section-content')));
|
|
336
|
+
expect(section2Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(1);
|
|
337
|
+
});
|
|
279
338
|
it('should not render sections on pages that fail show_when checks', function () {
|
|
280
339
|
var CHILD_PAGES = [{
|
|
281
340
|
show_when: [{
|
|
@@ -317,7 +376,7 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
317
376
|
var CUSTOM_ENTRY = _objectSpread(_objectSpread({}, ENTRY), {}, {
|
|
318
377
|
showSection1: false
|
|
319
378
|
});
|
|
320
|
-
var
|
|
379
|
+
var _renderWithValidation6 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
|
|
321
380
|
masterPage: MASTER_PAGE,
|
|
322
381
|
childMasterPages: [],
|
|
323
382
|
formData: {
|
|
@@ -325,7 +384,7 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
325
384
|
},
|
|
326
385
|
entryData: CUSTOM_ENTRY
|
|
327
386
|
})),
|
|
328
|
-
container =
|
|
387
|
+
container = _renderWithValidation6.container;
|
|
329
388
|
|
|
330
389
|
// Function to find an element by its text content
|
|
331
390
|
function getByTextContent(parent, text) {
|
|
@@ -383,13 +442,13 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
383
442
|
childPages: [].concat(CHILD_PAGES, CHILD_MASTER_PAGES)
|
|
384
443
|
};
|
|
385
444
|
var CHILD_COLLECTIONS = ['childCollection'];
|
|
386
|
-
var
|
|
445
|
+
var _renderWithValidation7 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
|
|
387
446
|
masterPage: MASTER_PAGE,
|
|
388
447
|
childCollections: CHILD_COLLECTIONS,
|
|
389
448
|
formData: {},
|
|
390
449
|
entryData: ENTRY
|
|
391
450
|
})),
|
|
392
|
-
container =
|
|
451
|
+
container = _renderWithValidation7.container;
|
|
393
452
|
|
|
394
453
|
// Function to find an element by its text content
|
|
395
454
|
function getByTextContent(parent, text) {
|