@ukhomeoffice/cop-react-form-renderer 5.71.1 → 5.71.3

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.
@@ -126,6 +126,13 @@ var CollectionSummary = function CollectionSummary(_ref) {
126
126
  });
127
127
  });
128
128
  var allPagesErrors = (childPages === null || childPages === void 0 ? void 0 : childPages.flatMap(function (page) {
129
+ // Handle nested collections
130
+ if (page.childPages) {
131
+ return page.childPages.flatMap(function (nestedCollectionPage) {
132
+ var pageErrors = _utils.default.Validate.page(nestedCollectionPage);
133
+ return hooks.onValidate(nestedCollectionPage, pageErrors);
134
+ });
135
+ }
129
136
  var pageErrors = _utils.default.Validate.page(page);
130
137
  return hooks.onValidate(page, pageErrors);
131
138
  })) || [];
@@ -92,13 +92,65 @@ describe('components.CollectionSummary.CollectionSummary', function () {
92
92
  expect(errorChecker.textContent).toContain('queuedErrors is an array of length 1');
93
93
  expect(errorChecker.textContent).toContain('testText is required');
94
94
  });
95
+ it('should correctly queue errors found when validating entries with nested collections', function () {
96
+ var FORM_DATA_NESTED = {
97
+ testCollection: [{
98
+ testDate: 'hello',
99
+ child: [{
100
+ randomField: 'hello'
101
+ }]
102
+ }]
103
+ };
104
+ var PAGES_NESTED = [{
105
+ id: 'page1',
106
+ collection: {
107
+ name: 'testCollection'
108
+ },
109
+ components: [{
110
+ id: 'testDate',
111
+ fieldId: 'testDate',
112
+ type: 'date'
113
+ }],
114
+ formData: FORM_DATA_NESTED
115
+ }, {
116
+ id: 'page2',
117
+ collection: {
118
+ name: 'testCollection.child'
119
+ },
120
+ components: [{
121
+ id: 'testText',
122
+ label: 'Nested Field',
123
+ fieldId: 'testText',
124
+ type: 'text',
125
+ required: true
126
+ }],
127
+ formData: FORM_DATA_NESTED
128
+ }];
129
+ var ErrorCheckComponent = function ErrorCheckComponent() {
130
+ var _useValidation2 = (0, _hooks.useValidation)(),
131
+ queuedErrors = _useValidation2.queuedErrors;
132
+ return /*#__PURE__*/_react.default.createElement("div", null, Array.isArray(queuedErrors) && "queuedErrors is an array of length ".concat(queuedErrors.length), (queuedErrors === null || queuedErrors === void 0 ? void 0 : queuedErrors.length) > 0 && queuedErrors.map(function (e) {
133
+ return e.error;
134
+ }));
135
+ };
136
+ var _renderWithValidation3 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(ErrorCheckComponent, null), /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
137
+ config: CONFIG,
138
+ formData: FORM_DATA_NESTED,
139
+ onAction: ON_ACTION,
140
+ pages: PAGES_NESTED
141
+ }))),
142
+ container = _renderWithValidation3.container;
143
+ var errorChecker = container.children[0];
144
+ expect(errorChecker.textContent).toContain('queuedErrors is an array of length 1');
145
+ expect(errorChecker.textContent).toContain('Nested Field is required');
146
+ });
95
147
  it('should render a confirmation when a SummaryCard\'s delete button is pressed', function () {
96
- var _renderWithValidation3 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
148
+ var _renderWithValidation4 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
97
149
  config: CONFIG,
98
150
  formData: FORM_DATA,
99
151
  onAction: ON_ACTION
100
152
  })),
101
- container = _renderWithValidation3.container;
153
+ container = _renderWithValidation4.container;
102
154
  var summary = checkSetup(container);
103
155
  expect(summary.children.length).toEqual(2);
104
156
  var card = summary.children[0];
@@ -122,12 +174,12 @@ describe('components.CollectionSummary.CollectionSummary', function () {
122
174
  title: 'Title'
123
175
  }
124
176
  };
125
- var _renderWithValidation4 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
177
+ var _renderWithValidation5 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
126
178
  config: CONFIG_WITH_BUTTON,
127
179
  formData: FORM_DATA,
128
180
  onAction: ON_ACTION
129
181
  })),
130
- container = _renderWithValidation4.container;
182
+ container = _renderWithValidation5.container;
131
183
  var summary = checkSetup(container);
132
184
  expect(summary.children.length).toEqual(3); // The button and a card for each item.
133
185
  expect(summary.children[0].id).toEqual("".concat(CONFIG_WITH_BUTTON.fieldId, ".addButton"));
@@ -146,12 +198,12 @@ describe('components.CollectionSummary.CollectionSummary', function () {
146
198
  title: 'Title'
147
199
  }
148
200
  };
