@ukhomeoffice/cop-react-form-renderer 0.1.0-gamma → 1.0.0-alpha

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 (62) hide show
  1. package/dist/components/CheckYourAnswers/Answer.test.js +94 -0
  2. package/dist/components/CheckYourAnswers/CheckYourAnswers.js +79 -27
  3. package/dist/components/CheckYourAnswers/CheckYourAnswers.scss +0 -7
  4. package/dist/components/CheckYourAnswers/CheckYourAnswers.stories.mdx +78 -1
  5. package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +332 -0
  6. package/dist/components/FormPage/FormPage.test.js +3 -1
  7. package/dist/components/FormRenderer/FormRenderer.js +75 -54
  8. package/dist/components/FormRenderer/FormRenderer.stories.mdx +35 -7
  9. package/dist/components/FormRenderer/FormRenderer.test.js +471 -0
  10. package/dist/components/FormRenderer/handlers/cyaAction.js +28 -0
  11. package/dist/components/FormRenderer/handlers/getPageId.js +28 -0
  12. package/dist/components/FormRenderer/handlers/getPageId.test.js +61 -0
  13. package/dist/components/FormRenderer/handlers/handlers.test.js +97 -0
  14. package/dist/components/FormRenderer/handlers/index.js +23 -0
  15. package/dist/components/FormRenderer/handlers/navigate.js +28 -0
  16. package/dist/components/FormRenderer/handlers/submissionError.js +20 -0
  17. package/dist/components/FormRenderer/helpers/canCYASubmit.js +42 -0
  18. package/dist/components/FormRenderer/helpers/canCYASubmit.test.js +155 -0
  19. package/dist/components/FormRenderer/helpers/getCYA.js +2 -2
  20. package/dist/components/FormRenderer/helpers/getCYA.test.js +5 -5
  21. package/dist/components/FormRenderer/helpers/getFormState.test.js +7 -7
  22. package/dist/components/FormRenderer/helpers/getNextPageId.js +65 -0
  23. package/dist/components/FormRenderer/helpers/getNextPageId.test.js +90 -0
  24. package/dist/components/FormRenderer/helpers/getPage.js +1 -1
  25. package/dist/components/FormRenderer/helpers/getPage.test.js +3 -3
  26. package/dist/components/FormRenderer/helpers/index.js +17 -13
  27. package/dist/components/PageActions/ActionButton.js +5 -9
  28. package/dist/components/PageActions/ActionButton.test.js +3 -1
  29. package/dist/components/PageActions/PageActions.test.js +4 -2
  30. package/dist/components/SummaryList/RowAction.js +1 -1
  31. package/dist/components/SummaryList/RowAction.test.js +8 -18
  32. package/dist/components/SummaryList/SummaryList.js +4 -4
  33. package/dist/components/SummaryList/SummaryList.scss +7 -0
  34. package/dist/components/SummaryList/SummaryList.stories.mdx +36 -0
  35. package/dist/components/SummaryList/SummaryList.test.js +197 -0
  36. package/dist/hooks/useHooks.js +12 -15
  37. package/dist/index.js +3 -1
  38. package/dist/index.test.js +18 -0
  39. package/dist/models/EventTypes.js +14 -0
  40. package/dist/models/FormPages.js +14 -0
  41. package/dist/models/PageAction.js +40 -0
  42. package/dist/models/index.js +24 -0
  43. package/dist/utils/CheckYourAnswers/getCYAAction.js +9 -0
  44. package/dist/utils/CheckYourAnswers/getCYARow.js +10 -0
  45. package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +9 -0
  46. package/dist/utils/CheckYourAnswers/showComponentCYA.js +6 -5
  47. package/dist/utils/Component/getComponent.test.js +1 -1
  48. package/dist/utils/Format/formatData.js +32 -0
  49. package/dist/utils/Format/formatData.test.js +46 -0
  50. package/dist/utils/Format/formatDataForComponent.js +41 -0
  51. package/dist/utils/Format/formatDataForComponent.test.js +161 -0
  52. package/dist/utils/Format/formatDataForForm.js +33 -0
  53. package/dist/utils/Format/formatDataForForm.test.js +78 -0
  54. package/dist/utils/Format/formatDataForPage.js +37 -0
  55. package/dist/utils/Format/formatDataForPage.test.js +96 -0
  56. package/dist/utils/Format/index.js +26 -0
  57. package/dist/utils/Hub/getFormHub.js +14 -0
  58. package/dist/utils/Validate/validatePage.test.js +1 -1
  59. package/dist/utils/index.js +3 -0
  60. package/package.json +6 -3
  61. package/dist/components/FormRenderer/helpers.js +0 -66
  62. package/dist/components/FormRenderer/helpers.test.js +0 -158
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.handlers = exports.default = void 0;
7
+
8
+ var _cyaAction = _interopRequireDefault(require("./cyaAction"));
9
+
10
+ var _navigate = _interopRequireDefault(require("./navigate"));
11
+
12
+ var _submissionError = _interopRequireDefault(require("./submissionError"));
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ var handlers = {
17
+ cyaAction: _cyaAction.default,
18
+ navigate: _navigate.default,
19
+ submissionError: _submissionError.default
20
+ };
21
+ exports.handlers = handlers;
22
+ var _default = handlers;
23
+ exports.default = _default;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _getPageId = _interopRequireDefault(require("./getPageId"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ /**
13
+ * Gets the pageId from the invoked page action and calls onNavigate if it is
14
+ * different to the currentPageId.
15
+ * @param {object} action The invoked action.
16
+ * @param {string} currentPageId The current pageId.
17
+ * @param {Function} onNavigate The handler to call if the pageId is different to the currentPageId.
18
+ */
19
+ var navigate = function navigate(action, currentPageId, onNavigate) {
20
+ var pageId = (0, _getPageId.default)(action, currentPageId);
21
+
22
+ if (pageId !== currentPageId) {
23
+ onNavigate(pageId);
24
+ }
25
+ };
26
+
27
+ var _default = navigate;
28
+ exports.default = _default;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ /**
9
+ * Formats back-end errors and invokes an onError handler.
10
+ * @param {Array} errors The errors returned by the backend when submitting.
11
+ * @param {Function} onError The handler to call with the formatted errors.
12
+ */
13
+ var submissionError = function submissionError(errors, onError) {
14
+ // For now, simply pass them straight through as we don't yet know
15
+ // what the errors will look like.
16
+ onError(errors);
17
+ };
18
+
19
+ var _default = submissionError;
20
+ exports.default = _default;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _utils = _interopRequireDefault(require("../../../utils"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
13
+
14
+ 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."); }
15
+
16
+ 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); }
17
+
18
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
19
+
20
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
21
+
22
+ 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; }
23
+
24
+ /**
25
+ * Assesses whether the CYA screen can submit.
26
+ * Presently, this will validate all of the form pages and, only if all pages are
27
+ * valid will it proceed.
28
+ * @param {Array} pages All of the pages contained within the form.
29
+ * @param {Function} onError A function to call with any validation errors.
30
+ * @returns A boolean where `true` means the CYA can submit and `false` means it cannot.
31
+ */
32
+ var canCYASubmit = function canCYASubmit(pages, onError) {
33
+ var errors = [];
34
+ pages.forEach(function (p) {
35
+ errors.push.apply(errors, _toConsumableArray(_utils.default.Validate.page(p.components, p.formData)));
36
+ });
37
+ onError(errors);
38
+ return errors.length === 0;
39
+ };
40
+
41
+ var _default = canCYASubmit;
42
+ exports.default = _default;
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+
3
+ var _canCYASubmit = _interopRequireDefault(require("./canCYASubmit"));
4
+
5
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
+
7
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
8
+
9
+ 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."); }
10
+
11
+ 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); }
12
+
13
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
14
+
15
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
16
+
17
+ 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; }
18
+
19
+ describe('components', function () {
20
+ describe('FormRenderer', function () {
21
+ describe('helpers', function () {
22
+ describe('canCYASubmit', function () {
23
+ it('should return true when all pages are valid', function () {
24
+ var PAGE_1 = {
25
+ components: [{
26
+ id: 'a',
27
+ fieldId: 'a',
28
+ label: 'Alpha',
29
+ required: true
30
+ }],
31
+ formData: {
32
+ a: 'Bravo'
33
+ }
34
+ };
35
+ var PAGE_2 = {
36
+ components: [{
37
+ id: 'c',
38
+ fieldId: 'c',
39
+ label: 'Charlie',
40
+ required: true
41
+ }],
42
+ formData: {
43
+ c: 'Delta'
44
+ }
45
+ };
46
+ expect((0, _canCYASubmit.default)([PAGE_1, PAGE_2], function () {})).toBeTruthy();
47
+ });
48
+ it('should return false when the first page is invalid and should have called the onErrors method appropriately', function () {
49
+ var PAGE_1 = {
50
+ components: [{
51
+ id: 'a',
52
+ fieldId: 'a',
53
+ label: 'Alpha',
54
+ required: true
55
+ }],
56
+ formData: {}
57
+ };
58
+ var PAGE_2 = {
59
+ components: [{
60
+ id: 'c',
61
+ fieldId: 'c',
62
+ label: 'Charlie',
63
+ required: true
64
+ }],
65
+ formData: {
66
+ c: 'Delta'
67
+ }
68
+ };
69
+ var ERRORS = [];
70
+
71
+ var ON_ERROR = function ON_ERROR(errors) {
72
+ ERRORS.push.apply(ERRORS, _toConsumableArray(errors));
73
+ };
74
+
75
+ expect((0, _canCYASubmit.default)([PAGE_1, PAGE_2], ON_ERROR)).toBeFalsy();
76
+ expect(ERRORS.length).toEqual(1);
77
+ expect(ERRORS[0]).toEqual({
78
+ id: 'a',
79
+ error: 'Alpha is required'
80
+ });
81
+ });
82
+ it('should return false when the second page is invalid and should have called the onErrors method appropriately', function () {
83
+ var PAGE_1 = {
84
+ components: [{
85
+ id: 'a',
86
+ fieldId: 'a',
87
+ label: 'Alpha',
88
+ required: true
89
+ }],
90
+ formData: {
91
+ a: 'Bravo'
92
+ }
93
+ };
94
+ var PAGE_2 = {
95
+ components: [{
96
+ id: 'c',
97
+ fieldId: 'c',
98
+ label: 'Charlie',
99
+ required: true
100
+ }],
101
+ formData: {}
102
+ };
103
+ var ERRORS = [];
104
+
105
+ var ON_ERROR = function ON_ERROR(errors) {
106
+ ERRORS.push.apply(ERRORS, _toConsumableArray(errors));
107
+ };
108
+
109
+ expect((0, _canCYASubmit.default)([PAGE_1, PAGE_2], ON_ERROR)).toBeFalsy();
110
+ expect(ERRORS.length).toEqual(1);
111
+ expect(ERRORS[0]).toEqual({
112
+ id: 'c',
113
+ error: 'Charlie is required'
114
+ });
115
+ });
116
+ it('should return false when the both pages are invalid and should have called the onErrors method appropriately', function () {
117
+ var PAGE_1 = {
118
+ components: [{
119
+ id: 'a',
120
+ fieldId: 'a',
121
+ label: 'Alpha',
122
+ required: true
123
+ }],
124
+ formData: {}
125
+ };
126
+ var PAGE_2 = {
127
+ components: [{
128
+ id: 'c',
129
+ fieldId: 'c',
130
+ label: 'Charlie',
131
+ required: true
132
+ }],
133
+ formData: {}
134
+ };
135
+ var ERRORS = [];
136
+
137
+ var ON_ERROR = function ON_ERROR(errors) {
138
+ ERRORS.push.apply(ERRORS, _toConsumableArray(errors));
139
+ };
140
+
141
+ expect((0, _canCYASubmit.default)([PAGE_1, PAGE_2], ON_ERROR)).toBeFalsy();
142
+ expect(ERRORS.length).toEqual(2);
143
+ expect(ERRORS[0]).toEqual({
144
+ id: 'a',
145
+ error: 'Alpha is required'
146
+ });
147
+ expect(ERRORS[1]).toEqual({
148
+ id: 'c',
149
+ error: 'Charlie is required'
150
+ });
151
+ });
152
+ });
153
+ });
154
+ });
155
+ });
@@ -16,11 +16,11 @@ var _models = require("../../../models");
16
16
  * @returns A configuration object for the Check your answers screen.
