@ukhomeoffice/cop-react-form-renderer 2.6.2 → 2.7.1

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.
@@ -22,6 +22,8 @@ var _userProfileData = _interopRequireDefault(require("../../json/userProfile.da
22
22
 
23
23
  var _userProfile = _interopRequireDefault(require("../../json/userProfile.json"));
24
24
 
25
+ var _groupOfRow = _interopRequireDefault(require("../../json/groupOfRow.json"));
26
+
25
27
  var _utils = _interopRequireDefault(require("../../utils"));
26
28
 
27
29
  var _CheckYourAnswers = _interopRequireWildcard(require("./CheckYourAnswers"));
@@ -198,7 +200,7 @@ describe('components', function () {
198
200
  }, _callee4);
199
201
  })));
200
202
  it('should show readonly page components correctly', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() {
201
- var cya, _cya$childNodes, names, _names$childNodes, firstName, surname;
203
+ var cya, _cya$childNodes, cyaChildNode, names, _names$childNodes, firstName, surname;
202
204
 
203
205
  return regeneratorRuntime.wrap(function _callee6$(_context6) {
204
206
  while (1) {
@@ -226,14 +228,15 @@ describe('components', function () {
226
228
 
227
229
  case 2:
228
230
  cya = checkCYA(container);
229
- _cya$childNodes = _slicedToArray(cya.childNodes, 2), names = _cya$childNodes[1];
231
+ _cya$childNodes = _slicedToArray(cya.childNodes, 2), cyaChildNode = _cya$childNodes[1];
232
+ names = cyaChildNode.childNodes[0];
230
233
  expect(names.tagName).toEqual('DL');
231
234
  expect(names.classList).toContain("govuk-!-margin-bottom-".concat(_CheckYourAnswers.DEFAULT_MARGIN_BOTTOM));
232
235
  _names$childNodes = _slicedToArray(names.childNodes, 2), firstName = _names$childNodes[0], surname = _names$childNodes[1];
233
236
  checkRow(firstName, 'First name', 'John', false);
234
237
  checkRow(surname, 'Last name', 'Smith', false);
235
238
 
236
- case 9:
239
+ case 10:
237
240
  case "end":
238
241
  return _context6.stop();
239
242
  }
@@ -241,7 +244,7 @@ describe('components', function () {
241
244
  }, _callee6);
242
245
  })));
243
246
  it('should show editable page components correctly', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8() {
244
- var cya, _cya$childNodes2, title, civilServant, _civilServant$childNo, status;
247
+ var cya, _cya$childNodes2, title, cyaChildNode, civilServant, _civilServant$childNo, status;
245
248
 
246
249
  return regeneratorRuntime.wrap(function _callee8$(_context8) {
247
250
  while (1) {
@@ -269,14 +272,15 @@ describe('components', function () {
269
272
 
270
273
  case 2:
271
274
  cya = checkCYA(container);
272
- _cya$childNodes2 = _slicedToArray(cya.childNodes, 4), title = _cya$childNodes2[2], civilServant = _cya$childNodes2[3];
275
+ _cya$childNodes2 = _slicedToArray(cya.childNodes, 4), title = _cya$childNodes2[2], cyaChildNode = _cya$childNodes2[3];
276
+ civilServant = cyaChildNode.childNodes[0];
273
277
  expect(title.textContent).toEqual('Are you a civil servant?');
274
278
  expect(civilServant.tagName).toEqual('DL');
275
279
  expect(civilServant.classList).toContain("govuk-!-margin-bottom-".concat(_CheckYourAnswers.DEFAULT_MARGIN_BOTTOM));
276
280
  _civilServant$childNo = _slicedToArray(civilServant.childNodes, 1), status = _civilServant$childNo[0];
277
281
  checkRow(status, 'Are you a civil servant?', 'Yes', true);
278
282
 
279
- case 9:
283
+ case 10:
280
284
  case "end":
281
285
  return _context8.stop();
282
286
  }
@@ -284,7 +288,7 @@ describe('components', function () {
284
288
  }, _callee8);
285
289
  })));
286
290
  it('should show editable page components correctly with page titles hidden', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee10() {
287
- var cya, _cya$childNodes3, civilServant, _civilServant$childNo2, status;
291
+ var cya, _cya$childNodes3, cyaChildNode, civilServant, _civilServant$childNo2, status;
288
292
 
289
293
  return regeneratorRuntime.wrap(function _callee10$(_context10) {
290
294
  while (1) {
@@ -313,15 +317,16 @@ describe('components', function () {
313
317
 
314
318
  case 2:
315
319
  cya = checkCYA(container);
316
- _cya$childNodes3 = _slicedToArray(cya.childNodes, 3), civilServant = _cya$childNodes3[2]; // The title simply isn't returned
320
+ _cya$childNodes3 = _slicedToArray(cya.childNodes, 3), cyaChildNode = _cya$childNodes3[2]; // The title simply isn't returned
317
321
 
322
+ civilServant = cyaChildNode.childNodes[0];
318
323
  expect(civilServant.tagName).toEqual('DL');
319
324
  expect(civilServant.classList).toContain("govuk-!-margin-bottom-0"); // Changed margin if no titles
320
325
 
321
326
  _civilServant$childNo2 = _slicedToArray(civilServant.childNodes, 1), status = _civilServant$childNo2[0];
322
327
  checkRow(status, 'Are you a civil servant?', 'Yes', true);
323
328
 
324
- case 8:
329
+ case 9:
325
330
  case "end":
326
331
  return _context10.stop();
327
332
  }
@@ -329,7 +334,7 @@ describe('components', function () {
329
334
  }, _callee10);
330
335
  })));
331
336
  it('should show no title if is set to hidden', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee12() {
332
- var cya, _cya$childNodes4, names, _names$childNodes2, firstName, surname;
337
+ var cya, _cya$childNodes4, cyaChildNode, names, _names$childNodes2, firstName, surname;
333
338
 
334
339
  return regeneratorRuntime.wrap(function _callee12$(_context12) {
335
340
  while (1) {
@@ -358,19 +363,76 @@ describe('components', function () {
358
363
 
359
364
  case 2:
360
365
  cya = checkCYA(container);
361
- _cya$childNodes4 = _slicedToArray(cya.childNodes, 1), names = _cya$childNodes4[0];
366
+ _cya$childNodes4 = _slicedToArray(cya.childNodes, 1), cyaChildNode = _cya$childNodes4[0];
367
+ names = cyaChildNode.childNodes[0];
362
368
  expect(names.tagName).toEqual('DL');
363
369
  expect(names.classList).toContain("govuk-!-margin-bottom-".concat(_CheckYourAnswers.DEFAULT_MARGIN_BOTTOM));
364
370
  _names$childNodes2 = _slicedToArray(names.childNodes, 2), firstName = _names$childNodes2[0], surname = _names$childNodes2[1];
365
371
  checkRow(firstName, 'First name', 'John', false);
366
372
  checkRow(surname, 'Last name', 'Smith', false);
367
373
 
368
- case 9:
374
+ case 10:
369
375
  case "end":
370
376
  return _context12.stop();
371
377
  }
372
378
  }
373
379
  }, _callee12);
374
380
  })));
381
+ it('should render a group with one action button', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee14() {
382
+ var GROUP_PAGES, cya, namesGroup, firstNameRow, surname, changeButtonDiv, changeButton;
383
+ return regeneratorRuntime.wrap(function _callee14$(_context14) {
384
+ while (1) {
385
+ switch (_context14.prev = _context14.next) {
386
+ case 0:
387
+ GROUP_PAGES = _utils.default.FormPage.getAll(_groupOfRow.default.pages, _groupOfRow.default.components, _objectSpread({}, DATA));
388
+ _context14.next = 3;
389
+ return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee13() {
390
+ return regeneratorRuntime.wrap(function _callee13$(_context13) {
391
+ while (1) {
392
+ switch (_context13.prev = _context13.next) {
393
+ case 0:
394
+ (0, _reactDom.render)( /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, {
395
+ pages: GROUP_PAGES,
396
+ onRowAction: ON_ROW_ACTION,
397
+ onAction: ON_ACTION,
398
+ groups: _groupOfRow.default.cya.groups
399
+ }), container);
400
+
401
+ case 1:
402
+ case "end":
403
+ return _context13.stop();
404
+ }
405
+ }
406
+ }, _callee13);
407
+ })));
408
+
409
+ case 3:
410
+ cya = checkCYA(container);
411
+ namesGroup = cya.childNodes[2];
412
+ firstNameRow = namesGroup.childNodes[0].childNodes[0];
413
+ expect(firstNameRow.childNodes.length).toEqual(2);
414
+ expect(firstNameRow.childNodes[0].textContent).toEqual('First name (optional)');
415
+ expect(firstNameRow.childNodes[0].tagName).toEqual('DT');
416
+ expect(firstNameRow.childNodes[1].textContent).toEqual('John');
417
+ expect(firstNameRow.childNodes[1].tagName).toEqual('DD');
418
+ surname = namesGroup.childNodes[0].childNodes[1];
419
+ expect(surname.childNodes.length).toEqual(2);
420
+ expect(surname.childNodes[0].textContent).toEqual('Last name (optional)');
421
+ expect(surname.childNodes[0].tagName).toEqual('DT');
422
+ expect(surname.childNodes[1].textContent).toEqual('Smith');
423
+ expect(surname.childNodes[1].tagName).toEqual('DD');
424
+ changeButtonDiv = namesGroup.childNodes[0].childNodes[2];
425
+ expect(changeButtonDiv.classList).toContain('change-group-button');
426
+ changeButton = changeButtonDiv.childNodes[0];
427
+ expect(changeButton.tagName).toEqual('A');
428
+ expect(changeButton.textContent).toEqual('Change names');
429
+
430
+ case 22:
431
+ case "end":
432
+ return _context14.stop();
433
+ }
434
+ }
435
+ }, _callee14);
436
+ })));
375
437
  });
