@ukhomeoffice/cop-react-form-renderer 1.0.0-gamma → 2.1.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 (74) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -0
  3. package/dist/components/CheckYourAnswers/CheckYourAnswers.js +16 -5
  4. package/dist/components/CheckYourAnswers/CheckYourAnswers.stories.mdx +199 -79
  5. package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +44 -0
  6. package/dist/components/FormPage/FormPage.js +8 -2
  7. package/dist/components/FormPage/FormPage.test.js +3 -3
  8. package/dist/components/FormRenderer/FormRenderer.js +44 -16
  9. package/dist/components/FormRenderer/FormRenderer.stories.mdx +115 -49
  10. package/dist/components/FormRenderer/FormRenderer.test.js +40 -0
  11. package/dist/components/FormRenderer/handlers/getPageId.js +1 -10
  12. package/dist/components/FormRenderer/handlers/getPageId.test.js +5 -31
  13. package/dist/components/FormRenderer/handlers/handlers.test.js +2 -2
  14. package/dist/components/FormRenderer/helpers/getNextPageId.js +33 -26
  15. package/dist/components/FormRenderer/helpers/getNextPageId.test.js +89 -7
  16. package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +27 -0
  17. package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +209 -0
  18. package/dist/components/FormRenderer/helpers/index.js +4 -1
  19. package/dist/components/PageActions/ActionButton.test.js +1 -1
  20. package/dist/components/PageActions/PageActions.stories.mdx +1 -1
  21. package/dist/components/PageActions/PageActions.test.js +5 -5
  22. package/dist/components/SummaryList/RowAction.js +1 -1
  23. package/dist/components/SummaryList/RowAction.test.js +6 -6
  24. package/dist/components/SummaryList/SummaryList.js +8 -5
  25. package/dist/components/SummaryList/SummaryList.scss +10 -2
  26. package/dist/components/SummaryList/SummaryList.stories.mdx +64 -10
  27. package/dist/components/SummaryList/SummaryList.test.js +54 -0
  28. package/dist/components/SummaryList/helpers/getRowActionAttributes.js +2 -2
  29. package/dist/components/SummaryList/helpers/getRowActionAttributes.test.js +4 -4
  30. package/dist/components/index.js +8 -0
  31. package/dist/index.js +8 -0
  32. package/dist/json/areYouACivilServant.json +7 -0
  33. package/dist/json/firstForm.json +94 -0
  34. package/dist/json/grade.json +108 -0
  35. package/dist/json/saveAndContinue.json +98 -0
  36. package/dist/json/team.json +17351 -0
  37. package/dist/json/userProfile.data.json +14 -0
  38. package/dist/json/userProfile.json +276 -0
  39. package/dist/models/ComponentTypes.js +7 -1
  40. package/dist/models/PageAction.js +9 -7
  41. package/dist/utils/CheckYourAnswers/getCYAAction.js +24 -3
  42. package/dist/utils/CheckYourAnswers/getCYAAction.test.js +62 -15
  43. package/dist/utils/CheckYourAnswers/getCYARow.js +8 -2
  44. package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +11 -5
  45. package/dist/utils/Component/getComponent.js +32 -0
  46. package/dist/utils/Component/getComponentTests/getComponent.autocomplete.test.js +75 -0
  47. package/dist/utils/Component/getComponentTests/getComponent.checkboxes.test.js +129 -0
  48. package/dist/utils/Component/getComponentTests/getComponent.date.test.js +129 -0
  49. package/dist/utils/Component/getComponentTests/getComponent.email.test.js +80 -0
  50. package/dist/utils/Component/getComponentTests/getComponent.heading.test.js +33 -0
  51. package/dist/utils/Component/getComponentTests/getComponent.html.test.js +45 -0
  52. package/dist/utils/Component/getComponentTests/getComponent.insetText.test.js +31 -0
  53. package/dist/utils/Component/getComponentTests/getComponent.phoneNumber.test.js +80 -0
  54. package/dist/utils/Component/getComponentTests/getComponent.radios.test.js +125 -0
  55. package/dist/utils/Component/getComponentTests/getComponent.text.test.js +80 -0
  56. package/dist/utils/Component/getComponentTests/getComponent.textarea.test.js +76 -0
  57. package/dist/utils/Component/getComponentTests/getComponent.unknown.test.js +14 -0
  58. package/dist/utils/Component/isEditable.js +1 -1
  59. package/dist/utils/Data/refDataToOptions.js +4 -0
  60. package/dist/utils/Data/refDataToOptions.test.js +30 -0
  61. package/dist/utils/FormPage/getEditableComponents.js +28 -0
  62. package/dist/utils/FormPage/getEditableComponents.test.js +75 -0
  63. package/dist/utils/FormPage/getFormPage.js +5 -1
  64. package/dist/utils/FormPage/getPageActions.js +66 -0
  65. package/dist/utils/FormPage/getPageActions.test.js +89 -0
  66. package/dist/utils/FormPage/index.js +7 -1
  67. package/dist/utils/FormPage/showFormPage.js +81 -0
  68. package/dist/utils/FormPage/showFormPage.test.js +131 -0
  69. package/dist/utils/Validate/validateComponent.js +5 -3
  70. package/dist/utils/Validate/validateRequired.js +11 -0
  71. package/dist/utils/Validate/validateRequired.test.js +12 -0
  72. package/package.json +15 -10
  73. package/dist/index.test.js +0 -18
  74. package/dist/utils/Component/getComponent.test.js +0 -329
