@ukhomeoffice/cop-react-form-renderer 5.62.1 → 5.62.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.
@@ -219,7 +219,10 @@ SummaryCard.propTypes = {
219
219
  }).isRequired,
220
220
  config: _propTypes.default.shape({
221
221
  banners: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.shape({})])),
222
- title: _propTypes.default.string,
222
+ title: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.PropTypes.arrayOf(_propTypes.default.shape({
223
+ title: _propTypes.default.string,
224
+ show_when: _propTypes.default.arrayOf({})
225
+ }))]),
223
226
  details: _propTypes.default.string,
224
227
  changeAction: _propTypes.default.shape({
225
228
  label: _propTypes.default.string,
@@ -7,7 +7,9 @@ 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 _models = require("../../models");
10
11
  var _getComponentRowForCYA = _interopRequireDefault(require("../../utils/CheckYourAnswers/getComponentRowForCYA"));
12
+ var _getCYARowsForContainer = _interopRequireDefault(require("../../utils/CheckYourAnswers/getCYARowsForContainer"));
11
13
  require("./SummaryCardDetails.scss");
12
14
  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
15
  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; }
@@ -84,6 +86,20 @@ var SummaryCardDetails = function SummaryCardDetails(_ref) {
84
86
  if (!component) {
85
87
  return null;
86
88
  }
89
+ if (component.type === _models.ComponentTypes.CONTAINER) {
90
+ var containerRows = (0, _getCYARowsForContainer.default)(childPage, component, entryData);
91
+ return /*#__PURE__*/_react.default.createElement("div", {
92
+ key: fieldId,
93
+ className: classes('field')
94
+ }, containerRows.map(function (subComponent) {
95
+ var _entryData$component$;
96
+ // Put value for current subcomponent at top level
97
+ var modEntry = _objectSpread(_objectSpread({}, entryData), _defineProperty({}, subComponent.fieldId, (_entryData$component$ = entryData[component.fieldId]) === null || _entryData$component$ === void 0 ? void 0 : _entryData$component$[subComponent.fieldId]));
98
+ return (0, _getComponentRowForCYA.default)(childPage, _objectSpread(_objectSpread({}, subComponent), {
99
+ label: subComponent.key
100
+ }), classes, modEntry);
101
+ }));
102
+ }
87
103
  return /*#__PURE__*/_react.default.createElement("div", {
88
104
  key: fieldId,
89
105
  className: classes('field')
@@ -82,6 +82,75 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
82
82
  var section2Content = section2Title.parentNode.querySelector(".".concat(classes('section-content')));
83
83
  expect(section2Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(1);
84
84
  });
85
+ it('should render sections containing containers based on summaryLayout config', function () {
86
+ var CHILD_PAGES = [{
87
+ summaryLayout: {
88
+ sections: [{
89
+ title: 'Section 1',
90
+ columns: 1,
91
+ fields: ['containerComponent']
92
+ }]
93
+ },
94
+ components: [{
95
+ fieldId: 'containerComponent',
96
+ type: 'container',
97
+ label: 'container',
98
+ components: [{
99
+ fieldId: 'subOne',
100
+ label: 'subOneLabel'
101
+ }, {
102
+ fieldId: 'subTwo',
103
+ label: 'subTwoLabel'
104
+ }, {
105
+ fieldId: 'subThree',
106
+ label: 'subThreeLabel'
107
+ }]
108
+ }]
109
+ }];
110
+ var CONTAINER_ENTRY = {
111
+ id: '001',
112
+ bannerText: 'A banner',
113
+ titleText: 'A title',
114
+ detailsText: 'Some details',
115
+ index: 0,
116
+ summaryText: 'Full details',
117
+ containerComponent: {
118
+ subOne: 'alpha',
119
+ subTwo: 'bravo',
120
+ subThree: 'charlie'
121
+ }
122
+ };
123
+ var MASTER_PAGE = {
124
+ childPages: CHILD_PAGES
125
+ };
126
+ var _renderWithValidation2 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
127
+ masterPage: MASTER_PAGE,
128
+ childMasterPages: [],
129
+ formData: {},
130
+ entryData: CONTAINER_ENTRY
131
+ })),
132
+ container = _renderWithValidation2.container;
133
+
134
+ // Function to find an element by its text content
135
+ function getByTextContent(parent, text) {
136
+ return Array.from(parent.getElementsByClassName(classes('section-title'))).find(function (el) {
137
+ return el.textContent === text;
138
+ });
139
+ }
140
+
141
+ // Check for section title
142
+ var section1Title = getByTextContent(container, 'Section 1');
143
+ expect(section1Title).not.toBeUndefined();
144
+
145
+ // All three subcomponents from the container should have labels and values displayed
146
+ var section1Content = section1Title.parentNode.querySelector(".".concat(classes('section-content')));
147
+ expect(section1Content.textContent).toContain('subOneLabel');
148
+ expect(section1Content.textContent).toContain('alpha');
149
+ expect(section1Content.textContent).toContain('subTwoLabel');
150
+ expect(section1Content.textContent).toContain('bravo');
151
+ expect(section1Content.textContent).toContain('subThreeLabel');
152
+ expect(section1Content.textContent).toContain('charlie');
153
+ });
85
154
  it('should render sections if they have show_when checks and pass them', function () {
86
155
  var CHILD_PAGES = [{
87
156
  summaryLayout: {
@@ -114,13 +183,13 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
114
183
  var CUSTOM_ENTRY = _objectSpread(_objectSpread({}, ENTRY), {}, {
115
184
  showSection1: true
116
185
  });
117
- var _renderWithValidation2 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
186
+ var _renderWithValidation3 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
118
187
  masterPage: MASTER_PAGE,
119
188
  childMasterPages: [],
120
189
  formData: {},
121
190
  entryData: CUSTOM_ENTRY
122
191
  })),
123
- container = _renderWithValidation2.container;
192
+ container = _renderWithValidation3.container;
124
193
 
125
194
  // Function to find an element by its text content
126
195
  function getByTextContent(parent, text) {
@@ -171,13 +240,13 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
171
240
  var CUSTOM_ENTRY = _objectSpread(_objectSpread({}, ENTRY), {}, {
172
241
  showSection1: false
173
242
  });
174
- var _renderWithValidation3 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
243
+ var _renderWithValidation4 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
175
244
  masterPage: MASTER_PAGE,
176
245
  childMasterPages: [],
177
246
  formData: {},
178
247
  entryData: CUSTOM_ENTRY
179
248
  })),
