@ukhomeoffice/cop-react-form-renderer 2.8.4 → 2.10.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.
Files changed (68) hide show
  1. package/dist/components/CheckYourAnswers/CheckYourAnswers.js +8 -12
  2. package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +11 -9
  3. package/dist/components/FormComponent/Collection.js +244 -0
  4. package/dist/components/FormComponent/Collection.scss +23 -0
  5. package/dist/components/FormComponent/Container.js +110 -0
  6. package/dist/components/FormComponent/Container.test.js +26 -26
  7. package/dist/components/FormComponent/FormComponent.js +65 -128
  8. package/dist/components/FormComponent/FormComponent.test.js +19 -19
  9. package/dist/components/FormComponent/helpers/getComponentError.js +31 -0
  10. package/dist/components/FormComponent/helpers/getComponentError.test.js +52 -0
  11. package/dist/components/FormComponent/helpers/index.js +15 -0
  12. package/dist/components/FormPage/FormPage.js +7 -11
  13. package/dist/components/FormPage/FormPage.test.js +12 -76
  14. package/dist/components/FormRenderer/FormRenderer.js +103 -44
  15. package/dist/components/FormRenderer/helpers/canActionProceed.js +3 -12
  16. package/dist/components/FormRenderer/helpers/canActionProceed.test.js +41 -65
  17. package/dist/components/FormRenderer/helpers/canCYASubmit.js +3 -24
  18. package/dist/components/FormRenderer/helpers/canCYASubmit.test.js +72 -145
  19. package/dist/components/SummaryList/GroupAction.js +6 -2
  20. package/dist/components/SummaryList/SummaryList.js +33 -18
  21. package/dist/components/SummaryList/SummaryList.scss +12 -8
  22. package/dist/components/SummaryList/SummaryList.test.js +94 -27
  23. package/dist/components/SummaryList/SummaryListRow.js +51 -0
  24. package/dist/components/SummaryList/SummaryListTitleRow.js +30 -0
  25. package/dist/context/ValidationContext/ValidationContext.js +122 -0
  26. package/dist/context/ValidationContext/ValidationContext.test.js +98 -0
  27. package/dist/context/ValidationContext/index.js +23 -0
  28. package/dist/context/index.js +15 -0
  29. package/dist/hooks/index.js +8 -0
  30. package/dist/hooks/useValidation.js +19 -0
  31. package/dist/index.js +11 -5
  32. package/dist/json/group.json +1 -17
  33. package/dist/json/port.json +346 -0
  34. package/dist/json/sublocation.json +859 -0
  35. package/dist/json/terminal.json +81 -0
  36. package/dist/models/CollectionLabels.js +14 -0
  37. package/dist/models/ComponentTypes.js +2 -0
  38. package/dist/models/index.js +8 -0
  39. package/dist/setupTests.js +32 -0
  40. package/dist/utils/CheckYourAnswers/getCYARow.js +14 -0
  41. package/dist/utils/CheckYourAnswers/getCYARow.test.js +34 -11
  42. package/dist/utils/CheckYourAnswers/getCYARowForGroup.js +1 -0
  43. package/dist/utils/CheckYourAnswers/getCYARowsForCollection.js +89 -0
  44. package/dist/utils/CheckYourAnswers/getCYARowsForCollection.test.js +194 -0
  45. package/dist/utils/CheckYourAnswers/getCYARowsForContainer.test.js +9 -13
  46. package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +11 -4
  47. package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +58 -14
  48. package/dist/utils/Component/cleanAttributes.js +1 -1
  49. package/dist/utils/Component/getComponent.js +36 -3
  50. package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +92 -0
  51. package/dist/utils/Component/getDefaultValue.js +25 -0
  52. package/dist/utils/Component/getDefaultValue.test.js +53 -0
  53. package/dist/utils/Component/index.js +4 -1
  54. package/dist/utils/Meta/constants.js +10 -0
  55. package/dist/utils/Meta/documents/getDocuments.js +18 -0
  56. package/dist/utils/Meta/documents/getDocuments.test.js +43 -0
  57. package/dist/utils/Meta/documents/index.js +23 -0
  58. package/dist/utils/Meta/documents/setDocumentForField.js +36 -0
  59. package/dist/utils/Meta/documents/setDocumentForField.test.js +49 -0
  60. package/dist/utils/Meta/index.js +21 -0
  61. package/dist/utils/Validate/validateCollection.js +42 -0
  62. package/dist/utils/Validate/validateCollection.test.js +74 -0
  63. package/dist/utils/Validate/validateComponent.js +67 -48
  64. package/dist/utils/Validate/validateComponent.test.js +247 -188
  65. package/dist/utils/Validate/validateContainer.js +29 -0
  66. package/dist/utils/Validate/validateContainer.test.js +68 -0
  67. package/dist/utils/index.js +4 -1
  68. package/package.json +2 -2