@@ -1,14 +1,23 @@
1
1
  <!-- Global imports -->
2
+
2
3
  import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
3
- import { Button, Details, Heading, Link, Panel } from '@ukhomeoffice/cop-react-components';
4
+ import {
5
+ Button,
6
+ Details,
7
+ Heading,
8
+ Link,
9
+ Panel,
10
+ } from '@ukhomeoffice/cop-react-components';
4
11
  import { useState } from 'react';
5
12
  import withMock from 'storybook-addon-mock';
6
13
 
7
14
  <!-- Local imports -->
15
+
8
16
  import { addHook } from '../../hooks/useHooks';
9
17
  import FormRenderer from './FormRenderer';
10
18
 
11
19
  <!-- JSON documents -->
20
+
12
21
  import CIVIL_SERVANT from '../../json/areYouACivilServant.json';
13
22
  import FIRST_FORM from '../../json/firstForm.json';
14
23
  import GRADE from '../../json/grade.json';
@@ -16,52 +25,60 @@ import TEAMS from '../../json/team.json';
16
25
  import USER_PROFILE_DATA from '../../json/userProfile.data.json';
17
26
  import USER_PROFILE from '../../json/userProfile.json';
18
27
 
19
- <Meta title="Components/Form renderer" id="D-FormRenderer" component={ FormRenderer } decorators={[withMock]} />
28
+ <Meta
29
+ title='Components/Form renderer'
30
+ id='D-FormRenderer'
31
+ component={FormRenderer}
32
+ decorators={[withMock]}
33
+ />
20
34
 
21
- <Heading size="xl" caption="Components">Form renderer</Heading>
35
+ <Heading size='xl' caption='Components'>
36
+ Form renderer
37
+ </Heading>
22
38
 
23
39
  Renders a form with <Link href="https://ukhomeoffice.github.io/cop-react-components/?path=/docs/d-alert--default-story">COP React components</Link>,
24
40
  on the basis of a <Link href="/?path=/docs/f-json-form">JSON</Link> that describes which elements are required.
25
41
 
26
42
  <Canvas withToolbar>
27
- <Story name="Default" parameters={{
28
- mockData: [
29
- {
30
- url: `${USER_PROFILE_DATA.urls.refData}/areYouACivilServant`,
31
- method: 'GET',
32
- status: 200,
33
- response: CIVIL_SERVANT
34
- },
35
- {
36
- url: `${USER_PROFILE_DATA.urls.refData}/grade`,
37
- method: 'GET',
38
- status: 200,
39
- response: GRADE
40
- },
41
- {
42
- url: `${USER_PROFILE_DATA.urls.refData}/team`,
43
- method: 'GET',
44
- status: 200,
45
- response: TEAMS
46
- }
47
- ]
48
- }}>
43
+ <Story
44
+ name='Default'
45
+ parameters={{
46
+ mockData: [
47
+ {
48
+ url: `${USER_PROFILE_DATA.urls.refData}/areYouACivilServant`,
49
+ method: 'GET',
50
+ status: 200,
51
+ response: CIVIL_SERVANT,
52
+ },
53
+ {
54
+ url: `${USER_PROFILE_DATA.urls.refData}/grade`,
55
+ method: 'GET',
56
+ status: 200,
57
+ response: GRADE,
58
+ },
59
+ {
60
+ url: `${USER_PROFILE_DATA.urls.refData}/team`,
61
+ method: 'GET',
62
+ status: 200,
63
+ response: TEAMS,
64
+ },
65
+ ],
66
+ }}
67
+ >
49
68
  {() => {
50
- return (
51
- <FormRenderer {...USER_PROFILE} data={USER_PROFILE_DATA} />
52
- );
69
+ return <FormRenderer {...USER_PROFILE} data={USER_PROFILE_DATA} />;
53
70
  }}
