@ukhomeoffice/cop-react-form-renderer 0.1.0-beta → 1.0.0-gamma
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.js +48 -0
- package/dist/components/CheckYourAnswers/Answer.test.js +94 -0
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +94 -23
- package/dist/components/CheckYourAnswers/CheckYourAnswers.scss +0 -7
- package/dist/components/CheckYourAnswers/CheckYourAnswers.stories.mdx +149 -0
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +332 -0
- package/dist/components/FormComponent/FormComponent.js +7 -7
- package/dist/components/FormComponent/FormComponent.stories.mdx +167 -0
- package/dist/components/FormComponent/FormComponent.test.js +137 -0
- package/dist/components/FormPage/FormPage.js +12 -11
- package/dist/components/FormPage/FormPage.stories.mdx +118 -0
- package/dist/components/FormPage/FormPage.test.js +255 -0
- package/dist/components/FormRenderer/FormRenderer.js +95 -54
- package/dist/components/FormRenderer/FormRenderer.stories.mdx +115 -0
- 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/canActionProceed.js +35 -0
- package/dist/components/FormRenderer/helpers/canActionProceed.test.js +73 -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 +31 -0
- package/dist/components/FormRenderer/helpers/getCYA.test.js +38 -0
- package/dist/components/FormRenderer/helpers/getFormState.js +32 -0
- package/dist/components/FormRenderer/helpers/getFormState.test.js +61 -0
- 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 +34 -0
- package/dist/components/FormRenderer/helpers/getPage.test.js +46 -0
- package/dist/components/FormRenderer/helpers/index.js +27 -0
- package/dist/components/PageActions/ActionButton.js +58 -0
- package/dist/components/PageActions/ActionButton.test.js +116 -0
- package/dist/components/PageActions/PageActions.js +18 -25
- package/dist/components/PageActions/PageActions.stories.mdx +74 -0
- package/dist/components/PageActions/PageActions.test.js +157 -0
- package/dist/components/SummaryList/RowAction.js +13 -22
- package/dist/components/SummaryList/RowAction.test.js +94 -0
- package/dist/components/SummaryList/SummaryList.js +6 -20
- 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/components/SummaryList/helpers/getRowActionAttributes.js +27 -0
- package/dist/components/SummaryList/helpers/getRowActionAttributes.test.js +77 -0
- package/dist/components/SummaryList/helpers/index.js +15 -0
- package/dist/components/index.js +8 -0
- package/dist/hooks/useGetRequest.js +16 -1
- package/dist/hooks/useHooks.js +16 -5
- 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.js +2 -2
- package/dist/utils/Component/getComponent.test.js +1 -1
- package/dist/utils/Data/setupFormData.js +3 -3
- package/dist/utils/Data/setupFormData.test.js +6 -6
- package/dist/utils/Data/setupRefDataUrlForComponent.test.js +4 -4
- package/dist/utils/FormPage/getFormPage.js +12 -1
- package/dist/utils/FormPage/getFormPage.test.js +178 -0
- package/dist/utils/FormPage/getFormPages.js +11 -6
- package/dist/utils/FormPage/getFormPages.test.js +95 -0
- package/dist/utils/FormPage/getParagraphFromText.js +6 -0
- package/dist/utils/FormPage/getParagraphFromText.test.js +29 -0
- package/dist/utils/FormPage/useComponent.js +9 -2
- package/dist/utils/FormPage/useComponent.test.js +82 -0
- 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 +18 -4
- package/dist/utils/Hub/getFormHub.test.js +96 -0
- package/dist/utils/Hub/index.js +0 -3
- 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
package/dist/hooks/useHooks.js
CHANGED
|
@@ -3,17 +3,28 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.resetHooks = exports.removeHook = exports.default = exports.addHook = void 0;
|
|
7
|
-
var ALLOWED_HOOKS = ['onRequest'];
|
|
6
|
+
exports.resetHooks = exports.removeHook = exports.default = exports.addHook = exports.ALLOWED_HOOKS = void 0;
|
|
7
|
+
var ALLOWED_HOOKS = ['onRequest', 'onFormComplete', 'onFormLoad', 'onPageChange', 'onSubmit'];
|
|
8
|
+
exports.ALLOWED_HOOKS = ALLOWED_HOOKS;
|
|
8
9
|
var DEFAULT_HOOKS = {
|
|
10
|
+
onFormComplete: function onFormComplete() {},
|
|
11
|
+
onFormLoad: function onFormLoad() {},
|
|
12
|
+
onPageChange: function onPageChange(pageId) {
|
|
13
|
+
return pageId;
|
|
14
|
+
},
|
|
9
15
|
onRequest: function onRequest(req) {
|
|
10
16
|
return req;
|
|
17
|
+
},
|
|
18
|
+
onSubmit: function onSubmit(type, payload, onSuccess, onError) {
|
|
19
|
+
if (typeof onSuccess === 'function') onSuccess();
|
|
11
20
|
}
|
|
12
21
|
};
|
|
13
22
|
var hooks = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
23
|
+
onFormComplete: DEFAULT_HOOKS.onFormComplete,
|
|
24
|
+
onFormLoad: DEFAULT_HOOKS.onFormLoad,
|
|
25
|
+
onPageChange: DEFAULT_HOOKS.onPageChange,
|
|
26
|
+
onRequest: DEFAULT_HOOKS.onRequest,
|
|
27
|
+
onSubmit: DEFAULT_HOOKS.onSubmit
|
|
17
28
|
};
|
|
18
29
|
|
|
19
30
|
var addHook = function addHook(name, hook) {
|
package/dist/index.js
CHANGED
|
@@ -41,7 +41,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
41
41
|
|
|
42
42
|
// Local imports
|
|
43
43
|
var intercepts = {
|
|
44
|
-
add: _useHooks.addHook
|
|
44
|
+
add: _useHooks.addHook,
|
|
45
|
+
remove: _useHooks.removeHook,
|
|
46
|
+
reset: _useHooks.resetHooks
|
|
45
47
|
};
|
|
46
48
|
exports.intercepts = intercepts;
|
|
47
49
|
var _default = _FormRenderer.default;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
4
|
+
|
|
5
|
+
var _ = _interopRequireWildcard(require("."));
|
|
6
|
+
|
|
7
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
8
|
+
|
|
9
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
10
|
+
|
|
11
|
+
// Local imports
|
|
12
|
+
it('should have exported everything appropriately', function () {
|
|
13
|
+
expect(_.default).toBeDefined();
|
|
14
|
+
expect(_.FormTypes).toBeDefined();
|
|
15
|
+
expect(_.HubFormats).toBeDefined();
|
|
16
|
+
expect(_.intercepts).toBeDefined();
|
|
17
|
+
expect(_.Utils).toBeDefined();
|
|
18
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var TYPE_BLUR = 'blur';
|
|
8
|
+
var TYPE_SUBMIT = 'submit';
|
|
9
|
+
var EventTypes = {
|
|
10
|
+
BLUR: TYPE_BLUR,
|
|
11
|
+
SUBMIT: TYPE_SUBMIT
|
|
12
|
+
};
|
|
13
|
+
var _default = EventTypes;
|
|
14
|
+
exports.default = _default;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var PAGE_CYA = 'cya';
|
|
8
|
+
var PAGE_HUB = 'hub';
|
|
9
|
+
var FormPages = {
|
|
10
|
+
CYA: PAGE_CYA,
|
|
11
|
+
HUB: PAGE_HUB
|
|
12
|
+
};
|
|
13
|
+
var _default = FormPages;
|
|
14
|
+
exports.default = _default;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.PageActionTypes = exports.DefaultPageActions = void 0;
|
|
7
|
+
|
|
8
|
+
var _DefaultPageActions;
|
|
9
|
+
|
|
10
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
|
+
|
|
12
|
+
var TYPE_SUBMIT = 'submit';
|
|
13
|
+
var TYPE_SAVE_AND_CONTINUE = 'saveAndContinue';
|
|
14
|
+
var TYPE_SAVE_AND_RETURN = 'saveAndReturn';
|
|
15
|
+
var PageActionTypes = {
|
|
16
|
+
SUBMIT: TYPE_SUBMIT,
|
|
17
|
+
SAVE_AND_CONTINUE: TYPE_SAVE_AND_CONTINUE,
|
|
18
|
+
SAVE_AND_RETURN: TYPE_SAVE_AND_RETURN
|
|
19
|
+
};
|
|
20
|
+
exports.PageActionTypes = PageActionTypes;
|
|
21
|
+
var DefaultPageActions = (_DefaultPageActions = {}, _defineProperty(_DefaultPageActions, TYPE_SUBMIT, {
|
|
22
|
+
type: TYPE_SUBMIT,
|
|
23
|
+
validate: true
|
|
24
|
+
}), _defineProperty(_DefaultPageActions, TYPE_SAVE_AND_CONTINUE, {
|
|
25
|
+
type: TYPE_SAVE_AND_CONTINUE,
|
|
26
|
+
validate: true,
|
|
27
|
+
label: 'Save and continue'
|
|
28
|
+
}), _defineProperty(_DefaultPageActions, TYPE_SAVE_AND_RETURN, {
|
|
29
|
+
type: TYPE_SAVE_AND_RETURN,
|
|
30
|
+
validate: false,
|
|
31
|
+
label: 'Save and return later',
|
|
32
|
+
classModifiers: 'secondary'
|
|
33
|
+
}), _DefaultPageActions);
|
|
34
|
+
exports.DefaultPageActions = DefaultPageActions;
|
|
35
|
+
var PageAction = {
|
|
36
|
+
TYPES: PageActionTypes,
|
|
37
|
+
DEFAULTS: DefaultPageActions
|
|
38
|
+
};
|
|
39
|
+
var _default = PageAction;
|
|
40
|
+
exports.default = _default;
|
package/dist/models/index.js
CHANGED
|
@@ -9,6 +9,18 @@ Object.defineProperty(exports, "ComponentTypes", {
|
|
|
9
9
|
return _ComponentTypes.default;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
+
Object.defineProperty(exports, "EventTypes", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _EventTypes.default;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "FormPages", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function get() {
|
|
21
|
+
return _FormPages.default;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
12
24
|
Object.defineProperty(exports, "FormTypes", {
|
|
13
25
|
enumerable: true,
|
|
14
26
|
get: function get() {
|
|
@@ -21,11 +33,23 @@ Object.defineProperty(exports, "HubFormats", {
|
|
|
21
33
|
return _HubFormats.default;
|
|
22
34
|
}
|
|
23
35
|
});
|
|
36
|
+
Object.defineProperty(exports, "PageAction", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function get() {
|
|
39
|
+
return _PageAction.default;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
24
42
|
|
|
25
43
|
var _ComponentTypes = _interopRequireDefault(require("./ComponentTypes"));
|
|
26
44
|
|
|
45
|
+
var _EventTypes = _interopRequireDefault(require("./EventTypes"));
|
|
46
|
+
|
|
47
|
+
var _FormPages = _interopRequireDefault(require("./FormPages"));
|
|
48
|
+
|
|
27
49
|
var _FormTypes = _interopRequireDefault(require("./FormTypes"));
|
|
28
50
|
|
|
29
51
|
var _HubFormats = _interopRequireDefault(require("./HubFormats"));
|
|
30
52
|
|
|
53
|
+
var _PageAction = _interopRequireDefault(require("./PageAction"));
|
|
54
|
+
|
|
31
55
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -5,6 +5,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Gets an action object, configured appropriately for a Check your answers component.
|
|
10
|
+
*
|
|
11
|
+
* @param {boolean} readonly Whether or not the component is readonly.
|
|
12
|
+
* @param {object} cya_link A configuration object for any link to show.
|
|
13
|
+
* @param {Function} onAction A function to invoke if the link is clicked.
|
|
14
|
+
*
|
|
15
|
+
* @returns An action object for a Check your answers row.
|
|
16
|
+
*/
|
|
8
17
|
var getCYAAction = function getCYAAction(readonly, cya_link, onAction) {
|
|
9
18
|
if (readonly !== true && cya_link) {
|
|
10
19
|
return {
|
|
@@ -12,6 +12,16 @@ var _getCYAAction = _interopRequireDefault(require("./getCYAAction"));
|
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
13
|
|
|
14
14
|
// Local imports
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Gets a row object, configured appropriately for a Check your answers component.
|
|
18
|
+
*
|
|
19
|
+
* @param {object} page The page to which this component row belongs.
|
|
20
|
+
* @param {object} component The component to render on this row.
|
|
21
|
+
* @param {Function} onAction A function to invoke if the change link is clicked.
|
|
22
|
+
*
|
|
23
|
+
* @returns A configuration object for a Check your answers row.
|
|
24
|
+
*/
|
|
15
25
|
var getCYARow = function getCYARow(page, component, onAction) {
|
|
16
26
|
return {
|
|
17
27
|
pageId: page.id,
|
|
@@ -12,6 +12,15 @@ var _showComponentCYA = _interopRequireDefault(require("./showComponentCYA"));
|
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
13
|
|
|
14
14
|
// Local imports
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Gets an array of row objects, each configured appropriately for a Check your answers component.
|
|
18
|
+
*
|
|
19
|
+
* @param {object} page The page to show components for.
|
|
20
|
+
* @param {Function} onAction A function to invoke if the change link on any row is clicked.
|
|
21
|
+
*
|
|
22
|
+
* @returns An array of configuration objects for Check your answers rows.
|
|
23
|
+
*/
|
|
15
24
|
var getCYARowsForPage = function getCYARowsForPage(page, onAction) {
|
|
16
25
|
return page.components.filter(function (c) {
|
|
17
26
|
return (0, _showComponentCYA.default)(c, page.formData);
|
|
@@ -5,20 +5,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var _Component = _interopRequireDefault(require("../Component"));
|
|
9
|
-
|
|
10
8
|
var _models = require("../../models");
|
|
11
9
|
|
|
10
|
+
var _Component = _interopRequireDefault(require("../Component"));
|
|
11
|
+
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
13
|
|
|
14
14
|
// Local imports
|
|
15
15
|
var EXCLUDE_FROM_CYA = [_models.ComponentTypes.HEADING, _models.ComponentTypes.HTML, _models.ComponentTypes.INSET_TEXT];
|
|
16
16
|
/**
|
|
17
|
-
* Determines whether a given component should display on the
|
|
18
|
-
*
|
|
17
|
+
* Determines whether a given component should display on the Check your answers screen.
|
|
18
|
+
*
|
|
19
19
|
* @param {object} options The component options.
|
|
20
20
|
* @param {object} data The data contained on the form.
|
|
21
|
-
*
|
|
21
|
+
*
|
|
22
|
+
* @returns A boolean true if the component should show; otherwise false.
|
|
22
23
|
*/
|
|
23
24
|
|
|
24
25
|
var showComponentCYA = function showComponentCYA(options, data) {
|
|
@@ -102,10 +102,10 @@ var getComponentByType = function getComponentByType(config) {
|
|
|
102
102
|
};
|
|
103
103
|
|
|
104
104
|
var getComponent = function getComponent(config) {
|
|
105
|
-
var
|
|
105
|
+
var wrap = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
106
106
|
var component = getComponentByType(config);
|
|
107
107
|
|
|
108
|
-
if (component &&
|
|
108
|
+
if (component && wrap && (0, _isEditable.default)(config)) {
|
|
109
109
|
var attrs = (0, _cleanAttributes.default)(config, ['fieldId', 'displayMenu']);
|
|
110
110
|
return (0, _wrapInFormGroup.default)(attrs, component);
|
|
111
111
|
}
|
|
@@ -75,7 +75,7 @@ describe('utils', function () {
|
|
|
75
75
|
|
|
76
76
|
var heading = (0, _react.getByTestId)(container, ID);
|
|
77
77
|
expect(heading.innerHTML).toContain(CONTENT);
|
|
78
|
-
expect(heading.tagName).toEqual('
|
|
78
|
+
expect(heading.tagName).toEqual('H2');
|
|
79
79
|
expect(heading.classList).toContain("govuk-heading-".concat(SIZE));
|
|
80
80
|
});
|
|
81
81
|
it('should return an appropriately rendered inset-text component', function () {
|
|
@@ -44,9 +44,9 @@ var setupPageSourceData = function setupPageSourceData(pages, data) {
|
|
|
44
44
|
* 2: fieldC: 'value'
|
|
45
45
|
* In the above example, fieldA will not get a value as fieldB isn't
|
|
46
46
|
* set until after fieldA is processed.
|
|
47
|
-
* @param {
|
|
48
|
-
* @param {
|
|
49
|
-
* @param {
|
|
47
|
+
* @param {Array} pages
|
|
48
|
+
* @param {Array} components
|
|
49
|
+
* @param {object} baseData
|
|
50
50
|
* @returns
|
|
51
51
|
*/
|
|
52
52
|
|
|
@@ -203,12 +203,12 @@ describe('utils', function () {
|
|
|
203
203
|
// and data calculated for the fields, based on that source data.
|
|
204
204
|
|
|
205
205
|
expect(RESULT).toEqual(_objectSpread(_objectSpread({}, _userProfileData.default), {}, {
|
|
206
|
-
firstName: _userProfileData.default.
|
|
207
|
-
surname: _userProfileData.default.
|
|
208
|
-
team: _userProfileData.default.
|
|
209
|
-
staffGradeId: _userProfileData.default.
|
|
210
|
-
linemanagerEmail: _userProfileData.default.
|
|
211
|
-
delegateEmails: _userProfileData.default.
|
|
206
|
+
firstName: _userProfileData.default.currentUser.givenName,
|
|
207
|
+
surname: _userProfileData.default.currentUser.familyName,
|
|
208
|
+
team: _userProfileData.default.userDetails.defaultteam,
|
|
209
|
+
staffGradeId: _userProfileData.default.userDetails.gradeid,
|
|
210
|
+
linemanagerEmail: _userProfileData.default.userDetails.linemanagerEmail,
|
|
211
|
+
delegateEmails: _userProfileData.default.userDetails.delegateEmails
|
|
212
212
|
}));
|
|
213
213
|
});
|
|
214
214
|
});
|
|
@@ -9,7 +9,7 @@ describe('utils', function () {
|
|
|
9
9
|
describe('Data', function () {
|
|
10
10
|
describe('setupRefDataUrlForComponent', function () {
|
|
11
11
|
var DATA = {
|
|
12
|
-
|
|
12
|
+
urls: {
|
|
13
13
|
refData: '/ref-data'
|
|
14
14
|
}
|
|
15
15
|
};
|
|
@@ -39,13 +39,13 @@ describe('utils', function () {
|
|
|
39
39
|
id: 'component',
|
|
40
40
|
// eslint-disable-next-line no-template-curly-in-string
|
|
41
41
|
data: {
|
|
42
|
-
url: '${
|
|
42
|
+
url: '${urls.refData}/v1/teams'
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
45
|
expect((0, _setupRefDataUrlForComponent.default)(COMPONENT, DATA)).toEqual({
|
|
46
46
|
id: COMPONENT.id,
|
|
47
47
|
data: {
|
|
48
|
-
url: "".concat(DATA.
|
|
48
|
+
url: "".concat(DATA.urls.refData, "/v1/teams")
|
|
49
49
|
}
|
|
50
50
|
});
|
|
51
51
|
});
|
|
@@ -68,7 +68,7 @@ describe('utils', function () {
|
|
|
68
68
|
id: 'component',
|
|
69
69
|
// eslint-disable-next-line no-template-curly-in-string
|
|
70
70
|
data: {
|
|
71
|
-
url: '${
|
|
71
|
+
url: '${urls.referenceData}/v1/teams'
|
|
72
72
|
}
|
|
73
73
|
};
|
|
74
74
|
expect((0, _setupRefDataUrlForComponent.default)(COMPONENT, DATA)).toEqual({
|
|
@@ -19,7 +19,18 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
19
19
|
|
|
20
20
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Converts a page object defined in the JSON to a page object for rendering.
|
|
24
|
+
* @param {object} pageOptions The JSON page.
|
|
25
|
+
* @param {Array} formComponents The components defined at the top-level of the form.
|
|
26
|
+
* @param {object} formData The top-level form data, used for setting up components.
|
|
27
|
+
* @returns A page object for rendering.
|
|
28
|
+
*/
|
|
22
29
|
var getFormPage = function getFormPage(pageOptions, formComponents, formData) {
|
|
30
|
+
if (!pageOptions) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
23
34
|
var components = pageOptions.components.map(function (componentOptions) {
|
|
24
35
|
if (typeof componentOptions === 'string') {
|
|
25
36
|
return (0, _getParagraphFromText.default)(componentOptions);
|
|
@@ -33,7 +44,7 @@ var getFormPage = function getFormPage(pageOptions, formComponents, formData) {
|
|
|
33
44
|
ret = _objectSpread({}, componentOptions);
|
|
34
45
|
}
|
|
35
46
|
|
|
36
|
-
return formData && formData.
|
|
47
|
+
return formData && formData.urls ? _Data.default.refData.setupUrl(ret, formData) : ret;
|
|
37
48
|
});
|
|
38
49
|
return _objectSpread(_objectSpread({}, pageOptions), {}, {
|
|
39
50
|
formData: formData,
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _getFormPage = _interopRequireDefault(require("./getFormPage"));
|
|
4
|
+
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
+
|
|
7
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
8
|
+
|
|
9
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
10
|
+
|
|
11
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
12
|
+
|
|
13
|
+
describe('utils', function () {
|
|
14
|
+
describe('FormPage', function () {
|
|
15
|
+
describe('getFormPage', function () {
|
|
16
|
+
var FORM_COMPONENTS = [{
|
|
17
|
+
id: 'a',
|
|
18
|
+
fieldId: 'a',
|
|
19
|
+
label: 'Alpha',
|
|
20
|
+
type: 'text'
|
|
21
|
+
}, {
|
|
22
|
+
id: 'b',
|
|
23
|
+
fieldId: 'b',
|
|
24
|
+
label: 'Bravo',
|
|
25
|
+
type: 'text'
|
|
26
|
+
}, // eslint-disable-next-line no-template-curly-in-string
|
|
27
|
+
{
|
|
28
|
+
id: 'c',
|
|
29
|
+
fieldId: 'c',
|
|
30
|
+
label: 'Charlie',
|
|
31
|
+
type: 'radios',
|
|
32
|
+
data: {
|
|
33
|
+
url: '${urls.refData}/v3/charlies'
|
|
34
|
+
}
|
|
35
|
+
}];
|
|
36
|
+
var FORM_DATA = {
|
|
37
|
+
urls: {
|
|
38
|
+
refData: 'https://ho.gov.uk/ref-data/'
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
it('should handle null or undefined pageOptions', function () {
|
|
42
|
+
expect((0, _getFormPage.default)(null, FORM_COMPONENTS, FORM_DATA)).toBeNull();
|
|
43
|
+
expect((0, _getFormPage.default)(undefined, FORM_COMPONENTS, FORM_DATA)).toBeNull();
|
|
44
|
+
});
|
|
45
|
+
it('should handle a page not using any form components', function () {
|
|
46
|
+
var PAGE = {
|
|
47
|
+
title: 'Page',
|
|
48
|
+
components: [{
|
|
49
|
+
type: 'heading',
|
|
50
|
+
size: 'l',
|
|
51
|
+
content: 'Page heading'
|
|
52
|
+
}]
|
|
53
|
+
};
|
|
54
|
+
expect((0, _getFormPage.default)(PAGE, FORM_COMPONENTS, FORM_DATA)).toEqual({
|
|
55
|
+
title: PAGE.title,
|
|
56
|
+
components: PAGE.components,
|
|
57
|
+
formData: FORM_DATA
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
it('should handle a page with inline strings and convert them to paragraphs', function () {
|
|
61
|
+
var PAGE = {
|
|
62
|
+
title: 'Page',
|
|
63
|
+
components: ["Opening paragraph", {
|
|
64
|
+
type: 'heading',
|
|
65
|
+
size: 'l',
|
|
66
|
+
content: 'Page heading'
|
|
67
|
+
}, "Closing paragraph"]
|
|
68
|
+
};
|
|
69
|
+
expect((0, _getFormPage.default)(PAGE, FORM_COMPONENTS, FORM_DATA)).toEqual({
|
|
70
|
+
title: PAGE.title,
|
|
71
|
+
components: [{
|
|
72
|
+
type: 'html',
|
|
73
|
+
tagName: 'p',
|
|
74
|
+
content: PAGE.components[0]
|
|
75
|
+
}, PAGE.components[1], {
|
|
76
|
+
type: 'html',
|
|
77
|
+
tagName: 'p',
|
|
78
|
+
content: PAGE.components[2]
|
|
79
|
+
}],
|
|
80
|
+
formData: FORM_DATA
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
it('should handle a page that references a form-level component', function () {
|
|
84
|
+
var PAGE = {
|
|
85
|
+
title: 'Page',
|
|
86
|
+
components: ["Opening paragraph", {
|
|
87
|
+
type: 'heading',
|
|
88
|
+
size: 'l',
|
|
89
|
+
content: 'Page heading'
|
|
90
|
+
}, "Closing paragraph", {
|
|
91
|
+
use: 'a'
|
|
92
|
+
}]
|
|
93
|
+
};
|
|
94
|
+
var A = FORM_COMPONENTS[0];
|
|
95
|
+
expect((0, _getFormPage.default)(PAGE, FORM_COMPONENTS, FORM_DATA)).toEqual({
|
|
96
|
+
title: PAGE.title,
|
|
97
|
+
components: [{
|
|
98
|
+
type: 'html',
|
|
99
|
+
tagName: 'p',
|
|
100
|
+
content: PAGE.components[0]
|
|
101
|
+
}, PAGE.components[1], {
|
|
102
|
+
type: 'html',
|
|
103
|
+
tagName: 'p',
|
|
104
|
+
content: PAGE.components[2]
|
|
105
|
+
}, _objectSpread(_objectSpread({
|
|
106
|
+
use: 'a'
|
|
107
|
+
}, A), {}, {
|
|
108
|
+
cya_label: A.label
|
|
109
|
+
})],
|
|
110
|
+
formData: FORM_DATA
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
it('should handle a page that references a form-level component with a data url', function () {
|
|
114
|
+
var PAGE = {
|
|
115
|
+
title: 'Page',
|
|
116
|
+
components: ["Opening paragraph", {
|
|
117
|
+
type: 'heading',
|
|
118
|
+
size: 'l',
|
|
119
|
+
content: 'Page heading'
|
|
120
|
+
}, "Closing paragraph", {
|
|
121
|
+
use: 'c'
|
|
122
|
+
}]
|
|
123
|
+
};
|
|
124
|
+
var C = FORM_COMPONENTS[2];
|
|
125
|
+
expect((0, _getFormPage.default)(PAGE, FORM_COMPONENTS, FORM_DATA)).toEqual({
|
|
126
|
+
title: PAGE.title,
|
|
127
|
+
components: [{
|
|
128
|
+
type: 'html',
|
|
129
|
+
tagName: 'p',
|
|
130
|
+
content: PAGE.components[0]
|
|
131
|
+
}, PAGE.components[1], {
|
|
132
|
+
type: 'html',
|
|
133
|
+
tagName: 'p',
|
|
134
|
+
content: PAGE.components[2]
|
|
135
|
+
}, _objectSpread(_objectSpread({
|
|
136
|
+
use: 'c'
|
|
137
|
+
}, C), {}, {
|
|
138
|
+
cya_label: C.label,
|
|
139
|
+
data: {
|
|
140
|
+
url: "".concat(FORM_DATA.urls.refData, "/v3/charlies")
|
|
141
|
+
}
|
|
142
|
+
})],
|
|
143
|
+
formData: FORM_DATA
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
it('should handle a page that references a form-level component with a data url without an environment context', function () {
|
|
147
|
+
var PAGE = {
|
|
148
|
+
title: 'Page',
|
|
149
|
+
components: ["Opening paragraph", {
|
|
150
|
+
type: 'heading',
|
|
151
|
+
size: 'l',
|
|
152
|
+
content: 'Page heading'
|
|
153
|
+
}, "Closing paragraph", {
|
|
154
|
+
use: 'c'
|
|
155
|
+
}]
|
|
156
|
+
};
|
|
157
|
+
var C = FORM_COMPONENTS[2];
|
|
158
|
+
expect((0, _getFormPage.default)(PAGE, FORM_COMPONENTS, {})).toEqual({
|
|
159
|
+
title: PAGE.title,
|
|
160
|
+
components: [{
|
|
161
|
+
type: 'html',
|
|
162
|
+
tagName: 'p',
|
|
163
|
+
content: PAGE.components[0]
|
|
164
|
+
}, PAGE.components[1], {
|
|
165
|
+
type: 'html',
|
|
166
|
+
tagName: 'p',
|
|
167
|
+
content: PAGE.components[2]
|
|
168
|
+
}, _objectSpread(_objectSpread({
|
|
169
|
+
use: 'c'
|
|
170
|
+
}, C), {}, {
|
|
171
|
+
cya_label: C.label
|
|
172
|
+
})],
|
|
173
|
+
formData: {}
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
});
|
|
@@ -15,18 +15,23 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
15
15
|
|
|
16
16
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Converts pages objects defined in the JSON to page objects for rendering.
|
|
20
|
+
* @param {Array} pages The JSON pages.
|
|
21
|
+
* @param {Array} components The components defined at the top-level of the form.
|
|
22
|
+
* @param {object} formData The top-level form data, used for setting up components.
|
|
23
|
+
* @returns An array of page objects for rendering.
|
|
24
|
+
*/
|
|
18
25
|
var getFormPages = function getFormPages(pages, components, formData) {
|
|
19
|
-
var formPages = [];
|
|
20
|
-
|
|
21
26
|
if (Array.isArray(pages)) {
|
|
22
|
-
pages.
|
|
23
|
-
|
|
27
|
+
return pages.map(function (options, index) {
|
|
28
|
+
return _objectSpread(_objectSpread({}, (0, _getFormPage.default)(options, components, formData)), {}, {
|
|
24
29
|
index: index
|
|
25
|
-
})
|
|
30
|
+
});
|
|
26
31
|
});
|
|
27
32
|
}
|
|
28
33
|
|
|
29
|
-
return
|
|
34
|
+
return [];
|
|
30
35
|
};
|
|
31
36
|
|
|
32
37
|
var _default = getFormPages;
|