@@ -0,0 +1,81 @@
1
+ {
2
+ "data": [
3
+ {
4
+ "id": 1,
5
+ "name": "Terminal 1",
6
+ "validfrom": "2019-01-01T00:01:00.000Z",
7
+ "validto": null,
8
+ "updatedby": null
9
+ },
10
+ {
11
+ "id": 2,
12
+ "name": "Terminal 2",
13
+ "validfrom": "2019-01-01T00:01:00.000Z",
14
+ "validto": null,
15
+ "updatedby": null
16
+ },
17
+ {
18
+ "id": 3,
19
+ "name": "Terminal 3",
20
+ "validfrom": "2019-01-01T00:01:00.000Z",
21
+ "validto": null,
22
+ "updatedby": null
23
+ },
24
+ {
25
+ "id": 4,
26
+ "name": "Terminal 4",
27
+ "validfrom": "2019-01-01T00:01:00.000Z",
28
+ "validto": null,
29
+ "updatedby": null
30
+ },
31
+ {
32
+ "id": 5,
33
+ "name": "Terminal 5",
34
+ "validfrom": "2019-01-01T00:01:00.000Z",
35
+ "validto": null,
36
+ "updatedby": null
37
+ },
38
+ {
39
+ "id": 6,
40
+ "name": "North Terminal",
41
+ "validfrom": "2019-01-01T00:01:00.000Z",
42
+ "validto": null,
43
+ "updatedby": null
44
+ },
45
+ {
46
+ "id": 7,
47
+ "name": "South Terminal",
48
+ "validfrom": "2019-01-01T00:01:00.000Z",
49
+ "validto": null,
50
+ "updatedby": null
51
+ },
52
+ {
53
+ "id": 8,
54
+ "name": "Eastern Docks",
55
+ "validfrom": "2019-01-01T00:01:00.000Z",
56
+ "validto": null,
57
+ "updatedby": null
58
+ },
59
+ {
60
+ "id": 9,
61
+ "name": "Western Docks",
62
+ "validfrom": "2019-01-01T00:01:00.000Z",
63
+ "validto": null,
64
+ "updatedby": null
65
+ },
66
+ {
67
+ "id": 10,
68
+ "name": "Tourist",
69
+ "validfrom": "2021-05-07T00:01:00.000Z",
70
+ "validto": null,
71
+ "updatedby": "Ben Milnes"
72
+ },
73
+ {
74
+ "id": 11,
75
+ "name": "Freight",
76
+ "validfrom": "2021-05-07T00:01:00.000Z",
77
+ "validto": null,
78
+ "updatedby": "Ben Milnes"
79
+ }
80
+ ]
81
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var CollectionLabels = {
8
+ add: 'Add another',
9
+ remove: 'Remove',
10
+ // eslint-disable-next-line no-template-curly-in-string
11
+ item: 'Item ${index}'
12
+ };
13
+ var _default = CollectionLabels;
14
+ exports.default = _default;
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var TYPE_AUTOCOMPLETE = 'autocomplete';
8
8
  var TYPE_CHECKBOXES = 'checkboxes';
9
+ var TYPE_COLLECTION = 'collection';
9
10
  var TYPE_CONTAINER = 'container';
10
11
  var TYPE_DATE = 'date';
11
12
  var TYPE_EMAIL = 'email';
@@ -21,6 +22,7 @@ var TYPE_TIME = 'time';
21
22
  var ComponentTypes = {
22
23
  AUTOCOMPLETE: TYPE_AUTOCOMPLETE,
23
24
  CHECKBOXES: TYPE_CHECKBOXES,
25
+ COLLECTION: TYPE_COLLECTION,
24
26
  CONTAINER: TYPE_CONTAINER,
25
27
  DATE: TYPE_DATE,
26
28
  EMAIL: TYPE_EMAIL,
@@ -3,6 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ Object.defineProperty(exports, "CollectionLabels", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _CollectionLabels.default;
10
+ }
11
+ });
6
12
  Object.defineProperty(exports, "ComponentTypes", {
7
13
  enumerable: true,
8
14
  get: function get() {
@@ -46,6 +52,8 @@ Object.defineProperty(exports, "TaskStates", {
46
52
  }
47
53
  });
48
54
 
55
+ var _CollectionLabels = _interopRequireDefault(require("./CollectionLabels"));
56
+
49
57
  var _ComponentTypes = _interopRequireDefault(require("./ComponentTypes"));
50
58
 
51
59
  var _EventTypes = _interopRequireDefault(require("./EventTypes"));
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.renderWithValidation = exports.renderDomWithValidation = exports.expectObjectLike = void 0;
7
+
8
+ var _react = require("@testing-library/react");
9
+
10
+ var _reactDom = require("react-dom");
11
+
12
+ var _context = require("./context");
13
+
14
+ var renderWithValidation = function renderWithValidation(ui, options) {
15
+ return (0, _react.render)( /*#__PURE__*/React.createElement(_context.ValidationContextProvider, null, ui), options);
16
+ };
17
+
18
+ exports.renderWithValidation = renderWithValidation;
19
+
20
+ var renderDomWithValidation = function renderDomWithValidation(ui, container, callback) {
21
+ return (0, _reactDom.render)( /*#__PURE__*/React.createElement(_context.ValidationContextProvider, null, ui), container, callback);
22
+ };
23
+
24
+ exports.renderDomWithValidation = renderDomWithValidation;
25
+
26
+ var expectObjectLike = function expectObjectLike(received, expected) {
27
+ Object.keys(expected).forEach(function (key) {
28
+ expect(received[key]).toEqual(expected[key]);
29
+ });
30
+ };
31
+
32
+ exports.expectObjectLike = expectObjectLike;
@@ -29,16 +29,30 @@ var getCYARow = function getCYARow(page, component, onAction) {
29
29
  value = page.formData[component.fieldId];
30
30
  }
31
31
 
32
+ setNestedValue(component, page);
32
33
  return {
33
34
  pageId: page.id,
34
35
  id: component.id,
35
36
  fieldId: component.fieldId,
37
+ full_path: component.full_path,
36
38
  key: component.label || component.cya_label,
39
+ required: component.required,
37
40
  component: _Component.default.editable(component) ? component : undefined,
38
41
  value: value || '',
39
42
  action: (0, _getCYAAction.default)(component.readonly, page, onAction)
40
43
  };
41
44
  };
42
45
 
46
+ var setNestedValue = function setNestedValue(component, page) {
47
+ var _component$data, _component$data$optio;
48
+
49
+ (_component$data = component.data) === null || _component$data === void 0 ? void 0 : (_component$data$optio = _component$data.options) === null || _component$data$optio === void 0 ? void 0 : _component$data$optio.forEach(function (option, index) {
50
+ //check if option is selected and has nested component
51
+ if (page.formData[component.id] === option.value && option.nested) {
52
+ component.data.options[index].nested.value = page.formData[option.nested.id];
53
+ }
54
+ });
55
+ };
56
+
43
57
  var _default = getCYARow;
44
58
  exports.default = _default;
@@ -1,19 +1,16 @@
1
1
  "use strict";
2
2
 
3
+ var _setupTests = require("../../setupTests");
4
+
3
5
  var _getCYARow = _interopRequireDefault(require("./getCYARow"));
4
6
 
5
7
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
8
 
7
- // Local imports
9
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
10
+
8
11
  describe('utils', function () {
9
12
  describe('CheckYourAnswers', function () {
10
13
  describe('getCYARow', function () {
11
- var expectObjectLike = function expectObjectLike(received, expected) {
12
- Object.keys(expected).forEach(function (key) {
13
- expect(received[key]).toEqual(expected[key]);
14
- });
15
- };
16
-
17
14
  it('should get an appropriate row for a readonly text component', function () {
18
15
  var PAGE = {
19
16
  id: 'page',
@@ -32,7 +29,7 @@ describe('utils', function () {
32
29
  var ON_ACTION = function ON_ACTION() {};
33
30
 
34
31
  var ROW = (0, _getCYARow.default)(PAGE, COMPONENT, ON_ACTION);
35
- expectObjectLike(ROW, {
32
+ (0, _setupTests.expectObjectLike)(ROW, {
36
33
  pageId: PAGE.id,
37
34
  fieldId: COMPONENT.fieldId,
38
35
  key: COMPONENT.label,
@@ -110,7 +107,7 @@ describe('utils', function () {
110
107
  var ON_ACTION = function ON_ACTION() {};
111
108
 
112
109
  var ROW = (0, _getCYARow.default)(PAGE, COMPONENT, ON_ACTION);
113
- expectObjectLike(ROW, {
110
+ (0, _setupTests.expectObjectLike)(ROW, {
114
111
  pageId: PAGE.id,
115
112
  fieldId: COMPONENT.fieldId,
116
113
  key: COMPONENT.cya_label,
@@ -137,17 +134,43 @@ describe('utils', function () {
137
134
  var ON_ACTION = function ON_ACTION() {};
138
135
 
139
136
  var ROW = (0, _getCYARow.default)(PAGE, COMPONENT, ON_ACTION);
140
- expectObjectLike(ROW, {
137
+ (0, _setupTests.expectObjectLike)(ROW, {
141
138
  pageId: PAGE.id,
142
139
  fieldId: COMPONENT.fieldId,
143
140
  key: COMPONENT.label,
144
141
  component: COMPONENT,
145
142
  value: 'Bravo'
146
143
  });
147
- expectObjectLike(ROW.action, {
144
+ (0, _setupTests.expectObjectLike)(ROW.action, {
148
145
  onAction: ON_ACTION
149
146
  });
150
147
  });
148
+ it('should update update any nested components with corresponding values from the stored formdata', function () {
149
+ var SELECTED_VALUE = 'selectedValue';
150
+ var NESTED_ID = 'nestedId';
151
+ var NESTED_VALUE = 'nestedValue';
152
+ var PAGE = {
153
+ id: 'page',
154
+ formData: _defineProperty({
155
+ a: SELECTED_VALUE
156
+ }, NESTED_ID, NESTED_VALUE),
157
+ cya_link: {}
158
+ };
159
+ var COMPONENT = {
160
+ type: 'radios',
161
+ id: 'a',
162
+ data: {
163
+ options: [{
164
+ value: SELECTED_VALUE,
165
+ nested: {
166
+ id: NESTED_ID
167
+ }
168
+ }]
169
+ }
170
+ };
171
+ var ROW = (0, _getCYARow.default)(PAGE, COMPONENT, function () {});
172
+ expect(ROW.component.data.options[0].nested.value).toEqual(NESTED_VALUE);
173
+ });
151
174
  });
152
175
  });
153
176
  });
@@ -69,6 +69,7 @@ var getCYARowForGroup = function getCYARowForGroup(page, group, rows, onAction)
69
69
  pageId: page.id,
70
70
  fieldId: group.id,
71
71
  key: group.label,
72
+ required: group.required,
72
73
  value: value,
73
74
  action: (0, _getCYAAction.default)(false, page, onAction)
74
75
  };
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _copReactComponents = require("@ukhomeoffice/cop-react-components");
9
+
10
+ var _models = require("../../models");
11
+
12
+ var _getCYARowsForContainer = _interopRequireDefault(require("./getCYARowsForContainer"));
13
+
14
+ var _showComponentCYA = _interopRequireDefault(require("./showComponentCYA"));
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
18
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
19
+
20
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
21
+
22
+ 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); }
23
+
24
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
25
+
26
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
27
+
28
+ 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; }
29
+
30
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
31
+
32
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
33
+
34
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
35
+
36
+ var getContainerForItem = function getContainerForItem(collection, item, labelCount, full_path) {
37
+ return {
38
+ id: item.id,
39
+ fieldId: item.id,
40
+ type: _models.ComponentTypes.CONTAINER,
41
+ required: collection.required,
42
+ full_path: full_path,
43
+ components: collection.item.map(function (component) {
44
+ return _objectSpread(_objectSpread({}, component), {}, {
45
+ label: _copReactComponents.Utils.interpolateString(component.label, _objectSpread(_objectSpread({}, item), {}, {
46
+ index: labelCount
47
+ })),
48
+ full_path: "".concat(full_path, ".").concat(component.fieldId)
49
+ });
50
+ })
51
+ };
52
+ };
53
+
54
+ var getTitleRowForItem = function getTitleRowForItem(collection, item, pageId, labelCount, full_path) {
55
+ var labels = _objectSpread(_objectSpread({}, _models.CollectionLabels), collection.labels);
56
+
57
+ if (labels.item) {
58
+ return {
59
+ pageId: pageId,
60
+ fieldId: collection.fieldId,
61
+ full_path: full_path,
62
+ key: _copReactComponents.Utils.interpolateString(labels.item, _objectSpread(_objectSpread({}, item), {}, {
63
+ index: labelCount
64
+ })),
65
+ type: 'title',
66
+ action: null
67
+ };
68
+ }
69
+
70
+ return null;
71
+ };
72
+
73
+ var getCYARowsForCollection = function getCYARowsForCollection(page, collection, items, onAction) {
74
+ if (Array.isArray(items) && (0, _showComponentCYA.default)(collection, page.formData)) {
75
+ return items.flatMap(function (item, index) {
76
+ var labelCount = (collection.countOffset || 0) + index + 1;
77
+ var full_path = "".concat(collection.full_path || collection.fieldId, "[").concat(index, "]");
78
+ var container = getContainerForItem(collection, item, labelCount, full_path);
79
+ return [getTitleRowForItem(collection, item, page.id, labelCount, full_path)].concat(_toConsumableArray((0, _getCYARowsForContainer.default)(page, container, item, onAction)));
80
+ }).filter(function (r) {
81
+ return !!r;
82
+ });
83
+ }
84
+
85
+ return [];
86
+ };
87
+
88
+ var _default = getCYARowsForCollection;
89
+ exports.default = _default;
@@ -0,0 +1,194 @@
1
+ "use strict";
2
+
3
+ var _models = require("../../models");
4
+
5
+ var _setupTests = require("../../setupTests");
6
+
7
+ var _getCYARowsForCollection = _interopRequireDefault(require("./getCYARowsForCollection"));
8
+
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+
11
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
12
+
13
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
14
+
15
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
16
+
17
+ describe('utils.CheckYourAnswers.getCYARowsForCollection', function () {
18
+ it('should get no rows when there are no items', function () {
19
+ var FORM_DATA = undefined;
20
+ var PAGE = {
21
+ id: 'page',
22
+ formData: FORM_DATA,
23
+ cya_link: {}
24
+ };
25
+ var COMPONENT = {
26
+ type: 'text',
27
+ readonly: true,
28
+ id: 'a',
29
+ fieldId: 'a',
30
+ label: 'Alpha'
31
+ };
32
+ var COLLECTION = {
33
+ id: 'collection',
34
+ fieldId: 'collection',
35
+ type: _models.ComponentTypes.COLLECTION,
36
+ item: [COMPONENT]
37
+ };
38
+
39
+ var ON_ACTION = function ON_ACTION() {};
40
+
41
+ var ROWS = (0, _getCYARowsForCollection.default)(PAGE, COLLECTION, undefined, ON_ACTION);
42
+ expect(ROWS.length).toEqual(0);
43
+ });
44
+ it('should get an appropriate row for a collection with a single readonly text component', function () {
45
+ var FORM_DATA = {
46
+ collection: [{
47
+ a: 'Bravo'
48
+ }]
49
+ };
50
+ var PAGE = {
51
+ id: 'page',
52
+ formData: FORM_DATA,
53
+ cya_link: {}
54
+ };
55
+ var COMPONENT = {
56
+ type: 'text',
57
+ readonly: true,
58
+ id: 'a',
59
+ fieldId: 'a',
60
+ label: 'Alpha'
61
+ };
62
+ var COLLECTION = {
63
+ id: 'collection',
64
+ fieldId: 'collection',
65
+ type: _models.ComponentTypes.COLLECTION,
66
+ countOffset: 22,
67
+ item: [COMPONENT],
68
+ value: FORM_DATA.collection,
69
+ formData: FORM_DATA
70
+ };
71
+
72
+ var ON_ACTION = function ON_ACTION() {};
73
+
74
+ var ROWS = (0, _getCYARowsForCollection.default)(PAGE, COLLECTION, FORM_DATA.collection, ON_ACTION);
75
+ expect(ROWS.length).toEqual(2); // Item title row + component row
76
+
77
+ (0, _setupTests.expectObjectLike)(ROWS[0], {
78
+ pageId: PAGE.id,
79
+ fieldId: COLLECTION.fieldId,
80
+ full_path: "".concat(COLLECTION.fieldId, "[0]"),
81
+ key: 'Item 23',
82
+ // includes countOffset
83
+ type: 'title',
84
+ action: null
85
+ });
86
+ (0, _setupTests.expectObjectLike)(ROWS[1], {
87
+ pageId: PAGE.id,
88
+ fieldId: COMPONENT.fieldId,
89
+ full_path: "".concat(COLLECTION.fieldId, "[0].").concat(COMPONENT.fieldId),
90
+ key: COMPONENT.label,
91
+ action: null,
92
+ component: _objectSpread(_objectSpread({}, COMPONENT), {}, {
93
+ full_path: "".concat(COLLECTION.fieldId, "[0].").concat(COMPONENT.fieldId)
94
+ }),
95
+ value: 'Bravo'
96
+ });
97
+ });
98
+ it('should get an appropriate row for a collection with a single readonly text component where the item label is an empty string', function () {
99
+ var FORM_DATA = {
100
+ collection: [{
101
+ a: 'Bravo'
102
+ }]
103
+ };
104
+ var PAGE = {
105
+ id: 'page',
106
+ formData: FORM_DATA,
107
+ cya_link: {}
108
+ };
109
+ var COMPONENT = {
110
+ type: 'text',
111
+ readonly: true,
112
+ id: 'a',
113
+ fieldId: 'a',
114
+ label: 'Alpha'
115
+ };
116
+ var COLLECTION = {
117
+ id: 'collection',
118
+ fieldId: 'collection',
119
+ type: _models.ComponentTypes.COLLECTION,
120
+ labels: {
121
+ item: ''
122
+ },
123
+ countOffset: 22,
124
+ item: [COMPONENT],
125
+ value: FORM_DATA.collection,
126
+ formData: FORM_DATA
127
+ };
128
+
129
+ var ON_ACTION = function ON_ACTION() {};
130
+
131
+ var ROWS = (0, _getCYARowsForCollection.default)(PAGE, COLLECTION, FORM_DATA.collection, ON_ACTION);
132
+ expect(ROWS.length).toEqual(1); // Just the component row, no title row
133
+
134
+ (0, _setupTests.expectObjectLike)(ROWS[0], {
135
+ pageId: PAGE.id,
136
+ fieldId: COMPONENT.fieldId,
137
+ full_path: "".concat(COLLECTION.fieldId, "[0].").concat(COMPONENT.fieldId),
138
+ key: COMPONENT.label,
139
+ action: null,
140
+ component: _objectSpread(_objectSpread({}, COMPONENT), {}, {
141
+ full_path: "".concat(COLLECTION.fieldId, "[0].").concat(COMPONENT.fieldId)
142
+ }),
143
+ value: 'Bravo'
144
+ });
145
+ });
146
+ it('should interpolate a field label appropriately', function () {
147
+ var FORM_DATA = {
148
+ collection: [{
149
+ a: 'Bravo'
150
+ }]
151
+ };
152
+ var PAGE = {
153
+ id: 'page',
154
+ formData: FORM_DATA,
155
+ cya_link: {}
156
+ }; // eslint-disable-next-line no-template-curly-in-string
157
+
158
+ var COMPONENT = {
159
+ type: 'text',
160
+ readonly: true,
161
+ id: 'a',
162
+ fieldId: 'a',
163
+ label: 'Alpha ${index}'
164
+ };
165
+ var COLLECTION = {
166
+ id: 'collection',
167
+ fieldId: 'collection',
168
+ type: _models.ComponentTypes.COLLECTION,
169
+ item: [COMPONENT],
170
+ value: FORM_DATA.collection,
171
+ formData: FORM_DATA
172
+ };
173
+
174
+ var ON_ACTION = function ON_ACTION() {};
175
+
176
+ var ROWS = (0, _getCYARowsForCollection.default)(PAGE, COLLECTION, FORM_DATA.collection, ON_ACTION);
177
+ expect(ROWS.length).toEqual(2); // Title and item row.
178
+
179
+ (0, _setupTests.expectObjectLike)(ROWS[1], {
180
+ pageId: PAGE.id,
181
+ fieldId: COMPONENT.fieldId,
182
+ full_path: "".concat(COLLECTION.fieldId, "[0].").concat(COMPONENT.fieldId),
183
+ key: 'Alpha 1',
184
+ // no countOffset
185
+ action: null,
186
+ component: _objectSpread(_objectSpread({}, COMPONENT), {}, {
187
+ full_path: "".concat(COLLECTION.fieldId, "[0].").concat(COMPONENT.fieldId),
188
+ label: 'Alpha 1' // no countOffset
189
+
190
+ }),
191
+ value: 'Bravo'
192
+ });
193
+ });
194
+ });
@@ -2,18 +2,14 @@
2
2
 
3
3
  var _models = require("../../models");
4
4
 
5
+ var _setupTests = require("../../setupTests");
6
+
5
7
  var _getCYARowsForContainer = _interopRequireDefault(require("./getCYARowsForContainer"));
6
8
 
7
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
10
 
9
11
  // Local imports
10
12
  describe('utils.CheckYourAnswers.getCYARowsForContainer', function () {
11
- var expectObjectLike = function expectObjectLike(received, expected) {
12
- Object.keys(expected).forEach(function (key) {
13
- expect(received[key]).toEqual(expected[key]);
14
- });
15
- };
16
-
17
13
  it('should get an appropriate row for a container with a single readonly text component', function () {
18
14
  var FORM_DATA = {
19
15
  container: {
@@ -46,7 +42,7 @@ describe('utils.CheckYourAnswers.getCYARowsForContainer', function () {
46
42
  var ROWS = (0, _getCYARowsForContainer.default)(PAGE, CONTAINER, FORM_DATA.container, ON_ACTION);
47
43
  expect(ROWS.length).toEqual(1);
48
44
  ROWS.forEach(function (row, index) {
49
- expectObjectLike(row, {
45
+ (0, _setupTests.expectObjectLike)(row, {
50
46
  pageId: PAGE.id,
51
47
  fieldId: CONTAINER.components[index].fieldId,
52
48
  key: CONTAINER.components[index].label,
@@ -94,14 +90,14 @@ describe('utils.CheckYourAnswers.getCYARowsForContainer', function () {
94
90
  var ROWS = (0, _getCYARowsForContainer.default)(PAGE, CONTAINER, FORM_DATA.container, ON_ACTION);
95
91
  expect(ROWS.length).toEqual(2);
96
92
  ROWS.forEach(function (row, index) {
97
- expectObjectLike(row, {
93
+ (0, _setupTests.expectObjectLike)(row, {
98
94
  pageId: PAGE.id,
99
95
  fieldId: CONTAINER.components[index].fieldId,
100
96
  key: CONTAINER.components[index].label,
101
97
  component: CONTAINER.components[index],
102
98
  value: "".concat(CONTAINER.components[index].label, " Charlie")
103
99
  });
104
- expectObjectLike(row.action, {
100
+ (0, _setupTests.expectObjectLike)(row.action, {
105
101
  onAction: ON_ACTION
106
102
  });
107
103
  });
@@ -148,14 +144,14 @@ describe('utils.CheckYourAnswers.getCYARowsForContainer', function () {
148
144
  var ROWS = (0, _getCYARowsForContainer.default)(PAGE, CONTAINER, FORM_DATA.container, ON_ACTION);
149
145
  expect(ROWS.length).toEqual(2);
150
146
  ROWS.forEach(function (row, index) {
151
- expectObjectLike(row, {
147
+ (0, _setupTests.expectObjectLike)(row, {
152
148
  pageId: PAGE.id,
153
149
  fieldId: CONTAINER.components[index].fieldId,
154
150
  key: CONTAINER.components[index].label,
155
151
  component: CONTAINER.components[index],
156
152
  value: "".concat(CONTAINER.components[index].label, " Charlie")
157
153
  });
158
- expectObjectLike(row.action, {
154
+ (0, _setupTests.expectObjectLike)(row.action, {
159
155
  onAction: ON_ACTION
160
156
  });
161
157
  });
@@ -202,7 +198,7 @@ describe('utils.CheckYourAnswers.getCYARowsForContainer', function () {
202
198
  var ROWS = (0, _getCYARowsForContainer.default)(PAGE, CONTAINER, FORM_DATA.container, ON_ACTION);
203
199
  expect(ROWS.length).toEqual(1);
204
200
  ROWS.forEach(function (row, index) {
205
- expectObjectLike(row, {
201
+ (0, _setupTests.expectObjectLike)(row, {
206
202
  pageId: PAGE.id,
207
203
  fieldId: NESTED_CONTAINER.components[index].fieldId,
208
204
  key: NESTED_CONTAINER.components[index].label,
@@ -244,7 +240,7 @@ describe('utils.CheckYourAnswers.getCYARowsForContainer', function () {
244
240
  var ROWS = (0, _getCYARowsForContainer.default)(PAGE, CONTAINER, undefined, ON_ACTION);
245
241
  expect(ROWS.length).toEqual(1);
246
242
  ROWS.forEach(function (row, index) {
247
- expectObjectLike(row, {
243
+ (0, _setupTests.expectObjectLike)(row, {
248
244
  pageId: PAGE.id,
249
245
  fieldId: NESTED_CONTAINER.components[index].fieldId,
250
246
  key: NESTED_CONTAINER.components[index].label,