54
71
  </Story>
55
72
  </Canvas>
56
73
 
57
- <Details summary="Properties" className="no-indent">
58
- <ArgsTable of={ FormRenderer } />
74
+ <Details summary='Properties' className='no-indent'>
75
+ <ArgsTable of={FormRenderer} />
59
76
  </Details>
60
77
 
61
78
  ## CYA type
62
79
 
63
80
  <Canvas>
64
- <Story name="CYA">
81
+ <Story name='CYA'>
65
82
  {() => {
66
83
  const [complete, setComplete] = useState(false);
67
84
  const [returnLater, setReturnLater] = useState(false);
@@ -82,7 +99,12 @@ on the basis of a <Link href="/?path=/docs/f-json-form">JSON</Link> that describ
82
99
  setReturnLater(!!pageId === false);
83
100
  });
84
101
  addHook('onSubmit', (type, payload, onSuccess, onError) => {
85
- console.log('onSubmit called of type', type, 'called, with the payload', payload);
102
+ console.log(
103
+ 'onSubmit called of type',
104
+ type,
105
+ 'called, with the payload',
106
+ payload
107
+ );
86
108
  onSuccess();
87
109
  });
88
110
  const reset = () => {
@@ -91,25 +113,69 @@ on the basis of a <Link href="/?path=/docs/f-json-form">JSON</Link> that describ
91
113
  };
92
114
  return (
93
115
  <>
94
- {!complete && !returnLater && <FormRenderer {...FIRST_FORM} data={{}} />}
95
- {complete &&
96
- <div>
97
- <Panel title="Submission successful">
98
- Your submission was successful.
99
- </Panel>
100
- <Button onClick={() => reset()}>Start again</Button>
101
- </div>
102
- }
103
- {!complete && returnLater &&
104
- <div>
105
- <Panel title="Saved to return later">
106
- You clicked on "Save and return later".
107
- </Panel>
108
- <Button onClick={() => reset()}>Start again</Button>
109
- </div>
110
- }
116
+ {!complete && !returnLater && (
117
+ <FormRenderer {...FIRST_FORM} data={{}} />
118
+ )}
119
+ {complete && (
120
+ <div>
121
+ <Panel title='Submission successful'>
122
+ Your submission was successful.
123
+ </Panel>
124
+ <Button onClick={() => reset()}>Start again</Button>
125
+ </div>
126
+ )}
127
+ {!complete && returnLater && (
128
+ <div>
129
+ <Panel title='Saved to return later'>
130
+ You clicked on "Save and return later".
131
+ </Panel>
132
+ <Button onClick={() => reset()}>Start again</Button>
133
+ </div>
134
+ )}
111
135
  </>
112
136
  );
113
137
  }}
114
138
  </Story>
115
139
  </Canvas>
140
+
141
+ ## Read-only style
142
+
143
+ <Canvas>
144
+ <Story
145
+ name='Read-only style'
146
+ parameters={{
147
+ mockData: [
148
+ {
149
+ url: `${USER_PROFILE_DATA.urls.refData}/areYouACivilServant`,
150
+ method: 'GET',
151
+ status: 200,
152
+ response: CIVIL_SERVANT,
153
+ },
154
+ {
155
+ url: `${USER_PROFILE_DATA.urls.refData}/grade`,
156
+ method: 'GET',
157
+ status: 200,
158
+ response: GRADE,
159
+ },
160
+ {
161
+ url: `${USER_PROFILE_DATA.urls.refData}/team`,
162
+ method: 'GET',
163
+ status: 200,
164
+ response: TEAMS,
165
+ },
166
+ ],
167
+ }}
168
+ >
169
+ {() => {
170
+ return (
171
+ <FormRenderer
172
+ {...USER_PROFILE}
173
+ data={USER_PROFILE_DATA}
174
+ summaryListClassModifiers='no-border'
175
+ hide_title={true}
176
+ noChangeAction={true}
177
+ />
178
+ );
179
+ }}
180
+ </Story>
181
+ </Canvas>
@@ -467,5 +467,45 @@ describe('components', function () {
467
467
  }
468
468
  }, _callee12);
