@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.
- package/dist/components/CheckYourAnswers/Answer.test.js +94 -0
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +79 -27
- package/dist/components/CheckYourAnswers/CheckYourAnswers.scss +0 -7
- package/dist/components/CheckYourAnswers/CheckYourAnswers.stories.mdx +78 -1
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +332 -0
- package/dist/components/FormPage/FormPage.test.js +3 -1
- package/dist/components/FormRenderer/FormRenderer.js +75 -54
- package/dist/components/FormRenderer/FormRenderer.stories.mdx +35 -7
- package/dist/components/FormRenderer/FormRenderer.test.js +471 -0
- package/dist/components/FormRenderer/handlers/cyaAction.js +28 -0
- package/dist/components/FormRenderer/handlers/getPageId.js +28 -0
- package/dist/components/FormRenderer/handlers/getPageId.test.js +61 -0
- package/dist/components/FormRenderer/handlers/handlers.test.js +97 -0
- package/dist/components/FormRenderer/handlers/index.js +23 -0
- package/dist/components/FormRenderer/handlers/navigate.js +28 -0
- package/dist/components/FormRenderer/handlers/submissionError.js +20 -0
- package/dist/components/FormRenderer/helpers/canCYASubmit.js +42 -0
- package/dist/components/FormRenderer/helpers/canCYASubmit.test.js +155 -0
- package/dist/components/FormRenderer/helpers/getCYA.js +2 -2
- package/dist/components/FormRenderer/helpers/getCYA.test.js +5 -5
- package/dist/components/FormRenderer/helpers/getFormState.test.js +7 -7
- package/dist/components/FormRenderer/helpers/getNextPageId.js +65 -0
- package/dist/components/FormRenderer/helpers/getNextPageId.test.js +90 -0
- package/dist/components/FormRenderer/helpers/getPage.js +1 -1
- package/dist/components/FormRenderer/helpers/getPage.test.js +3 -3
- package/dist/components/FormRenderer/helpers/index.js +17 -13
- package/dist/components/PageActions/ActionButton.js +5 -9
- package/dist/components/PageActions/ActionButton.test.js +3 -1
- package/dist/components/PageActions/PageActions.test.js +4 -2
- package/dist/components/SummaryList/RowAction.js +1 -1
- package/dist/components/SummaryList/RowAction.test.js +8 -18
- package/dist/components/SummaryList/SummaryList.js +4 -4
- package/dist/components/SummaryList/SummaryList.scss +7 -0
- package/dist/components/SummaryList/SummaryList.stories.mdx +36 -0
- package/dist/components/SummaryList/SummaryList.test.js +197 -0
- package/dist/hooks/useHooks.js +12 -15
- package/dist/index.js +3 -1
- package/dist/index.test.js +18 -0
- package/dist/models/EventTypes.js +14 -0
- package/dist/models/FormPages.js +14 -0
- package/dist/models/PageAction.js +40 -0
- package/dist/models/index.js +24 -0
- package/dist/utils/CheckYourAnswers/getCYAAction.js +9 -0
- package/dist/utils/CheckYourAnswers/getCYARow.js +10 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +9 -0
- package/dist/utils/CheckYourAnswers/showComponentCYA.js +6 -5
- package/dist/utils/Component/getComponent.test.js +1 -1
- package/dist/utils/Format/formatData.js +32 -0
- package/dist/utils/Format/formatData.test.js +46 -0
- package/dist/utils/Format/formatDataForComponent.js +41 -0
- package/dist/utils/Format/formatDataForComponent.test.js +161 -0
- package/dist/utils/Format/formatDataForForm.js +33 -0
- package/dist/utils/Format/formatDataForForm.test.js +78 -0
- package/dist/utils/Format/formatDataForPage.js +37 -0
- package/dist/utils/Format/formatDataForPage.test.js +96 -0
- package/dist/utils/Format/index.js +26 -0
- package/dist/utils/Hub/getFormHub.js +14 -0
- package/dist/utils/Validate/validatePage.test.js +1 -1
- package/dist/utils/index.js +3 -0
- package/package.json +6 -3
- package/dist/components/FormRenderer/helpers.js +0 -66
- package/dist/components/FormRenderer/helpers.test.js +0 -158
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getPage = exports.getFormState = exports.getCYA = exports.canActionProceed = void 0;
|
|
7
|
-
|
|
8
|
-
var _models = require("../../models");
|
|
9
|
-
|
|
10
|
-
var _utils = _interopRequireDefault(require("../../utils"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
// Local imports
|
|
15
|
-
var getCYA = function getCYA(pageId, hub) {
|
|
16
|
-
if (pageId === 'hub' && hub === _models.HubFormats.CYA) {
|
|
17
|
-
return {
|
|
18
|
-
title: ''
|
|
19
|
-
};
|
|
20
|
-
} else if (pageId === _models.HubFormats.CYA) {
|
|
21
|
-
return {};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return undefined;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
exports.getCYA = getCYA;
|
|
28
|
-
|
|
29
|
-
var getPage = function getPage(pageId, pages, hub) {
|
|
30
|
-
if (pageId) {
|
|
31
|
-
if (pageId === 'hub') {
|
|
32
|
-
return hub === _models.HubFormats.CYA ? undefined : hub;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return pages.find(function (p) {
|
|
36
|
-
return p.id === pageId;
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return undefined;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
exports.getPage = getPage;
|
|
44
|
-
|
|
45
|
-
var getFormState = function getFormState(pageId, pages, hub) {
|
|
46
|
-
return {
|
|
47
|
-
pageId: pageId,
|
|
48
|
-
cya: getCYA(pageId, hub),
|
|
49
|
-
page: getPage(pageId, pages, hub)
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
exports.getFormState = getFormState;
|
|
54
|
-
|
|
55
|
-
var canActionProceed = function canActionProceed(action, page, onError) {
|
|
56
|
-
if (action.validate) {
|
|
57
|
-
var errors = _utils.default.Validate.page(page.components, page.formData);
|
|
58
|
-
|
|
59
|
-
onError(errors);
|
|
60
|
-
return errors.length === 0;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return true;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
exports.canActionProceed = canActionProceed;
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _helpers = require("./helpers");
|
|
4
|
-
|
|
5
|
-
var _models = require("../../models");
|
|
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
|
-
var HUB = {
|
|
23
|
-
id: 'hub',
|
|
24
|
-
components: []
|
|
25
|
-
};
|
|
26
|
-
var PAGES = [{
|
|
27
|
-
id: 'alpha',
|
|
28
|
-
components: ['x']
|
|
29
|
-
}, {
|
|
30
|
-
id: 'bravo',
|
|
31
|
-
components: ['y', 'z']
|
|
32
|
-
}, HUB];
|
|
33
|
-
describe('getCYA', function () {
|
|
34
|
-
it('should give an empty object if the pageId is "CYA"', function () {
|
|
35
|
-
expect((0, _helpers.getCYA)(_models.HubFormats.CYA)).toEqual({});
|
|
36
|
-
});
|
|
37
|
-
it('should give an object with a blank title if the pageId is "hub" and the hub is the CYA', function () {
|
|
38
|
-
expect((0, _helpers.getCYA)('hub', _models.HubFormats.CYA)).toEqual({
|
|
39
|
-
title: ''
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
it('should give undefined if pageId is "hub" and the hub is NOT the CYA', function () {
|
|
43
|
-
expect((0, _helpers.getCYA)('hub', HUB)).toBeUndefined();
|
|
44
|
-
});
|
|
45
|
-
it('should give undefined if pageId is NOT "hub" and the hub is NOT the CYA', function () {
|
|
46
|
-
expect((0, _helpers.getCYA)('bob', HUB)).toBeUndefined();
|
|
47
|
-
});
|
|
48
|
-
it('should give undefined if pageId is NOT "hub" and the hub is the CYA', function () {
|
|
49
|
-
expect((0, _helpers.getCYA)('bob', _models.HubFormats.CYA)).toBeUndefined();
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
describe('getPage', function () {
|
|
53
|
-
it('should give undefined if the pageId is undefined', function () {
|
|
54
|
-
expect((0, _helpers.getPage)(undefined, PAGES, _models.HubFormats.CYA)).toBeUndefined();
|
|
55
|
-
});
|
|
56
|
-
it('should give undefined if the pageId is "hub" but the hub is the CYA', function () {
|
|
57
|
-
expect((0, _helpers.getPage)('hub', PAGES, _models.HubFormats.CYA)).toBeUndefined();
|
|
58
|
-
});
|
|
59
|
-
it('should give hub if the pageId is "hub" and the hub is NOT the CYA', function () {
|
|
60
|
-
expect((0, _helpers.getPage)('hub', PAGES, HUB)).toEqual(HUB);
|
|
61
|
-
});
|
|
62
|
-
it('should give find the appropriate page if the pageId is not "hub"', function () {
|
|
63
|
-
expect((0, _helpers.getPage)('alpha', PAGES, HUB)).toEqual({
|
|
64
|
-
id: 'alpha',
|
|
65
|
-
components: ['x']
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
it('should give undefined if the pageId is not "hub" and not found in the pages collection', function () {
|
|
69
|
-
expect((0, _helpers.getPage)('charlie', PAGES, HUB)).toBeUndefined();
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
describe('getFormState', function () {
|
|
73
|
-
it('should set up accordingly when viewing a hub that is the CYA', function () {
|
|
74
|
-
expect((0, _helpers.getFormState)('hub', PAGES, _models.HubFormats.CYA)).toEqual({
|
|
75
|
-
pageId: 'hub',
|
|
76
|
-
cya: {
|
|
77
|
-
title: ''
|
|
78
|
-
},
|
|
79
|
-
page: undefined
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
it('should set up accordingly when viewing a hub that is NOT the CYA', function () {
|
|
83
|
-
expect((0, _helpers.getFormState)('hub', PAGES, HUB)).toEqual({
|
|
84
|
-
pageId: 'hub',
|
|
85
|
-
cya: undefined,
|
|
86
|
-
page: HUB
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
it('should set up accordingly when viewing the CYA', function () {
|
|
90
|
-
expect((0, _helpers.getFormState)(_models.HubFormats.CYA, PAGES, HUB)).toEqual({
|
|
91
|
-
pageId: _models.HubFormats.CYA,
|
|
92
|
-
cya: {},
|
|
93
|
-
page: undefined
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
it('should set up accordingly when viewing a standard page', function () {
|
|
97
|
-
expect((0, _helpers.getFormState)('bravo', PAGES, HUB)).toEqual({
|
|
98
|
-
pageId: 'bravo',
|
|
99
|
-
cya: undefined,
|
|
100
|
-
page: {
|
|
101
|
-
id: 'bravo',
|
|
102
|
-
components: ['y', 'z']
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
describe('canActionProceed', function () {
|
|
108
|
-
it('should return true when the action does not require validation', function () {
|
|
109
|
-
var ACTION = {
|
|
110
|
-
validate: false
|
|
111
|
-
};
|
|
112
|
-
expect((0, _helpers.canActionProceed)(ACTION, {}, function () {})).toBeTruthy();
|
|
113
|
-
});
|
|
114
|
-
it('should return true when the page is valid', function () {
|
|
115
|
-
var ACTION = {
|
|
116
|
-
validate: true
|
|
117
|
-
};
|
|
118
|
-
var PAGE = {
|
|
119
|
-
components: [{
|
|
120
|
-
id: 'a',
|
|
121
|
-
fieldId: 'a',
|
|
122
|
-
label: 'Alpha',
|
|
123
|
-
required: true
|
|
124
|
-
}],
|
|
125
|
-
formData: {
|
|
126
|
-
a: 'Bravo'
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
expect((0, _helpers.canActionProceed)(ACTION, PAGE, function () {})).toBeTruthy();
|
|
130
|
-
});
|
|
131
|
-
it('should return false when the page is invalid and should have called the onErrors method appropriately', function () {
|
|
132
|
-
var ACTION = {
|
|
133
|
-
validate: true
|
|
134
|
-
};
|
|
135
|
-
var PAGE = {
|
|
136
|
-
components: [{
|
|
137
|
-
id: 'a',
|
|
138
|
-
fieldId: 'a',
|
|
139
|
-
label: 'Alpha',
|
|
140
|
-
required: true
|
|
141
|
-
}],
|
|
142
|
-
formData: {}
|
|
143
|
-
};
|
|
144
|
-
var ERRORS = [];
|
|
145
|
-
|
|
146
|
-
var ON_ERROR = function ON_ERROR(errors) {
|
|
147
|
-
ERRORS.push.apply(ERRORS, _toConsumableArray(errors));
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
expect((0, _helpers.canActionProceed)(ACTION, PAGE, ON_ERROR)).toBeFalsy();
|
|
151
|
-
expect(ERRORS.length).toEqual(1);
|
|
152
|
-
expect(ERRORS[0].id).toEqual('a');
|
|
153
|
-
expect(ERRORS[0].error).toEqual('Alpha is required');
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
});
|