376
438
  });
@@ -89,7 +89,7 @@ describe('components', function () {
89
89
  };
90
90
 
91
91
  var getChangeLink = function getChangeLink(summaryList) {
92
- var _summaryList$childNod = _slicedToArray(summaryList.childNodes[0].childNodes, 3),
92
+ var _summaryList$childNod = _slicedToArray(summaryList.childNodes[0].childNodes[0].childNodes, 3),
93
93
  actions = _summaryList$childNod[2];
94
94
 
95
95
  return actions.childNodes[0];
@@ -22,7 +22,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
22
22
  */
23
23
  var canActionProceed = function canActionProceed(action, page, onError) {
24
24
  if (action.validate) {
25
- var errors = _utils.default.Validate.page(page.components, page.formData);
25
+ var errors = _utils.default.Validate.page(page);
26
26
 
27
27
  onError(errors);
28
28
  return errors.length === 0;
@@ -32,7 +32,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
32
32
  var canCYASubmit = function canCYASubmit(pages, onError) {
33
33
  var errors = [];
34
34
  pages.forEach(function (p) {
35
- errors.push.apply(errors, _toConsumableArray(_utils.default.Validate.page(p.components, p.formData)));
35
+ errors.push.apply(errors, _toConsumableArray(_utils.default.Validate.page(p)));
36
36
  });
37
37
  onError(errors);
38
38
  return errors.length === 0;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _react = _interopRequireWildcard(require("react"));
11
+
12
+ var _copReactComponents = require("@ukhomeoffice/cop-react-components");
13
+
14
+ var _propTypes = _interopRequireDefault(require("prop-types"));
15
+
16
+ var _getGroupActionAttributes = _interopRequireDefault(require("./helpers/getGroupActionAttributes"));
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
20
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
21
+
22
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
+
24
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
25
+
26
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
27
+
28
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
29
+
30
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
31
+
32
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
33
+
34
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
35
+
36
+ var GroupAction = function GroupAction(_ref) {
37
+ var group = _ref.group;
38
+
39
+ var _useState = (0, _react.useState)({}),
40
+ _useState2 = _slicedToArray(_useState, 2),
41
+ attrs = _useState2[0],
42
+ setAttrs = _useState2[1];
43
+
44
+ (0, _react.useEffect)(function () {
45
+ setAttrs((0, _getGroupActionAttributes.default)(group));
46
+ }, [group, setAttrs]);
47
+
48
+ if (!group.action) {
49
+ return null;
50
+ }
51
+
52
+ return /*#__PURE__*/_react.default.createElement(_copReactComponents.Link, attrs, group.action.label, group.action.aria_suffix && /*#__PURE__*/_react.default.createElement("span", {
53
+ className: "mobile-text govuk-link"
54
+ }, ' ', "".concat(group.action.aria_suffix)));
55
+ };
56
+
57
+ GroupAction.propTypes = {
58
+ group: _propTypes.default.shape({
59
+ action: _propTypes.default.shape({
60
+ label: _propTypes.default.string.isRequired,
61
+ page: _propTypes.default.string,
62
+ aria_suffix: _propTypes.default.string,
63
+ onAction: _propTypes.default.func
64
+ })
65
+ }).isRequired
66
+ };
67
+ var _default = GroupAction;
68
+ exports.default = _default;
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+
3
+ var _react = require("@testing-library/react");
4
+
5
+ var _react2 = _interopRequireDefault(require("react"));
6
+
7
+ var _GroupAction = _interopRequireDefault(require("./GroupAction"));
8
+
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+
11
+ // Global imports
12
+ // Local imports
13
+ describe('components', function () {
14
+ describe('SummaryList.GroupAction', function () {
15
+ it('should handle a group row without an action', function () {
16
+ var ROW = {};
17
+
18
+ var _render = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_GroupAction.default, {
19
+ group: ROW
20
+ })),
21
+ container = _render.container;
22
+
23
+ expect(container.childNodes.length).toEqual(0);
24
+ });
25
+ it('should handle a row with an href in the action', function () {
26
+ var PAGE = 'alpha';
27
+ var ROW = {
28
+ action: {
29
+ page: PAGE,
30
+ label: 'Change'
31
+ }
32
+ };
33
+
34
+ var _render2 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_GroupAction.default, {
35
+ group: ROW
36
+ })),
37
+ container = _render2.container;
38
+
39
+ var link = container.childNodes[0];
40
+ expect(link.tagName).toEqual('A');
41
+ expect(link.getAttribute('href')).toEqual("/".concat(PAGE));
42
+ expect(link.textContent).toEqual(ROW.action.label);
43
+ });
44
+ it('should render an aria_suffix appropriately', function () {
45
+ var PAGE = 'alpha';
46
+ var ROW = {
47
+ action: {
48
+ page: PAGE,
49
+ label: 'Change',
50
+ aria_suffix: 'the thing'
51
+ }
52
+ };
53
+
54
+ var _render3 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_GroupAction.default, {
55
+ group: ROW
56
+ })),
57
+ container = _render3.container;
58
+
59
+ var link = container.childNodes[0];
60
+ expect(link.tagName).toEqual('A');
61
+ expect(link.getAttribute('href')).toEqual("/".concat(PAGE));
62
+ expect(link.textContent).toEqual("".concat(ROW.action.label, " ").concat(ROW.action.aria_suffix));
63
+ });
64
+ it('should handle a row with an onAction in the action', function () {
65
+ var ON_ACTION_CALLS = [];
66
+
67
+ var ON_ACTION = function ON_ACTION(row) {
68
+ ON_ACTION_CALLS.push(row);
69
+ };
70
+
71
+ var ROW = {
72
+ action: {
73
+ onAction: ON_ACTION,
74
+ label: 'Change'
75
+ }
76
+ };
77
+
78
+ var _render4 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_GroupAction.default, {
79
+ group: ROW
80
+ })),
81
+ container = _render4.container;
82
+
83
+ var link = container.childNodes[0];
84
+ expect(link.tagName).toEqual('A');
85
+ expect(link.getAttribute('onClick')).toBeDefined();
86
+ expect(link.textContent).toEqual(ROW.action.label);
87
+
88
+ _react.fireEvent.click(link, {});
89
+
90
+ expect(ON_ACTION_CALLS.length).toEqual(1);
91
+ expect(ON_ACTION_CALLS[0]).toEqual(ROW);
92
+ });
93
+ });
94
+ });
@@ -11,11 +11,13 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
11
11
 
