@ukhomeoffice/cop-react-form-renderer 1.0.0 → 2.2.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/LICENSE +21 -0
- package/README.md +12 -0
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +16 -5
- package/dist/components/CheckYourAnswers/CheckYourAnswers.stories.mdx +199 -79
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +44 -0
- package/dist/components/FormComponent/FormComponent.js +6 -1
- package/dist/components/FormComponent/FormComponent.test.js +67 -0
- package/dist/components/FormPage/FormPage.js +8 -2
- package/dist/components/FormPage/FormPage.test.js +2 -2
- package/dist/components/FormRenderer/FormRenderer.js +43 -15
- package/dist/components/FormRenderer/FormRenderer.stories.mdx +115 -49
- package/dist/components/FormRenderer/FormRenderer.test.js +40 -0
- 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/PageActions.stories.mdx +1 -1
- package/dist/components/PageActions/PageActions.test.js +2 -2
- package/dist/components/SummaryList/RowAction.js +1 -1
- package/dist/components/SummaryList/RowAction.test.js +6 -6
- package/dist/components/SummaryList/SummaryList.js +8 -5
- package/dist/components/SummaryList/SummaryList.scss +10 -2
- package/dist/components/SummaryList/SummaryList.stories.mdx +64 -10
- package/dist/components/SummaryList/SummaryList.test.js +54 -0
- package/dist/components/SummaryList/helpers/getRowActionAttributes.js +2 -2
- package/dist/components/SummaryList/helpers/getRowActionAttributes.test.js +4 -4
- package/dist/hooks/useHooks.js +5 -1
- package/dist/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 +4 -0
- 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 +42 -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 +5 -3
- package/dist/utils/Validate/validateRequired.js +11 -0
- package/dist/utils/Validate/validateRequired.test.js +12 -0
- package/package.json +9 -5
- package/dist/utils/Component/getComponent.test.js +0 -361
|
@@ -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;
|
|
@@ -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
|
};
|
|
@@ -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, {
|
|
@@ -121,7 +121,7 @@ describe('components', function () {
|
|
|
121
121
|
case 0:
|
|
122
122
|
NAVIGATE = {
|
|
123
123
|
type: _models.PageAction.TYPES.NAVIGATE,
|
|
124
|
-
|
|
124
|
+
page: 'alpha',
|
|
125
125
|
label: 'Alpha'
|
|
126
126
|
};
|
|
127
127
|
ACTIONS = [NAVIGATE, _models.PageAction.TYPES.SUBMIT];
|
|
@@ -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 () {
|
|
@@ -15,7 +15,7 @@ var _RowAction = _interopRequireDefault(require("./RowAction"));
|
|
|
15
15
|
|
|
16
16
|
require("./SummaryList.scss");
|
|
17
17
|
|
|
18
|
-
var _excluded = ["rows", "classBlock", "classModifiers", "className"];
|
|
18
|
+
var _excluded = ["rows", "noChangeAction", "classBlock", "classModifiers", "className"];
|
|
19
19
|
|
|
20
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
21
|
|
|
@@ -30,6 +30,7 @@ exports.DEFAULT_CLASS = DEFAULT_CLASS;
|
|
|
30
30
|
|
|
31
31
|
var SummaryList = function SummaryList(_ref) {
|
|
32
32
|
var rows = _ref.rows,
|
|
33
|
+
noChangeAction = _ref.noChangeAction,
|
|
33
34
|
classBlock = _ref.classBlock,
|
|
34
35
|
classModifiers = _ref.classModifiers,
|
|
35
36
|
className = _ref.className,
|
|
@@ -47,7 +48,7 @@ var SummaryList = function SummaryList(_ref) {
|
|
|
47
48
|
className: classes('key')
|
|
48
49
|
}, row.key), /*#__PURE__*/_react.default.createElement("dd", {
|
|
49
50
|
className: classes('value')
|
|
50
|
-
}, row.value), /*#__PURE__*/_react.default.createElement("dd", {
|
|
51
|
+
}, row.value), !noChangeAction && /*#__PURE__*/_react.default.createElement("dd", {
|
|
51
52
|
className: classes('actions')
|
|
52
53
|
}, row.action && /*#__PURE__*/_react.default.createElement(_RowAction.default, {
|
|
53
54
|
row: row
|
|
@@ -62,7 +63,7 @@ SummaryList.propTypes = {
|
|
|
62
63
|
key: _propTypes.default.string.isRequired,
|
|
63
64
|
value: _propTypes.default.any,
|
|
64
65
|
action: _propTypes.default.shape({
|
|
65
|
-
|
|
66
|
+
page: _propTypes.default.string,
|
|
66
67
|
label: _propTypes.default.string,
|
|
67
68
|
aria_suffix: _propTypes.default.string,
|
|
68
69
|
onAction: _propTypes.default.func
|
|
@@ -70,10 +71,12 @@ SummaryList.propTypes = {
|
|
|
70
71
|
})).isRequired,
|
|
71
72
|
classBlock: _propTypes.default.string,
|
|
72
73
|
classModifiers: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
|
|
73
|
-
className: _propTypes.default.string
|
|
74
|
+
className: _propTypes.default.string,
|
|
75
|
+
noChangeAction: _propTypes.default.bool
|
|
74
76
|
};
|
|
75
77
|
SummaryList.defaultProps = {
|
|
76
|
-
classBlock: DEFAULT_CLASS
|
|
78
|
+
classBlock: DEFAULT_CLASS,
|
|
79
|
+
noChangeAction: false
|
|
77
80
|
};
|
|
78
81
|
var _default = SummaryList;
|
|
79
82
|
exports.default = _default;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
@import
|
|
2
|
-
@import
|
|
1
|
+
@import 'node_modules/govuk-frontend/govuk/_base';
|
|
2
|
+
@import 'node_modules/govuk-frontend/govuk/components/summary-list/_summary-list';
|
|
3
3
|
|
|
4
4
|
.govuk-summary-list__actions {
|
|
5
5
|
.govuk-link {
|
|
@@ -7,3 +7,11 @@
|
|
|
7
7
|
cursor: pointer;
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
+
|
|
11
|
+
.caseview__key {
|
|
12
|
+
font-weight: normal;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.caseview__value {
|
|
16
|
+
@include govuk-typography-weight-bold;
|
|
17
|
+
}
|
|
@@ -1,36 +1,90 @@
|
|
|
1
1
|
<!-- Global imports -->
|
|
2
|
+
|
|
2
3
|
import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
|
|
3
4
|
import { Details, Heading } from '@ukhomeoffice/cop-react-components';
|
|
4
5
|
|
|
5
6
|
<!-- Local imports -->
|
|
7
|
+
|
|
6
8
|
import Utils from '../../utils';
|
|
7
9
|
import SummaryList from './SummaryList';
|
|
8
10
|
|
|
9
|
-
<Meta
|
|
11
|
+
<Meta
|
|
12
|
+
title='Components/Summary list'
|
|
13
|
+
id='D-SummaryList'
|
|
14
|
+
component={SummaryList}
|
|
15
|
+
/>
|
|
10
16
|
|
|
11
|
-
<Heading size=
|
|
17
|
+
<Heading size='xl' caption='Components'>
|
|
18
|
+
Summary list
|
|
19
|
+
</Heading>
|
|
12
20
|
|
|
13
21
|
Renders a list of key-value pairs, most commonly on the **Check your answers** screen, and optionally
|
|
14
22
|
display action links.
|
|
15
23
|
|
|
16
24
|
<Canvas withToolbar>
|
|
17
|
-
<Story name=
|
|
25
|
+
<Story name='Default'>
|
|
18
26
|
{() => {
|
|
19
27
|
const onAction = (row) => {
|
|
20
28
|
console.log('action clicked', row);
|
|
21
29
|
};
|
|
22
30
|
const ROWS = [
|
|
23
|
-
{
|
|
31
|
+
{
|
|
32
|
+
pageId: 'p1',
|
|
33
|
+
fieldId: 'forename',
|
|
34
|
+
key: 'Forename(s)',
|
|
35
|
+
value: 'John',
|
|
36
|
+
},
|
|
24
37
|
{ pageId: 'p1', fieldId: 'surname', key: 'Surname', value: 'Smith' },
|
|
25
|
-
{
|
|
38
|
+
{
|
|
39
|
+
pageId: 'p2',
|
|
40
|
+
fieldId: 'dob',
|
|
41
|
+
key: 'Date of birth',
|
|
42
|
+
value: '29/08/1993',
|
|
43
|
+
action: { label: 'Change', onAction },
|
|
44
|
+
},
|
|
26
45
|
];
|
|
27
|
-
return
|
|
28
|
-
<SummaryList rows={ROWS} />
|
|
29
|
-
);
|
|
46
|
+
return <SummaryList rows={ROWS} />;
|
|
30
47
|
}}
|
|
31
48
|
</Story>
|
|
32
49
|
</Canvas>
|
|
33
50
|
|
|
34
|
-
<Details summary=
|
|
35
|
-
<ArgsTable of={
|
|
51
|
+
<Details summary='Properties' className='no-indent'>
|
|
52
|
+
<ArgsTable of={SummaryList} />
|
|
36
53
|
</Details>
|
|
54
|
+
|
|
55
|
+
## Variant
|
|
56
|
+
|
|
57
|
+
### Read-only style
|
|
58
|
+
|
|
59
|
+
<Canvas>
|
|
60
|
+
<Story name='Read-only style'>
|
|
61
|
+
{() => {
|
|
62
|
+
const onAction = (row) => {
|
|
63
|
+
console.log('action clicked', row);
|
|
64
|
+
};
|
|
65
|
+
const ROWS = [
|
|
66
|
+
{
|
|
67
|
+
pageId: 'p1',
|
|
68
|
+
fieldId: 'forename',
|
|
69
|
+
key: 'Forename(s)',
|
|
70
|
+
value: 'John',
|
|
71
|
+
},
|
|
72
|
+
{ pageId: 'p1', fieldId: 'surname', key: 'Surname', value: 'Smith' },
|
|
73
|
+
{
|
|
74
|
+
pageId: 'p2',
|
|
75
|
+
fieldId: 'dob',
|
|
76
|
+
key: 'Date of birth',
|
|
77
|
+
value: '29/08/1993',
|
|
78
|
+
action: { label: 'Change', onAction },
|
|
79
|
+
},
|
|
80
|
+
];
|
|
81
|
+
return (
|
|
82
|
+
<SummaryList
|
|
83
|
+
classModifiers='no-border'
|
|
84
|
+
rows={ROWS}
|
|
85
|
+
noChangeAction={true}
|
|
86
|
+
/>
|
|
87
|
+
);
|
|
88
|
+
}}
|
|
89
|
+
</Story>
|
|
90
|
+
</Canvas>
|