149
- var _renderWithValidation5 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
201
+ var _renderWithValidation6 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
150
202
  config: CONFIG_WITH_BUTTON,
151
203
  formData: FORM_DATA,
152
204
  onAction: ON_ACTION
153
205
  })),
154
- container = _renderWithValidation5.container;
206
+ container = _renderWithValidation6.container;
155
207
  var summary = checkSetup(container);
156
208
  expect(summary.children.length).toEqual(3); // The button and a card for each item.
157
209
  expect(summary.children[0].id).toEqual("".concat(CONFIG_WITH_BUTTON.fieldId, ".addButton"));
@@ -159,12 +211,12 @@ describe('components.CollectionSummary.CollectionSummary', function () {
159
211
  expect(summary.children[0].tagName).toEqual('BUTTON');
160
212
  });
161
213
  it('should apply the expected class name to the summary card when delete button is pressed', function () {
162
- var _renderWithValidation6 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
214
+ var _renderWithValidation7 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
163
215
  config: CONFIG,
164
216
  formData: FORM_DATA,
165
217
  onAction: ON_ACTION
166
218
  })),
167
- container = _renderWithValidation6.container;
219
+ container = _renderWithValidation7.container;
168
220
  var summary = checkSetup(container);
169
221
  expect(summary.children.length).toEqual(2);
170
222
  var card = summary.children[0];
@@ -175,12 +227,12 @@ describe('components.CollectionSummary.CollectionSummary', function () {
175
227
  expect(card.className).toContain('deleting-summary-card');
176
228
  });
177
229
  it('should focus on the delete button in the confirmation panel', function () {
178
- var _renderWithValidation7 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
230
+ var _renderWithValidation8 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
179
231
  config: CONFIG,
180
232
  formData: FORM_DATA,
181
233
  onAction: ON_ACTION
182
234
  })),
183
- container = _renderWithValidation7.container;
235
+ container = _renderWithValidation8.container;
184
236
  var summary = checkSetup(container);
185
237
  expect(summary.children.length).toEqual(2);
186
238
  var card = summary.children[0];
@@ -191,12 +243,12 @@ describe('components.CollectionSummary.CollectionSummary', function () {
191
243
  expect(document.activeElement).toEqual(confirmButton);
192
244
  });
193
245
  it('should have the role "alert" in the confirmation panel', function () {
194
- var _renderWithValidation8 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
246
+ var _renderWithValidation9 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
195
247
  config: CONFIG,
196
248
  formData: FORM_DATA,
197
249
  onAction: ON_ACTION
198
250
  })),
199
- container = _renderWithValidation8.container;
251
+ container = _renderWithValidation9.container;
200
252
  var summary = checkSetup(container);
201
253
  expect(summary.children.length).toEqual(2);
202
254
  var card = summary.children[0];
@@ -216,14 +268,14 @@ describe('components.CollectionSummary.CollectionSummary', function () {
216
268
  displayFields: ['testText']
217
269
  }
218
270
  });
219
- var _renderWithValidation9 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
271
+ var _renderWithValidation10 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
220
272
  config: listViewConfig,
221
273
  formData: FORM_DATA,
222
274
  onAction: ON_ACTION,
223
275
  pages: PAGES
224
276
  })),
225
- container = _renderWithValidation9.container,
226
- getByText = _renderWithValidation9.getByText;
277
+ container = _renderWithValidation10.container,
278
+ getByText = _renderWithValidation10.getByText;
227
279
  var summary = checkSetup(container);
228
280
  expect(summary.children.length).toEqual(2);
229
281
  var card = summary.children[0];
@@ -248,14 +300,14 @@ describe('components.CollectionSummary.CollectionSummary', function () {
248
300
  message: 'Test confirmation message with index number ${index}'
249
301
  }
250
302
  });
251
- var _renderWithValidation10 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
303
+ var _renderWithValidation11 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
252
304
  config: listViewConfig,
253
305
  formData: FORM_DATA,
254
306
  onAction: ON_ACTION,
255
307
  pages: PAGES
256
308
  })),
257
- container = _renderWithValidation10.container,
258
- getByText = _renderWithValidation10.getByText;
309
+ container = _renderWithValidation11.container,
310
+ getByText = _renderWithValidation11.getByText;
259
311
  var summary = checkSetup(container);
260
312
  expect(summary.children.length).toEqual(2);
261
313
  var card = summary.children[0];
@@ -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 _renderWithValidation5 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
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 = _renderWithValidation5.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 _renderWithValidation6 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
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 = _renderWithValidation6.container;
451
+ container = _renderWithValidation7.container;
393
452
 
394
453
  // Function to find an element by its text content
395
454
  function getByTextContent(parent, text) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "5.71.1",
3
+ "version": "5.71.3",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",