12
12
  var _react = _interopRequireDefault(require("react"));
13
13
 
14
+ var _GroupAction = _interopRequireDefault(require("./GroupAction"));
15
+
14
16
  var _RowAction = _interopRequireDefault(require("./RowAction"));
15
17
 
16
18
  require("./SummaryList.scss");
17
19
 
18
- var _excluded = ["rows", "noChangeAction", "classBlock", "classModifiers", "className"];
20
+ var _excluded = ["rows", "noChangeAction", "isGroup", "classBlock", "classModifiers", "className"];
19
21
 
20
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
23
 
@@ -31,6 +33,7 @@ exports.DEFAULT_CLASS = DEFAULT_CLASS;
31
33
  var SummaryList = function SummaryList(_ref) {
32
34
  var rows = _ref.rows,
33
35
  noChangeAction = _ref.noChangeAction,
36
+ isGroup = _ref.isGroup,
34
37
  classBlock = _ref.classBlock,
35
38
  classModifiers = _ref.classModifiers,
36
39
  className = _ref.className,
@@ -38,22 +41,30 @@ var SummaryList = function SummaryList(_ref) {
38
41
 
39
42
  var classes = _copReactComponents.Utils.classBuilder(classBlock, classModifiers, className);
40
43
 
41
- return /*#__PURE__*/_react.default.createElement("dl", _extends({}, attrs, {
44
+ return /*#__PURE__*/_react.default.createElement("div", {
45
+ className: "group-of-rows"
46
+ }, /*#__PURE__*/_react.default.createElement("dl", _extends({}, attrs, {
42
47
  className: classes()
43
48
  }), rows.map(function (row) {
49
+ var _row$component;
50
+
44
51
  return /*#__PURE__*/_react.default.createElement("div", {
45
52
  key: "".concat(row.pageId, "_").concat(row.fieldId),
46
53
  className: classes('row')
47
54
  }, /*#__PURE__*/_react.default.createElement("dt", {
48
55
  className: classes('key')
49
- }, row.key), /*#__PURE__*/_react.default.createElement("dd", {
56
+ }, row.key, !((_row$component = row.component) !== null && _row$component !== void 0 && _row$component.required) && " (optional)"), /*#__PURE__*/_react.default.createElement("dd", {
50
57
  className: classes('value')
51
58
  }, row.value), !noChangeAction && /*#__PURE__*/_react.default.createElement("dd", {
52
59
  className: classes('actions')
53
60
  }, row.action && /*#__PURE__*/_react.default.createElement(_RowAction.default, {
54
61
  row: row
55
62
  })));
56
- }));
63
+ }), isGroup && /*#__PURE__*/_react.default.createElement("div", {
64
+ className: "change-group-button"
65
+ }, /*#__PURE__*/_react.default.createElement(_GroupAction.default, {
66
+ group: rows[0]
67
+ }))));
57
68
  };
58
69
 
59
70
  SummaryList.propTypes = {
@@ -1,17 +1,41 @@
1
1
  @import 'node_modules/govuk-frontend/govuk/_base';
2
2
  @import 'node_modules/govuk-frontend/govuk/components/summary-list/_summary-list';
3
3
 
4
- .govuk-summary-list__actions {
4
+ // .govuk-summary-list__actions {
5
+ // .govuk-link {
6
+ // float: right;
7
+ // color: govuk-colour('blue');
8
+ // cursor: pointer;
9
+ // }
10
+ // }
11
+
12
+ .changeRow {
5
13
  .govuk-link {
14
+ float: right;
6
15
  color: govuk-colour('blue');
7
16
  cursor: pointer;
8
17
  }
9
18
  }
10
19
 
11
- .caseview__key {
12
- font-weight: normal;
20
+ .group-of-rows {
21
+ position:relative;
22
+ }
23
+
24
+ .mobile-text{
25
+ text-transform: lowercase;
13
26
  }
14
27
 
15
- .caseview__value {
16
- @include govuk-typography-weight-bold;
28
+ @media screen and (min-width: 640px) {
29
+ .change-group-button {
30
+ position: absolute;
31
+ top: -47px;
32
+ right: 0;
33
+ }
34
+
35
+ .mobile-text{
36
+ display:none;
37
+ }
38
+
39
+
17
40
  }
41
+
@@ -113,7 +113,7 @@ describe('components', function () {
113
113
  value = _checkRow2[1],
114
114
  actions = _checkRow2[2];
115
115
 
116
- expect(key.textContent).toEqual(row.key);
116
+ expect(key.textContent).toEqual("".concat(row.key, " (optional)"));
117
117
  expect(value.textContent).toEqual(row.value);
118
118
  expect(actions.childNodes.length).toEqual(0);
119
119
  });
@@ -148,7 +148,7 @@ describe('components', function () {
148
148
  value = _checkRow4[1],
149
149
  actions = _checkRow4[2];
150
150
 
151
- expect(key.textContent).toEqual(row.key);
151
+ expect(key.textContent).toEqual("".concat(row.key, " (optional)"));
152
152
  expect(value.childNodes.length).toEqual(1);
153
153
  var valueDiv = value.childNodes[0];
154
154
  expect(valueDiv.tagName).toEqual('DIV');
@@ -199,7 +199,7 @@ describe('components', function () {
199
199
  value = _checkRow6[1],
200
200
  actions = _checkRow6[2];
201
201
 
202
- expect(key.textContent).toEqual(row.key);
202
+ expect(key.textContent).toEqual("".concat(row.key, " (optional)"));
203
203
  expect(value.textContent).toEqual(row.value);
204
204
  var a = actions.childNodes[0];
205
205
  expect(a.textContent).toEqual(row.action.label);
@@ -240,7 +240,50 @@ describe('components', function () {
240
240
  key = _checkRowNoChangeActi2[0],
241
241
  value = _checkRowNoChangeActi2[1];
242
242
 
243
- expect(key.textContent).toEqual(row.key);
243
+ expect(key.textContent).toEqual("".concat(row.key, " (optional)"));
244
+ expect(value.childNodes.length).toEqual(1);
245
+ var valueDiv = value.childNodes[0];
246
+ expect(valueDiv.tagName).toEqual('DIV');
247
+ expect(valueDiv.textContent).toEqual(VALUES[index]);
248
+ });
249
+ });
250
+ it('should render groups of rows corretly', function () {
251
+ var ID = 'test-id';
252
+ var VALUES = ['Alpha component value', 'Bravo component value', 'Charlie component value'];
253
+ var ISGROUP = true;
254
+ var ROWS = [{
255
+ pageId: 'p1',
256
+ fieldId: 'a',
257
+ key: 'Alpha',
258
+ value: /*#__PURE__*/_react2.default.createElement("div", null, VALUES[0])
259
+ }, {
260
+ pageId: 'p1',
261
+ fieldId: 'b',
262
+ key: 'Bravo',
263
+ value: /*#__PURE__*/_react2.default.createElement("div", null, VALUES[1])
264
+ }, {
265
+ pageId: 'p1',
266
+ fieldId: 'c',
267
+ key: 'Charlie',
268
+ value: /*#__PURE__*/_react2.default.createElement("div", null, VALUES[2])
269
+ }];
270
+
271
+ var _render6 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_SummaryList.default, {
272
+ "data-testid": ID,
273
+ rows: ROWS,
274
+ isGroup: ISGROUP
275
+ })),
276
+ container = _render6.container;
277
+
278
+ var summaryList = checkSummaryList(container, ID);
279
+ expect(summaryList.childNodes.length).toEqual(ROWS.length + 1);
280
+ ROWS.forEach(function (row, index) {
281
+ var _checkRow7 = checkRow(summaryList, index),
282
+ _checkRow8 = _slicedToArray(_checkRow7, 2),
283
+ key = _checkRow8[0],
284
+ value = _checkRow8[1];
285
+
286
+ expect(key.textContent).toEqual("".concat(row.key, " (optional)"));
244
287
  expect(value.childNodes.length).toEqual(1);
245
288
  var valueDiv = value.childNodes[0];
246
289
  expect(valueDiv.tagName).toEqual('DIV');
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var getGroupActionAttributes = function getGroupActionAttributes(groupRow) {
9
+ if (groupRow && Object.prototype.hasOwnProperty.call(groupRow, 'action')) {
10
+ if (typeof groupRow.action.onAction === 'function') {
11
+ return {
12
+ onClick: function onClick() {
13
+ return groupRow.action.onAction(groupRow);
14
+ }
15
+ };
16
+ } else if (groupRow.action.page) {
17
+ return {
18
+ href: "/".concat(groupRow.action.page)
19
+ };
20
+ }
21
+ }
22
+
23
+ return {};
24
+ };
25
+
26
+ var _default = getGroupActionAttributes;
27
+ exports.default = _default;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ var _getGroupActionAttributes = _interopRequireDefault(require("./getGroupActionAttributes"));
4
+
5
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
+
7
+ describe('components', function () {
8
+ describe('SummaryList', function () {
9
+ describe('helpers', function () {
10
+ describe('getGroupActionAttributes', function () {
11
+ it('should handle a null row', function () {
12
+ expect((0, _getGroupActionAttributes.default)(null)).toEqual({});
13
+ });
14
+ it('should handle a row without an action', function () {
15
+ expect((0, _getGroupActionAttributes.default)({})).toEqual({});
16
+ });
17
+ it('should handle a row with an empty action', function () {
18
+ var ROW = {
19
+ action: {}
20
+ };
21
+ expect((0, _getGroupActionAttributes.default)(ROW)).toEqual({});
22
+ });
23
+ it('should handle a row with a page', function () {
24
+ var PAGE = 'alpha';
25
+ var ROW = {
26
+ action: {
27
+ page: PAGE
28
+ }
29
+ };
30
+ expect((0, _getGroupActionAttributes.default)(ROW)).toEqual({
31
+ href: "/".concat(PAGE)
32
+ });
33
+ });
34
+ it('should handle a row with an onAction function', function () {
35
+ var ON_ACTION_CALLS = [];
36
+
37
+ var ON_ACTION = function ON_ACTION(row) {
38
+ ON_ACTION_CALLS.push(row);
39
+ };
40
+
41
+ var ROW = {
42
+ action: {
43
+ onAction: ON_ACTION
44
+ }
45
+ };
46
+ var ATTRS = (0, _getGroupActionAttributes.default)(ROW);
47
+ expect(ATTRS.onClick).toBeDefined();
48
+ expect(ATTRS.href).not.toBeDefined();
49
+ ATTRS.onClick();
50
+ expect(ON_ACTION_CALLS.length).toEqual(1);
51
+ expect(ON_ACTION_CALLS[0]).toEqual(ROW);
52
+ });
53
+ it('should favour onAction over href', function () {
54
+ var ON_ACTION_CALLS = [];
55
+
56
+ var ON_ACTION = function ON_ACTION(row) {
57
+ ON_ACTION_CALLS.push(row);
58
+ };
59
+
60
+ var HREF = 'http://alpha.homeoffice.gov.uk';
61
+ var ROW = {
62
+ action: {
63
+ href: HREF,
64
+ onAction: ON_ACTION
65
+ }
66
+ };
67
+ var ATTRS = (0, _getGroupActionAttributes.default)(ROW);
68
+ expect(ATTRS.onClick).toBeDefined();
69
+ expect(ATTRS.href).not.toBeDefined();
70
+ ATTRS.onClick();
71
+ expect(ON_ACTION_CALLS.length).toEqual(1);
72
+ expect(ON_ACTION_CALLS[0]).toEqual(ROW);
73
+ });
74
+ });
75
+ });
76
+ });
77
+ });