17
17
  */
18
18
  var getCYA = function getCYA(pageId, hub) {
19
- if (pageId === 'hub' && hub === _models.HubFormats.CYA) {
19
+ if (pageId === _models.FormPages.HUB && hub === _models.HubFormats.CYA) {
20
20
  return {
21
21
  title: ''
22
22
  };
23
- } else if (pageId === _models.HubFormats.CYA) {
23
+ } else if (pageId === _models.FormPages.CYA) {
24
24
  return {};
25
25
  }
26
26
 
@@ -11,23 +11,23 @@ describe('components', function () {
11
11
  describe('FormRenderer', function () {
12
12
  describe('helpers', function () {
13
13
  var HUB = {
14
- id: 'hub',
14
+ id: _models.FormPages.HUB,
15
15
  components: []
16
16
  };
17
17
  describe('getCYA', function () {
18
18
  it('should give an empty object if the pageId is "CYA"', function () {
19
- expect((0, _getCYA.default)(_models.HubFormats.CYA)).toEqual({});
19
+ expect((0, _getCYA.default)(_models.FormPages.CYA)).toEqual({});
20
20
  });
21
21
  it('should give an object with a blank title if the pageId is "hub" and the hub is the CYA', function () {
22
- expect((0, _getCYA.default)('hub', _models.HubFormats.CYA)).toEqual({
22
+ expect((0, _getCYA.default)(_models.FormPages.HUB, _models.HubFormats.CYA)).toEqual({
23
23
  title: ''
24
24
  });
25
25
  });
26
26
  it('should give undefined if pageId is "hub" and the hub is NOT the CYA', function () {
27
- expect((0, _getCYA.default)('hub', HUB)).toBeUndefined();
27
+ expect((0, _getCYA.default)(_models.FormPages.HUB, HUB)).toBeUndefined();
28
28
  });
29
29
  it('should give undefined if pageId is NOT "hub" and the hub is NOT the CYA', function () {
30
- expect((0, _getCYA.default)('bob', HUB)).toBeUndefined();
30
+ expect((0, _getCYA.default)(_models.FormPages.HUB, HUB)).toBeUndefined();
31
31
  });
32
32
  it('should give undefined if pageId is NOT "hub" and the hub is the CYA', function () {
33
33
  expect((0, _getCYA.default)('bob', _models.HubFormats.CYA)).toBeUndefined();
@@ -11,7 +11,7 @@ describe('components', function () {
11
11
  describe('FormRenderer', function () {
12
12
  describe('helpers', function () {
13
13
  var HUB = {
14
- id: 'hub',
14
+ id: _models.FormPages.HUB,
15
15
  components: []
16
16
  };
17
17
  var PAGES = [{
@@ -23,8 +23,8 @@ describe('components', function () {
23
23
  }, HUB];
24
24
  describe('getFormState', function () {
25
25
  it('should set up accordingly when viewing a hub that is the CYA', function () {
26
- expect((0, _getFormState.default)('hub', PAGES, _models.HubFormats.CYA)).toEqual({
27
- pageId: 'hub',
26
+ expect((0, _getFormState.default)(_models.FormPages.HUB, PAGES, _models.HubFormats.CYA)).toEqual({
27
+ pageId: _models.FormPages.HUB,
28
28
  cya: {
29
29
  title: ''
30
30
  },
@@ -32,15 +32,15 @@ describe('components', function () {
32
32
  });
33
33
  });
34
34
  it('should set up accordingly when viewing a hub that is NOT the CYA', function () {
35
- expect((0, _getFormState.default)('hub', PAGES, HUB)).toEqual({
36
- pageId: 'hub',
35
+ expect((0, _getFormState.default)(_models.FormPages.HUB, PAGES, HUB)).toEqual({
36
+ pageId: _models.FormPages.HUB,
37
37
  cya: undefined,
38
38
  page: HUB
39
39
  });
40
40
  });
41
41
  it('should set up accordingly when viewing the CYA', function () {
42
- expect((0, _getFormState.default)(_models.HubFormats.CYA, PAGES, HUB)).toEqual({
43
- pageId: _models.HubFormats.CYA,
42
+ expect((0, _getFormState.default)(_models.FormPages.CYA, PAGES, HUB)).toEqual({
43
+ pageId: _models.FormPages.CYA,
44
44
  cya: {},
45
45
  page: undefined
46
46
  });
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _models = require("../../../models");
9
+
10
+ var getNextHubPageId = function getNextHubPageId(action) {
11
+ if ((action === null || action === void 0 ? void 0 : action.type) === _models.PageAction.TYPES.SAVE_AND_RETURN) {
12
+ return _models.FormPages.HUB;
13
+ }
14
+
15
+ return (action === null || action === void 0 ? void 0 : action.nextPageId) || _models.FormPages.HUB;
16
+ };
17
+
18
+ var getNextCYAPageId = function getNextCYAPageId(pages, currentPageId, action) {
19
+ if ((action === null || action === void 0 ? void 0 : action.type) === _models.PageAction.TYPES.SAVE_AND_RETURN) {
20
+ return undefined;
21
+ }
22
+
23
+ var nextIndex = pages.findIndex(function (p) {
24
+ return p.id === currentPageId;
25
+ }) + 1;
26
+ return nextIndex < pages.length ? pages[nextIndex].id : _models.FormPages.CYA;
27
+ };
28
+
29
+ var getNextWizardPageId = function getNextWizardPageId(pages, currentPageId, action) {
30
+ if ((action === null || action === void 0 ? void 0 : action.type) === _models.PageAction.TYPES.SAVE_AND_RETURN) {
31
+ return undefined;
32
+ }
33
+
34
+ var nextIndex = pages.findIndex(function (p) {
35
+ return p.id === currentPageId;
36
+ }) + 1;
37
+ return nextIndex < pages.length ? pages[nextIndex].id : undefined;
38
+ };
39
+
40
+ var getNextFormPageId = function getNextFormPageId(pages, action) {
41
+ if ((action === null || action === void 0 ? void 0 : action.type) === _models.PageAction.TYPES.SAVE_AND_RETURN) {
42
+ return undefined;
43
+ }
44
+
45
+ return pages.length > 0 ? pages[0].id : undefined;
46
+ };
47
+
48
+ var getNextPageId = function getNextPageId(formType, pages, currentPageId, action) {
49
+ switch (formType) {
50
+ case _models.FormTypes.HUB:
51
+ return getNextHubPageId(action);
52
+
53
+ case _models.FormTypes.CYA:
54
+ return getNextCYAPageId(pages, currentPageId, action);
55
+
56
+ case _models.FormTypes.WIZARD:
57
+ return getNextWizardPageId(pages, currentPageId, action);
58
+
59
+ default:
60
+ return getNextFormPageId(pages, action);
61
+ }
62
+ };
63
+
64
+ var _default = getNextPageId;
65
+ exports.default = _default;
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+
3
+ var _models = require("../../../models");
4
+
5
+ var _getNextPageId = _interopRequireDefault(require("./getNextPageId"));
6
+
7
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
+
9
+ // Local imports
10
+ describe('components', function () {
11
+ describe('FormRenderer', function () {
12
+ describe('helpers', function () {
13
+ describe('getNextPageId', function () {
14
+ var PAGES = [{
15
+ id: 'alpha'
16
+ }, {
17
+ id: 'bravo'
18
+ }];
19
+ describe("when the form type is '".concat(_models.FormTypes.HUB, "'"), function () {
20
+ var FORM_TYPE = _models.FormTypes.HUB;
21
+ it("should return '".concat(_models.FormPages.HUB, "' by default"), function () {
22
+ expect((0, _getNextPageId.default)(FORM_TYPE, PAGES)).toEqual(_models.FormPages.HUB);
23
+ });
24
+ it("should return '".concat(_models.FormPages.HUB, "' if the action is '").concat(_models.PageAction.TYPES.SAVE_AND_RETURN, "'"), function () {
25
+ var ACTION = _models.PageAction.DEFAULTS.saveAndReturn;
26
+ expect((0, _getNextPageId.default)(FORM_TYPE, PAGES, PAGES[0].id, ACTION)).toEqual(_models.FormPages.HUB);
27
+ });
28
+ it('should return action.nextPageId if specified', function () {
29
+ var ACTION = {
30
+ nextPageId: 'bob'
31
+ };
32
+ expect((0, _getNextPageId.default)(FORM_TYPE, PAGES, undefined, ACTION)).toEqual(ACTION.nextPageId);
33
+ });
34
+ });
35
+ describe("when the form type is '".concat(_models.FormTypes.CYA, "'"), function () {
36
+ var FORM_TYPE = _models.FormTypes.CYA;
37
+ it('should return the first page by default', function () {
38
+ expect((0, _getNextPageId.default)(FORM_TYPE, PAGES)).toEqual(PAGES[0].id);
39
+ });
40
+ it('should return the second page when on the first page', function () {
41
+ expect((0, _getNextPageId.default)(FORM_TYPE, PAGES, PAGES[0].id)).toEqual(PAGES[1].id);
42
+ });
43
+ it("should return '".concat(_models.FormPages.CYA, "' when on the last page"), function () {
44
+ expect((0, _getNextPageId.default)(FORM_TYPE, PAGES, PAGES[PAGES.length - 1].id)).toEqual(_models.FormPages.CYA);
45
+ });
46
+ it("should return undefined if the action is '".concat(_models.PageAction.TYPES.SAVE_AND_RETURN, "'"), function () {
47
+ var ACTION = _models.PageAction.DEFAULTS.saveAndReturn;
48
+ expect((0, _getNextPageId.default)(FORM_TYPE, PAGES, PAGES[0].id, ACTION)).toBeUndefined();
49
+ });
50
+ });
51
+ describe("when the form type is '".concat(_models.FormTypes.WIZARD, "'"), function () {
52
+ var FORM_TYPE = _models.FormTypes.WIZARD;
53
+ it('should return the first page by default', function () {
54
+ expect((0, _getNextPageId.default)(FORM_TYPE, PAGES)).toEqual(PAGES[0].id);
55
+ });
56
+ it('should return the second page when on the first page', function () {
57
+ expect((0, _getNextPageId.default)(FORM_TYPE, PAGES, PAGES[0].id)).toEqual(PAGES[1].id);
58
+ });
59
+ it('should return undefined when on the last page', function () {
60
+ expect((0, _getNextPageId.default)(FORM_TYPE, PAGES, PAGES[PAGES.length - 1].id)).toBeUndefined();
61
+ });
62
+ it("should return undefined if the action is '".concat(_models.PageAction.TYPES.SAVE_AND_RETURN, "'"), function () {
63
+ var ACTION = _models.PageAction.DEFAULTS.saveAndReturn;
64
+ expect((0, _getNextPageId.default)(FORM_TYPE, PAGES, PAGES[0].id, ACTION)).toBeUndefined();
65
+ });
66
+ });
67
+ describe("when the form type is '".concat(_models.FormTypes.FORM, "'"), function () {
68
+ var FORM_TYPE = _models.FormTypes.FORM;
69
+ it("should always return the first page if there any pages and the action is not '".concat(_models.PageAction.TYPES.SAVE_AND_RETURN, "'"), function () {
70
+ var ACTION = {
71
+ type: _models.PageAction.TYPES.SUBMIT,
72
+ nextPageId: 'bob'
73
+ };
74
+ expect((0, _getNextPageId.default)(FORM_TYPE, PAGES)).toEqual(PAGES[0].id);
75
+ expect((0, _getNextPageId.default)(FORM_TYPE, PAGES, PAGES[0].id)).toEqual(PAGES[0].id);
76
+ expect((0, _getNextPageId.default)(FORM_TYPE, PAGES, PAGES[1].id)).toEqual(PAGES[0].id);
77
+ expect((0, _getNextPageId.default)(FORM_TYPE, PAGES, PAGES[0].id, ACTION)).toEqual(PAGES[0].id);
78
+ });
79
+ it("should return undefined if the action is '".concat(_models.PageAction.TYPES.SAVE_AND_RETURN, "'"), function () {
80
+ var ACTION = _models.PageAction.DEFAULTS.saveAndReturn;
81
+ expect((0, _getNextPageId.default)(FORM_TYPE, PAGES, PAGES[0].id, ACTION)).toBeUndefined();
82
+ });
83
+ it('should return undefined if there are no pages', function () {
84
+ expect((0, _getNextPageId.default)(FORM_TYPE, [])).toBeUndefined();
85
+ });
86
+ });
87
+ });
88
+ });
89
+ });
90
+ });
@@ -18,7 +18,7 @@ var _models = require("../../../models");
18
18
  */
19
19
  var getPage = function getPage(pageId, pages, hub) {
20
20
  if (pageId) {
21
- if (pageId === 'hub') {
21
+ if (pageId === _models.FormPages.HUB) {
22
22
  return hub === _models.HubFormats.CYA ? undefined : hub;
23
23
  }
24
24
 
@@ -11,7 +11,7 @@ describe('components', function () {
11
11
  describe('FormRenderer', function () {
12
12
  describe('helpers', function () {
13
13
  var HUB = {
14
- id: 'hub',
14
+ id: _models.FormPages.HUB,
15
15
  components: []
16
16
  };
17
17
  var PAGES = [{
@@ -26,10 +26,10 @@ describe('components', function () {
26
26
  expect((0, _getPage.default)(undefined, PAGES, _models.HubFormats.CYA)).toBeUndefined();
27
27
  });
28
28
  it('should give undefined if the pageId is "hub" but the hub is the CYA', function () {
29
- expect((0, _getPage.default)('hub', PAGES, _models.HubFormats.CYA)).toBeUndefined();
29
+ expect((0, _getPage.default)(_models.FormPages.HUB, PAGES, _models.HubFormats.CYA)).toBeUndefined();
30
30
  });
31
31
  it('should give hub if the pageId is "hub" and the hub is NOT the CYA', function () {
32
- expect((0, _getPage.default)('hub', PAGES, HUB)).toEqual(HUB);
32
+ expect((0, _getPage.default)(_models.FormPages.HUB, PAGES, HUB)).toEqual(HUB);
33
33
  });
34
34
  it('should give find the appropriate page if the pageId is not "hub"', function () {
35
35
  expect((0, _getPage.default)('alpha', PAGES, HUB)).toEqual({
@@ -3,21 +3,25 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "canActionProceed", {
7
- enumerable: true,
8
- get: function get() {
9
- return _canActionProceed.default;
10
- }
11
- });
12
- Object.defineProperty(exports, "getFormState", {
13
- enumerable: true,
14
- get: function get() {
15
- return _getFormState.default;
16
- }
17
- });
6
+ exports.helpers = exports.default = void 0;
18
7
 
19
8
  var _canActionProceed = _interopRequireDefault(require("./canActionProceed"));
20
9
 
10
+ var _canCYASubmit = _interopRequireDefault(require("./canCYASubmit"));
11
+
21
12
  var _getFormState = _interopRequireDefault(require("./getFormState"));
22
13
 
23
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+ var _getNextPageId = _interopRequireDefault(require("./getNextPageId"));
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
18
+ // Local imports
19
+ var helpers = {
20
+ canActionProceed: _canActionProceed.default,
21
+ canCYASubmit: _canCYASubmit.default,
22
+ getFormState: _getFormState.default,
23
+ getNextPageId: _getNextPageId.default
24
+ };
25
+ exports.helpers = helpers;
26
+ var _default = helpers;
27
+ exports.default = _default;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = exports.DEFAULT_LABEL = exports.DEFAULT_ACTIONS = void 0;
6
+ exports.default = exports.DEFAULT_LABEL = void 0;
7
7
 
8
8
  var _copReactComponents = require("@ukhomeoffice/cop-react-components");
9
9
 
@@ -11,6 +11,8 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
11
11
 
12
12
  var _react = _interopRequireDefault(require("react"));
13
13
 
14
+ var _models = require("../../models");
15
+
14
16
  var _excluded = ["action", "onAction"];
15
17
 
16
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -23,20 +25,13 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
23
25
 
24
26
  var DEFAULT_LABEL = 'Continue';
25
27
  exports.DEFAULT_LABEL = DEFAULT_LABEL;
26
- var DEFAULT_ACTIONS = {
27
- submit: {
28
- type: 'submit',
29
- validate: true
30
- }
31
- };
32
- exports.DEFAULT_ACTIONS = DEFAULT_ACTIONS;
33
28
 
34
29
  var ActionButton = function ActionButton(_ref) {
35
30
  var _action = _ref.action,
36
31
  onAction = _ref.onAction,
37
32
  attrs = _objectWithoutProperties(_ref, _excluded);
38
33
 
39
- var action = typeof _action === 'string' ? DEFAULT_ACTIONS[_action] : _action;
34
+ var action = typeof _action === 'string' ? _models.PageAction.DEFAULTS[_action] : _action;
40
35
 
41
36
  if (!action) {
42
37
  return null;
@@ -45,6 +40,7 @@ var ActionButton = function ActionButton(_ref) {
45
40
  return /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, _extends({}, attrs, {
46
41
  className: action.className,
47
42
  classModifiers: action.classModifiers,
43
+ start: action.start || false,
48
44
  onClick: function onClick() {
49
45
  return onAction(action);
50
46
  }
@@ -6,6 +6,8 @@ var _react = require("@testing-library/react");
6
6
 
7
7
  var _react2 = _interopRequireDefault(require("react"));
8
8
 
9
+ var _models = require("../../models");
10
+
9
11
  var _ActionButton = _interopRequireWildcard(require("./ActionButton"));
10
12
 
11
13
  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); }
@@ -69,7 +71,7 @@ describe('components', function () {
69
71
  _react.fireEvent.click(button, {});
70
72
 
71
73
  expect(ON_ACTION_CALLS.length).toEqual(1);
72
- expect(ON_ACTION_CALLS[0]).toEqual(_ActionButton.DEFAULT_ACTIONS.submit);
74
+ expect(ON_ACTION_CALLS[0]).toEqual(_models.PageAction.DEFAULTS.submit);
73
75
 
74
76
  case 8:
75
77
  case "end":