@ukhomeoffice/cop-react-form-renderer 1.0.0-delta → 2.0.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.
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +32 -6
- package/dist/components/CheckYourAnswers/CheckYourAnswers.stories.mdx +53 -4
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +17 -2
- package/dist/components/FormPage/FormPage.js +8 -2
- package/dist/components/FormPage/FormPage.test.js +3 -3
- package/dist/components/FormRenderer/FormRenderer.js +54 -9
- package/dist/components/FormRenderer/FormRenderer.stories.mdx +35 -10
- package/dist/components/FormRenderer/FormRenderer.test.js +24 -22
- package/dist/components/FormRenderer/handlers/getPageId.js +1 -10
- package/dist/components/FormRenderer/handlers/getPageId.test.js +5 -31
- package/dist/components/FormRenderer/handlers/handlers.test.js +2 -2
- package/dist/components/FormRenderer/helpers/getNextPageId.js +33 -26
- package/dist/components/FormRenderer/helpers/getNextPageId.test.js +89 -7
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +27 -0
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +209 -0
- package/dist/components/FormRenderer/helpers/index.js +4 -1
- package/dist/components/PageActions/ActionButton.test.js +1 -1
- package/dist/components/PageActions/PageActions.stories.mdx +1 -1
- package/dist/components/PageActions/PageActions.test.js +5 -5
- package/dist/components/SummaryList/RowAction.js +1 -1
- package/dist/components/SummaryList/RowAction.test.js +6 -6
- package/dist/components/SummaryList/SummaryList.js +1 -1
- package/dist/components/SummaryList/helpers/getRowActionAttributes.js +2 -2
- package/dist/components/SummaryList/helpers/getRowActionAttributes.test.js +4 -4
- package/dist/components/index.js +8 -0
- package/dist/json/areYouACivilServant.json +7 -0
- package/dist/json/firstForm.json +94 -0
- package/dist/json/grade.json +108 -0
- package/dist/json/saveAndContinue.json +98 -0
- package/dist/json/team.json +17351 -0
- package/dist/json/userProfile.data.json +14 -0
- package/dist/json/userProfile.json +276 -0
- package/dist/models/ComponentTypes.js +7 -1
- package/dist/models/PageAction.js +9 -7
- package/dist/utils/CheckYourAnswers/getCYAAction.js +24 -3
- package/dist/utils/CheckYourAnswers/getCYAAction.test.js +62 -15
- package/dist/utils/CheckYourAnswers/getCYARow.js +8 -2
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +11 -5
- package/dist/utils/Component/getComponent.js +32 -0
- package/dist/utils/Component/getComponentTests/getComponent.autocomplete.test.js +75 -0
- package/dist/utils/Component/getComponentTests/getComponent.checkboxes.test.js +129 -0
- package/dist/utils/Component/getComponentTests/getComponent.date.test.js +129 -0
- package/dist/utils/Component/getComponentTests/getComponent.email.test.js +80 -0
- package/dist/utils/Component/getComponentTests/getComponent.heading.test.js +33 -0
- package/dist/utils/Component/getComponentTests/getComponent.html.test.js +45 -0
- package/dist/utils/Component/getComponentTests/getComponent.insetText.test.js +31 -0
- package/dist/utils/Component/getComponentTests/getComponent.phoneNumber.test.js +80 -0
- package/dist/utils/Component/getComponentTests/getComponent.radios.test.js +125 -0
- package/dist/utils/Component/getComponentTests/getComponent.text.test.js +80 -0
- package/dist/utils/Component/getComponentTests/getComponent.textarea.test.js +76 -0
- package/dist/utils/Component/getComponentTests/getComponent.unknown.test.js +14 -0
- package/dist/utils/Component/isEditable.js +1 -1
- package/dist/utils/Data/refDataToOptions.js +4 -0
- package/dist/utils/Data/refDataToOptions.test.js +30 -0
- package/dist/utils/FormPage/getEditableComponents.js +28 -0
- package/dist/utils/FormPage/getEditableComponents.test.js +75 -0
- package/dist/utils/FormPage/getFormPage.js +5 -1
- package/dist/utils/FormPage/getPageActions.js +66 -0
- package/dist/utils/FormPage/getPageActions.test.js +89 -0
- package/dist/utils/FormPage/index.js +7 -1
- package/dist/utils/FormPage/showFormPage.js +81 -0
- package/dist/utils/FormPage/showFormPage.test.js +131 -0
- package/dist/utils/Validate/validateComponent.js +4 -2
- package/package.json +9 -5
- package/dist/utils/Component/getComponent.test.js +0 -329
|
@@ -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
|
-
|
|
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
|
|
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
|
|
25
|
-
var
|
|
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
|
-
|
|
28
|
+
page: NAVIGATE_TO
|
|
30
29
|
};
|
|
31
|
-
expect((0, _getPageId.default)(ACTION, PAGE_ID)).toEqual(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
15
|
+
return (action === null || action === void 0 ? void 0 : action.page) || _models.FormPages.HUB;
|
|
16
|
+
};
|
|
14
17
|
|
|
15
|
-
|
|
18
|
+
var getNextCYAPageId = function getNextCYAPageId(pages, currentPageId, formData) {
|
|
19
|
+
return getNextWizardPageId(pages, currentPageId, formData) || _models.FormPages.CYA;
|
|
16
20
|
};
|
|
17
21
|
|
|
18
|
-
var
|
|
19
|
-
|
|
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
|
-
|
|
27
|
-
};
|
|
28
|
+
var page = pages[nextIndex];
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
while (page && !_FormPage.default.show(page, formData)) {
|
|
31
|
+
nextIndex++;
|
|
32
|
+
page = pages[nextIndex];
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
|
|
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
|
|
41
|
-
|
|
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,
|
|
61
|
+
return getNextCYAPageId(pages, currentPageId, formData);
|
|
55
62
|
|
|
56
63
|
case _models.FormTypes.WIZARD:
|
|
57
|
-
return getNextWizardPageId(pages, currentPageId,
|
|
64
|
+
return getNextWizardPageId(pages, currentPageId, formData);
|
|
58
65
|
|
|
59
66
|
default:
|
|
60
|
-
return getNextFormPageId(pages
|
|
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.
|
|
104
|
+
it('should return action.page if specified', function () {
|
|
29
105
|
var ACTION = {
|
|
30
|
-
|
|
106
|
+
page: 'bob'
|
|
31
107
|
};
|
|
32
|
-
expect((0, _getNextPageId.default)(FORM_TYPE, PAGES, undefined, ACTION)).toEqual(ACTION.
|
|
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(
|
|
44
|
-
expect((0, _getNextPageId.default)(FORM_TYPE, PAGES, PAGES[
|
|
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;
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _models = require("../../../models");
|
|
4
|
+
|
|
5
|
+
var _getSubmissionStatus = _interopRequireDefault(require("./getSubmissionStatus"));
|
|
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('getSubmissionStatus', 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
|
+
|
|
52
|
+
var PAGES = [{
|
|
53
|
+
id: 'alpha'
|
|
54
|
+
}, {
|
|
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
|
|
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, _getSubmissionStatus.default)(_models.FormTypes.HUB, PAGES, PAGES[0].id, ACTION, FORM_DATA)).toMatchObject({
|
|
77
|
+
page: undefined
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
it('should return the page on the action if it exists among the pages', function () {
|
|
81
|
+
var PAGE = PAGES[1].id;
|
|
82
|
+
var ACTION = {
|
|
83
|
+
type: _models.PageAction.TYPES.NAVIGATE,
|
|
84
|
+
page: PAGE
|
|
85
|
+
};
|
|
86
|
+
expect((0, _getSubmissionStatus.default)(_models.FormTypes.HUB, PAGES, PAGES[0].id, ACTION, FORM_DATA)).toMatchObject({
|
|
87
|
+
page: PAGE
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
it('should return undefined if the page on the action does not exist among the pages', function () {
|
|
91
|
+
var PAGE = 'golf';
|
|
92
|
+
var ACTION = {
|
|
93
|
+
type: _models.PageAction.TYPES.NAVIGATE,
|
|
94
|
+
page: PAGE
|
|
95
|
+
};
|
|
96
|
+
expect((0, _getSubmissionStatus.default)(_models.FormTypes.HUB, PAGES, PAGES[0].id, ACTION, FORM_DATA)).toMatchObject({
|
|
97
|
+
page: undefined
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
describe("when the action type is '".concat(_models.PageAction.TYPES.SAVE_AND_RETURN, "'"), function () {
|
|
102
|
+
Object.values(_models.FormTypes).forEach(function (formType) {
|
|
103
|
+
it("should return the current page if the form type is '".concat(formType, "'"), function () {
|
|
104
|
+
var ACTION = _models.PageAction.DEFAULTS.saveAndReturn;
|
|
105
|
+
expect((0, _getSubmissionStatus.default)(formType, PAGES, PAGES[0].id, ACTION, FORM_DATA)).toMatchObject({
|
|
106
|
+
page: PAGES[0].id
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
describe("when the form type is '".concat(_models.FormTypes.HUB, "'"), function () {
|
|
112
|
+
var FORM_TYPE = _models.FormTypes.HUB;
|
|
113
|
+
it("should return '".concat(_models.FormPages.HUB, "' by default"), function () {
|
|
114
|
+
expect((0, _getSubmissionStatus.default)(FORM_TYPE, PAGES)).toMatchObject({
|
|
115
|
+
page: _models.FormPages.HUB
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
it('should return action.page if specified', function () {
|
|
119
|
+
var ACTION = {
|
|
120
|
+
page: 'bob'
|
|
121
|
+
};
|
|
122
|
+
expect((0, _getSubmissionStatus.default)(FORM_TYPE, PAGES, undefined, ACTION, FORM_DATA)).toMatchObject({
|
|
123
|
+
page: ACTION.page
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
describe("when the form type is '".concat(_models.FormTypes.CYA, "'"), function () {
|
|
128
|
+
var FORM_TYPE = _models.FormTypes.CYA;
|
|
129
|
+
var ACTION = _models.PageAction.DEFAULTS.saveAndContinue;
|
|
130
|
+
it('should return the first page by default', function () {
|
|
131
|
+
expect((0, _getSubmissionStatus.default)(FORM_TYPE, PAGES, ACTION, FORM_DATA)).toMatchObject({
|
|
132
|
+
page: PAGES[0].id
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
it('should return the second page when on the first page', function () {
|
|
136
|
+
expect((0, _getSubmissionStatus.default)(FORM_TYPE, PAGES, PAGES[0].id, ACTION, FORM_DATA)).toMatchObject({
|
|
137
|
+
page: PAGES[1].id
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
it('should return the third page when on the second page', function () {
|
|
141
|
+
expect((0, _getSubmissionStatus.default)(FORM_TYPE, PAGES, PAGES[1].id, ACTION, FORM_DATA)).toMatchObject({
|
|
142
|
+
page: PAGES[2].id
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
it("should return the fifth page when on the third page because the fourth page show_when is not met", function () {
|
|
146
|
+
expect((0, _getSubmissionStatus.default)(FORM_TYPE, PAGES, PAGES[2].id, ACTION, FORM_DATA)).toMatchObject({
|
|
147
|
+
page: PAGES[4].id
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
it("should return the sixth page when on the fifth page because the sixth page show_when is met", function () {
|
|
151
|
+
expect((0, _getSubmissionStatus.default)(FORM_TYPE, PAGES, PAGES[4].id, ACTION, FORM_DATA)).toMatchObject({
|
|
152
|
+
page: PAGES[5].id
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
it("should return '".concat(_models.FormPages.CYA, "' when on the sixth (last) page"), function () {
|
|
156
|
+
var lastPageIndex = PAGES.length - 1;
|
|
157
|
+
expect((0, _getSubmissionStatus.default)(FORM_TYPE, PAGES, PAGES[lastPageIndex].id, ACTION, FORM_DATA)).toMatchObject({
|
|
158
|
+
page: _models.FormPages.CYA
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
describe("when the form type is '".concat(_models.FormTypes.WIZARD, "'"), function () {
|
|
163
|
+
var FORM_TYPE = _models.FormTypes.WIZARD;
|
|
164
|
+
it('should return the first page by default', function () {
|
|
165
|
+
expect((0, _getSubmissionStatus.default)(FORM_TYPE, PAGES)).toMatchObject({
|
|
166
|
+
page: PAGES[0].id
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
it('should return the second page when on the first page', function () {
|
|
170
|
+
expect((0, _getSubmissionStatus.default)(FORM_TYPE, PAGES, PAGES[0].id)).toMatchObject({
|
|
171
|
+
page: PAGES[1].id
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
it('should return undefined when on the last page', function () {
|
|
175
|
+
expect((0, _getSubmissionStatus.default)(FORM_TYPE, PAGES, PAGES[PAGES.length - 1].id)).toMatchObject({
|
|
176
|
+
page: undefined
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
describe("when the form type is '".concat(_models.FormTypes.FORM, "'"), function () {
|
|
181
|
+
var FORM_TYPE = _models.FormTypes.FORM;
|
|
182
|
+
it("should always return the first page if there any pages and the action is not '".concat(_models.PageAction.TYPES.SAVE_AND_RETURN, "'"), function () {
|
|
183
|
+
var ACTION = {
|
|
184
|
+
type: _models.PageAction.TYPES.SUBMIT,
|
|
185
|
+
nextPageId: 'bob'
|
|
186
|
+
};
|
|
187
|
+
expect((0, _getSubmissionStatus.default)(FORM_TYPE, PAGES)).toMatchObject({
|
|
188
|
+
page: PAGES[0].id
|
|
189
|
+
});
|
|
190
|
+
expect((0, _getSubmissionStatus.default)(FORM_TYPE, PAGES, PAGES[0].id)).toMatchObject({
|
|
191
|
+
page: PAGES[0].id
|
|
192
|
+
});
|
|
193
|
+
expect((0, _getSubmissionStatus.default)(FORM_TYPE, PAGES, PAGES[1].id)).toMatchObject({
|
|
194
|
+
page: PAGES[0].id
|
|
195
|
+
});
|
|
196
|
+
expect((0, _getSubmissionStatus.default)(FORM_TYPE, PAGES, PAGES[0].id, ACTION)).toMatchObject({
|
|
197
|
+
page: PAGES[0].id
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
it('should return undefined if there are no pages', function () {
|
|
201
|
+
expect((0, _getSubmissionStatus.default)(FORM_TYPE, [])).toMatchObject({
|
|
202
|
+
page: undefined
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
});
|
|
@@ -13,6 +13,8 @@ var _getFormState = _interopRequireDefault(require("./getFormState"));
|
|
|
13
13
|
|
|
14
14
|
var _getNextPageId = _interopRequireDefault(require("./getNextPageId"));
|
|
15
15
|
|
|
16
|
+
var _getSubmissionStatus = _interopRequireDefault(require("./getSubmissionStatus"));
|
|
17
|
+
|
|
16
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
19
|
|
|
18
20
|
// Local imports
|
|
@@ -20,7 +22,8 @@ var helpers = {
|
|
|
20
22
|
canActionProceed: _canActionProceed.default,
|
|
21
23
|
canCYASubmit: _canCYASubmit.default,
|
|
22
24
|
getFormState: _getFormState.default,
|
|
23
|
-
getNextPageId: _getNextPageId.default
|
|
25
|
+
getNextPageId: _getNextPageId.default,
|
|
26
|
+
getSubmissionStatus: _getSubmissionStatus.default
|
|
24
27
|
};
|
|
25
28
|
exports.helpers = helpers;
|
|
26
29
|
var _default = helpers;
|
|
@@ -59,7 +59,7 @@ describe('components', function () {
|
|
|
59
59
|
while (1) {
|
|
60
60
|
switch (_context2.prev = _context2.next) {
|
|
61
61
|
case 0:
|
|
62
|
-
ACTION =
|
|
62
|
+
ACTION = _models.PageAction.TYPES.SUBMIT;
|
|
63
63
|
_render2 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_ActionButton.default, {
|
|
64
64
|
action: ACTION,
|
|
65
65
|
onAction: ON_ACTION
|
|
@@ -43,7 +43,7 @@ Renders the buttons at the bottom of a Page.
|
|
|
43
43
|
<Canvas>
|
|
44
44
|
<Story name="Custom action">
|
|
45
45
|
{() => {
|
|
46
|
-
const ACTIONS = [{ type: 'navigate',
|
|
46
|
+
const ACTIONS = [{ type: 'navigate', page: 'profile', label: 'Go to profile' }];
|
|
47
47
|
const ON_ACTION = (action, patch, onError) => {
|
|
48
48
|
console.log('action invoked', action, patch);
|
|
49
49
|
};
|
|
@@ -55,7 +55,7 @@ describe('components', function () {
|
|
|
55
55
|
while (1) {
|
|
56
56
|
switch (_context2.prev = _context2.next) {
|
|
57
57
|
case 0:
|
|
58
|
-
ACTIONS = [
|
|
58
|
+
ACTIONS = [_models.PageAction.TYPES.SUBMIT];
|
|
59
59
|
_render2 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_PageActions.default, {
|
|
60
60
|
actions: ACTIONS,
|
|
61
61
|
onAction: ON_ACTION
|
|
@@ -87,7 +87,7 @@ describe('components', function () {
|
|
|
87
87
|
case 0:
|
|
88
88
|
ACTIONS = [{
|
|
89
89
|
type: 'navigate',
|
|
90
|
-
|
|
90
|
+
page: 'alpha',
|
|
91
91
|
label: 'Alpha'
|
|
92
92
|
}];
|
|
93
93
|
_render3 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_PageActions.default, {
|
|
@@ -120,11 +120,11 @@ describe('components', function () {
|
|
|
120
120
|
switch (_context4.prev = _context4.next) {
|
|
121
121
|
case 0:
|
|
122
122
|
NAVIGATE = {
|
|
123
|
-
type:
|
|
124
|
-
|
|
123
|
+
type: _models.PageAction.TYPES.NAVIGATE,
|
|
124
|
+
page: 'alpha',
|
|
125
125
|
label: 'Alpha'
|
|
126
126
|
};
|
|
127
|
-
ACTIONS = [NAVIGATE,
|
|
127
|
+
ACTIONS = [NAVIGATE, _models.PageAction.TYPES.SUBMIT];
|
|
128
128
|
_render4 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_PageActions.default, {
|
|
129
129
|
actions: ACTIONS,
|
|
130
130
|
onAction: ON_ACTION
|
|
@@ -56,7 +56,7 @@ RowAction.propTypes = {
|
|
|
56
56
|
row: _propTypes.default.shape({
|
|
57
57
|
action: _propTypes.default.shape({
|
|
58
58
|
label: _propTypes.default.string.isRequired,
|
|
59
|
-
|
|
59
|
+
page: _propTypes.default.string,
|
|
60
60
|
aria_suffix: _propTypes.default.string,
|
|
61
61
|
onAction: _propTypes.default.func
|
|
62
62
|
})
|
|
@@ -23,10 +23,10 @@ describe('components', function () {
|
|
|
23
23
|
expect(container.childNodes.length).toEqual(0);
|
|
24
24
|
});
|
|
25
25
|
it('should handle a row with an href in the action', function () {
|
|
26
|
-
var
|
|
26
|
+
var PAGE = 'alpha';
|
|
27
27
|
var ROW = {
|
|
28
28
|
action: {
|
|
29
|
-
|
|
29
|
+
page: PAGE,
|
|
30
30
|
label: 'Change'
|
|
31
31
|
}
|
|
32
32
|
};
|
|
@@ -38,14 +38,14 @@ describe('components', function () {
|
|
|
38
38
|
|
|
39
39
|
var link = container.childNodes[0];
|
|
40
40
|
expect(link.tagName).toEqual('A');
|
|
41
|
-
expect(link.getAttribute('href')).toEqual(
|
|
41
|
+
expect(link.getAttribute('href')).toEqual("/".concat(PAGE));
|
|
42
42
|
expect(link.textContent).toEqual(ROW.action.label);
|
|
43
43
|
});
|
|
44
44
|
it('should render an aria_suffix appropriately', function () {
|
|
45
|
-
var
|
|
45
|
+
var PAGE = 'alpha';
|
|
46
46
|
var ROW = {
|
|
47
47
|
action: {
|
|
48
|
-
|
|
48
|
+
page: PAGE,
|
|
49
49
|
label: 'Change',
|
|
50
50
|
aria_suffix: 'the thing'
|
|
51
51
|
}
|
|
@@ -58,7 +58,7 @@ describe('components', function () {
|
|
|
58
58
|
|
|
59
59
|
var link = container.childNodes[0];
|
|
60
60
|
expect(link.tagName).toEqual('A');
|
|
61
|
-
expect(link.getAttribute('href')).toEqual(
|
|
61
|
+
expect(link.getAttribute('href')).toEqual("/".concat(PAGE));
|
|
62
62
|
expect(link.textContent).toEqual("".concat(ROW.action.label, " ").concat(ROW.action.aria_suffix));
|
|
63
63
|
});
|
|
64
64
|
it('should handle a row with an onAction in the action', function () {
|