180
- container = _renderWithValidation3.container;
249
+ container = _renderWithValidation4.container;
181
250
 
182
251
  // Function to find an element by its text content
183
252
  function getByTextContent(parent, text) {
@@ -231,7 +300,7 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
231
300
  var CUSTOM_ENTRY = _objectSpread(_objectSpread({}, ENTRY), {}, {
232
301
  showSection1: false
233
302
  });
234
- var _renderWithValidation4 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
303
+ var _renderWithValidation5 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
235
304
  masterPage: MASTER_PAGE,
236
305
  childMasterPages: [],
237
306
  formData: {
@@ -239,7 +308,7 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
239
308
  },
240
309
  entryData: CUSTOM_ENTRY
241
310
  })),
242
- container = _renderWithValidation4.container;
311
+ container = _renderWithValidation5.container;
243
312
 
244
313
  // Function to find an element by its text content
245
314
  function getByTextContent(parent, text) {
@@ -294,13 +363,13 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
294
363
  childPages: [].concat(CHILD_PAGES, CHILD_MASTER_PAGES)
295
364
  };
296
365
  var CHILD_COLLECTIONS = ['childCollection'];
297
- var _renderWithValidation5 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
366
+ var _renderWithValidation6 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
298
367
  masterPage: MASTER_PAGE,
299
368
  childCollections: CHILD_COLLECTIONS,
300
369
  formData: {},
301
370
  entryData: ENTRY
302
371
  })),
303
- container = _renderWithValidation5.container;
372
+ container = _renderWithValidation6.container;
304
373
 
305
374
  // Function to find an element by its text content
306
375
  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.62.1",
3
+ "version": "5.62.2",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",