469
469
  })));
470
+ it('should show no title when hide_title is set to true', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee14() {
471
+ var form, hub;
472
+ return regeneratorRuntime.wrap(function _callee14$(_context14) {
473
+ while (1) {
474
+ switch (_context14.prev = _context14.next) {
475
+ case 0:
476
+ _context14.next = 2;
477
+ return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee13() {
478
+ return regeneratorRuntime.wrap(function _callee13$(_context13) {
479
+ while (1) {
480
+ switch (_context13.prev = _context13.next) {
481
+ case 0:
482
+ (0, _reactDom.render)( /*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, _userProfile.default, {
483
+ data: _userProfileData.default,
484
+ hide_title: true
485
+ })), container);
486
+
487
+ case 1:
488
+ case "end":
489
+ return _context13.stop();
490
+ }
491
+ }
492
+ }, _callee13);
493
+ })));
494
+
495
+ case 2:
496
+ form = checkForm(container);
497
+ expect(form.childNodes.length).toEqual(1); //Hub page (= CYA)
498
+
499
+ hub = form.childNodes[0];
500
+ expect(hub.tagName).toEqual('DIV');
501
+ expect(hub.classList).toContain(_CheckYourAnswers.DEFAULT_CLASS);
502
+
503
+ case 7:
504
+ case "end":
505
+ return _context14.stop();
506
+ }
507
+ }
508
+ }, _callee14);
509
+ })));
470
510
  });
471
511
  });
@@ -12,16 +12,7 @@ exports.default = void 0;
12
12
  * @returns A page id.
13
13
  */
14
14
  var getPageId = function getPageId(action, pageId) {
15
- if (action) {
16
- // TODO: Improve how this is handled.
17
- if (action.href) {
18
- return action.href.split('/').pop();
19
- } else if (action.url) {
20
- return action.url.split('/').pop();
21
- }
22
- }
23
-
24
- return pageId;
15
+ return (action === null || action === void 0 ? void 0 : action.page) || pageId;
25
16
  };
26
17
 
27
18
  var _default = getPageId;
@@ -14,46 +14,20 @@ describe('components', function () {
14
14
  var ACTION = null;
15
15
  expect((0, _getPageId.default)(ACTION, PAGE_ID)).toEqual(PAGE_ID);
16
16
  });
17
- it('should return the pageId when the action contains no href or url', function () {
17
+ it('should return the pageId when the action contains no page', function () {
18
18
  var PAGE_ID = 'alpha';
19
19
  var ACTION = {
20
20
  id: 'bravo'
21
21
  };
22
22
  expect((0, _getPageId.default)(ACTION, PAGE_ID)).toEqual(PAGE_ID);
23
23
  });
24
- it('should return the final part of the href when provided', function () {
25
- var LAST_PART = 'delta';
26
- var HREF = "/bravo/charlie/".concat(LAST_PART);
24
+ it('should return the page when provided', function () {
25
+ var NAVIGATE_TO = 'delta';
27
26
  var PAGE_ID = 'alpha';
28
27
  var ACTION = {
29
- href: HREF
28
+ page: NAVIGATE_TO
30
29
  };
31
- expect((0, _getPageId.default)(ACTION, PAGE_ID)).toEqual(LAST_PART);
32
- });
33
- it('should return the final part of the url when provided', function () {
34
- var LAST_PART = 'delta';
35
- var URL = "/bravo/charlie/".concat(LAST_PART);
36
- var PAGE_ID = 'alpha';
37
- var ACTION = {
38
- url: URL
39
- };
40
- expect((0, _getPageId.default)(ACTION, PAGE_ID)).toEqual(LAST_PART);
41
- });
42
- it('should return the whole href when it contains no backslashes', function () {
43
- var HREF = 'delta';
44
- var PAGE_ID = 'alpha';
45
- var ACTION = {
46
- href: HREF
47
- };
48
- expect((0, _getPageId.default)(ACTION, PAGE_ID)).toEqual(HREF);
49
- });
50
- it('should return the whole url when it contains no backslashes', function () {
51
- var URL = 'delta';
52
- var PAGE_ID = 'alpha';
53
- var ACTION = {
54
- url: URL
55
- };
56
- expect((0, _getPageId.default)(ACTION, PAGE_ID)).toEqual(URL);
30
+ expect((0, _getPageId.default)(ACTION, PAGE_ID)).toEqual(NAVIGATE_TO);
57
31
  });
58
32
  });
59
33
  });
@@ -46,7 +46,7 @@ describe('components', function () {
46
46
  it('should not call the onNavigate method when the page is unchanged', function () {
47
47
  var CURRENT_PAGE_ID = 'alpha';
48
48
  var ACTION = {
49
- href: "/".concat(CURRENT_PAGE_ID)
49
+ page: CURRENT_PAGE_ID
50
50
  };
51
51
  var ON_NAVIGATE_CALLS = [];
52
52
 
@@ -62,7 +62,7 @@ describe('components', function () {
62
62
  var CURRENT_PAGE_ID = 'alpha';
63
63
  var NEW_PAGE_ID = 'bravo';
64
64
  var ACTION = {
65
- href: "/".concat(NEW_PAGE_ID)
65
+ page: NEW_PAGE_ID
66
66
  };
67
67
  var ON_NAVIGATE_CALLS = [];
68
68
 
@@ -7,57 +7,64 @@ exports.default = void 0;
7
7
 
8
8
  var _models = require("../../../models");
9
9
 
10
+ var _FormPage = _interopRequireDefault(require("../../../utils/FormPage"));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
10
14
  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
- }
15
+ return (action === null || action === void 0 ? void 0 : action.page) || _models.FormPages.HUB;
16
+ };
14
17
 
15
- return (action === null || action === void 0 ? void 0 : action.nextPageId) || _models.FormPages.HUB;
18
+ var getNextCYAPageId = function getNextCYAPageId(pages, currentPageId, formData) {
19
+ return getNextWizardPageId(pages, currentPageId, formData) || _models.FormPages.CYA;
16
20
  };
17
21
 
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
+ var getNextWizardPageId = function getNextWizardPageId(pages, currentPageId, formData) {
23
+ var _page;
22
24
 
23
25
  var nextIndex = pages.findIndex(function (p) {
24
26
  return p.id === currentPageId;
25
27
  }) + 1;
26
- return nextIndex < pages.length ? pages[nextIndex].id : _models.FormPages.CYA;
27
- };
28
+ var page = pages[nextIndex];
28
29
 
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;
30
+ while (page && !_FormPage.default.show(page, formData)) {
31
+ nextIndex++;
32
+ page = pages[nextIndex];
32
33
  }
33
34
 
34
- var nextIndex = pages.findIndex(function (p) {
35
- return p.id === currentPageId;
36
- }) + 1;
37
- return nextIndex < pages.length ? pages[nextIndex].id : undefined;
35
+ return ((_page = page) === null || _page === void 0 ? void 0 : _page.id) || undefined;
38
36
  };
39
37
 
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
-
38
+ var getNextFormPageId = function getNextFormPageId(pages) {
39
+ // A form has a single page... so always return that id.
45
40
  return pages.length > 0 ? pages[0].id : undefined;
46
41
  };
47
42
 
48
- var getNextPageId = function getNextPageId(formType, pages, currentPageId, action) {
43
+ var getNextPageId = function getNextPageId(formType, pages, currentPageId, action, formData) {
44
+ if (action) {
45
+ if (action.type === _models.PageAction.TYPES.NAVIGATE) {
46
+ return pages.find(function (p) {
47
+ return p.id === action.page;
48
+ }) ? action.page : undefined;
49
+ }
50
+
51
+ if (action.type === _models.PageAction.TYPES.SAVE_AND_RETURN) {
52
+ return formType === _models.FormTypes.HUB ? _models.FormPages.HUB : undefined;
53
+ }
54
+ }
55
+
49
56
  switch (formType) {
50
57
  case _models.FormTypes.HUB:
51
58
  return getNextHubPageId(action);
52
59
 
53
60
  case _models.FormTypes.CYA:
54
- return getNextCYAPageId(pages, currentPageId, action);
61
+ return getNextCYAPageId(pages, currentPageId, formData);
55
62
 
56
63
  case _models.FormTypes.WIZARD:
57
- return getNextWizardPageId(pages, currentPageId, action);
64
+ return getNextWizardPageId(pages, currentPageId, formData);
58
65
 
59
66
  default:
60
- return getNextFormPageId(pages, action);
67
+ return getNextFormPageId(pages);
61
68
  }
62
69
  };
63
70
 
@@ -11,11 +11,87 @@ describe('components', function () {
11
11
  describe('FormRenderer', function () {
12
12
  describe('helpers', function () {
13
13
  describe('getNextPageId', function () {
14
+ var OPTIONS = [{
15
+ value: 'romeo',
16
+ label: 'Romeo'
17
+ }, {
18
+ value: 'juliet',
19
+ label: 'Juliet'
20
+ }];
21
+ var RADIOS = {
22
+ id: 'radios',
23
+ fieldId: 'radios',
24
+ type: _models.ComponentTypes.RADIOS,
25
+ data: {
26
+ options: OPTIONS
27
+ }
28
+ };
29
+ var TEXT = {
30
+ id: 'text',
31
+ fieldId: 'text',
32
+ type: _models.ComponentTypes.TEXT
33
+ };
34
+ var HTML = {
35
+ type: _models.ComponentTypes.HTML,
36
+ content: 'HTML'
37
+ };
38
+ var SHOW_WHEN_JULIET = {
39
+ field: RADIOS.fieldId,
40
+ op: '=',
41
+ value: OPTIONS[1].value
42
+ };
43
+ var SHOW_WHEN_ROMEO = {
44
+ field: RADIOS.fieldId,
45
+ op: '=',
46
+ value: OPTIONS[0].value
47
+ };
48
+ var FORM_DATA = {
49
+ radios: OPTIONS[0].value
50
+ }; // 'romeo'
51
+
14
52
  var PAGES = [{
15
53
  id: 'alpha'
16
54
  }, {
17
55
  id: 'bravo'
56
+ }, {
57
+ id: 'charlie',
58
+ components: [RADIOS]
59
+ }, {
60
+ id: 'delta',
61
+ components: [TEXT],
62
+ show_when: SHOW_WHEN_JULIET
63
+ }, {
64
+ id: 'echo',
65
+ components: [HTML]
66
+ }, {
67
+ id: 'foxtrot',
68
+ components: [TEXT],
69
+ show_when: SHOW_WHEN_ROMEO
18
70
  }];
71
+ describe("when the action type is '".concat(_models.PageAction.TYPES.NAVIGATE, "'"), function () {
72
+ it('should return undefined if the action has no page property', function () {
73
+ var ACTION = {
74
+ type: _models.PageAction.TYPES.NAVIGATE
75
+ };
76
+ expect((0, _getNextPageId.default)(_models.FormTypes.HUB, PAGES, PAGES[0].id, ACTION, FORM_DATA)).toBeUndefined();
77
+ });
78
+ it('should return the page on the action if it exists among the pages', function () {
79
+ var PAGE = PAGES[1].id;
80
+ var ACTION = {
81
+ type: _models.PageAction.TYPES.NAVIGATE,
82
+ page: PAGE
83
+ };
84
+ expect((0, _getNextPageId.default)(_models.FormTypes.HUB, PAGES, PAGES[0].id, ACTION, FORM_DATA)).toEqual(PAGE);
85
+ });
86
+ it('should return undefined if the page on the action does not exist among the pages', function () {
87
+ var PAGE = 'golf';
88
+ var ACTION = {
89
+ type: _models.PageAction.TYPES.NAVIGATE,
90
+ page: PAGE
91
+ };
92
+ expect((0, _getNextPageId.default)(_models.FormTypes.HUB, PAGES, PAGES[0].id, ACTION, FORM_DATA)).toBeUndefined();
93
+ });
94
+ });
19
95
  describe("when the form type is '".concat(_models.FormTypes.HUB, "'"), function () {
20
96
  var FORM_TYPE = _models.FormTypes.HUB;
21
97
  it("should return '".concat(_models.FormPages.HUB, "' by default"), function () {
@@ -23,13 +99,13 @@ describe('components', function () {
23
99
  });
24
100
  it("should return '".concat(_models.FormPages.HUB, "' if the action is '").concat(_models.PageAction.TYPES.SAVE_AND_RETURN, "'"), function () {
25
101
  var ACTION = _models.PageAction.DEFAULTS.saveAndReturn;
26
- expect((0, _getNextPageId.default)(FORM_TYPE, PAGES, PAGES[0].id, ACTION)).toEqual(_models.FormPages.HUB);
102
+ expect((0, _getNextPageId.default)(FORM_TYPE, PAGES, PAGES[0].id, ACTION, FORM_DATA)).toEqual(_models.FormPages.HUB);
27
103
  });
28
- it('should return action.nextPageId if specified', function () {
104
+ it('should return action.page if specified', function () {
29
105
  var ACTION = {
30
- nextPageId: 'bob'
106
+ page: 'bob'
31
107
  };
32
- expect((0, _getNextPageId.default)(FORM_TYPE, PAGES, undefined, ACTION)).toEqual(ACTION.nextPageId);
108
+ expect((0, _getNextPageId.default)(FORM_TYPE, PAGES, undefined, ACTION, FORM_DATA)).toEqual(ACTION.page);
33
109
  });
34
110
  });
35
111
  describe("when the form type is '".concat(_models.FormTypes.CYA, "'"), function () {
@@ -40,12 +116,18 @@ describe('components', function () {
40
116
  it('should return the second page when on the first page', function () {
41
117
  expect((0, _getNextPageId.default)(FORM_TYPE, PAGES, PAGES[0].id)).toEqual(PAGES[1].id);
42
118
  });
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);
119
+ it('should return the third page when on the second page', function () {
120
+ expect((0, _getNextPageId.default)(FORM_TYPE, PAGES, PAGES[1].id)).toEqual(PAGES[2].id);
121
+ });
122
+ it("should return the fifth page when on the third page because the fourth page show_when is not met", function () {
123
+ expect((0, _getNextPageId.default)(FORM_TYPE, PAGES, PAGES[2].id, _models.PageAction.DEFAULTS.saveAndContinue, FORM_DATA)).toEqual(PAGES[4].id);
124
+ });
125
+ it("should return the sixth page when on the fifth page because the sixth page show_when is met", function () {
126
+ expect((0, _getNextPageId.default)(FORM_TYPE, PAGES, PAGES[4].id, _models.PageAction.DEFAULTS.saveAndContinue, FORM_DATA)).toEqual(PAGES[5].id);
45
127
  });
46
128
  it("should return undefined if the action is '".concat(_models.PageAction.TYPES.SAVE_AND_RETURN, "'"), function () {
47
129
  var ACTION = _models.PageAction.DEFAULTS.saveAndReturn;
48
- expect((0, _getNextPageId.default)(FORM_TYPE, PAGES, PAGES[0].id, ACTION)).toBeUndefined();
130
+ expect((0, _getNextPageId.default)(FORM_TYPE, PAGES, PAGES[0].id, ACTION, FORM_DATA)).toBeUndefined();
49
131
  });
50
132
  });
51
133
  describe("when the form type is '".concat(_models.FormTypes.WIZARD, "'"), function () {
@@ -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 _models = require("../../../models");
9
+
10
+ var _getNextPageId = _interopRequireDefault(require("./getNextPageId"));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ var getSubmissionStatus = function getSubmissionStatus(formType, pages, currentPageId, action, formData) {
15
+ if ((action === null || action === void 0 ? void 0 : action.type) === _models.PageAction.TYPES.SAVE_AND_RETURN) {
16
+ return {
17
+ page: currentPageId
18
+ };
19
+ }
20
+
21
+ return {
22
+ page: (0, _getNextPageId.default)(formType, pages, currentPageId, action, formData)
23
+ };
24
+ };
25
+
26
+ var _default = getSubmissionStatus;
27
+ exports.default = _default;