@ukhomeoffice/cop-react-form-renderer 1.0.0 → 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/FormPage/FormPage.js +8 -2
- package/dist/components/FormPage/FormPage.test.js +2 -2
- package/dist/components/FormRenderer/FormRenderer.js +26 -10
- 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 +1 -1
- package/dist/components/SummaryList/helpers/getRowActionAttributes.js +2 -2
- package/dist/components/SummaryList/helpers/getRowActionAttributes.test.js +4 -4
- 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 +24 -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 -361
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _react = require("@testing-library/react");
|
|
4
|
+
|
|
5
|
+
var _models = require("../../../models");
|
|
6
|
+
|
|
7
|
+
var _getComponent = _interopRequireDefault(require("../getComponent"));
|
|
8
|
+
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
|
|
11
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
12
|
+
|
|
13
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
14
|
+
|
|
15
|
+
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); }
|
|
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
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
20
|
+
|
|
21
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
22
|
+
|
|
23
|
+
describe('utils.Component.get', function () {
|
|
24
|
+
it('should return an appropriately rendered text component', function () {
|
|
25
|
+
var ID = 'test-id';
|
|
26
|
+
var FIELD_ID = 'field-id';
|
|
27
|
+
var LABEL = 'label';
|
|
28
|
+
var ON_CHANGE_CALLS = [];
|
|
29
|
+
|
|
30
|
+
var ON_CHANGE = function ON_CHANGE(e) {
|
|
31
|
+
ON_CHANGE_CALLS.push(e.target);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
var COMPONENT = {
|
|
35
|
+
type: _models.ComponentTypes.TEXT,
|
|
36
|
+
id: ID,
|
|
37
|
+
fieldId: FIELD_ID,
|
|
38
|
+
label: LABEL,
|
|
39
|
+
onChange: ON_CHANGE,
|
|
40
|
+
'data-testid': ID
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
var _render = (0, _react.render)((0, _getComponent.default)(COMPONENT)),
|
|
44
|
+
container = _render.container;
|
|
45
|
+
|
|
46
|
+
var _getAllByTestId = (0, _react.getAllByTestId)(container, ID),
|
|
47
|
+
_getAllByTestId2 = _slicedToArray(_getAllByTestId, 2),
|
|
48
|
+
formGroup = _getAllByTestId2[0],
|
|
49
|
+
input = _getAllByTestId2[1];
|
|
50
|
+
|
|
51
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
52
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
53
|
+
var label = undefined;
|
|
54
|
+
formGroup.childNodes.forEach(function (node) {
|
|
55
|
+
// Check if it's an element.
|
|
56
|
+
if (node instanceof Element && node.tagName === 'LABEL') {
|
|
57
|
+
label = node;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
expect(label).toBeDefined();
|
|
61
|
+
expect(label.innerHTML).toContain(LABEL);
|
|
62
|
+
expect(label.getAttribute('for')).toEqual(ID);
|
|
63
|
+
expect(input.tagName).toEqual('INPUT');
|
|
64
|
+
expect(input.classList).toContain('govuk-input');
|
|
65
|
+
expect(input.id).toEqual(ID);
|
|
66
|
+
|
|
67
|
+
_react.fireEvent.change(input, {
|
|
68
|
+
target: {
|
|
69
|
+
name: FIELD_ID,
|
|
70
|
+
value: 'blah'
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
expect(ON_CHANGE_CALLS.length).toEqual(1);
|
|
75
|
+
expect(ON_CHANGE_CALLS[0]).toMatchObject({
|
|
76
|
+
name: FIELD_ID,
|
|
77
|
+
value: 'blah'
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _react = require("@testing-library/react");
|
|
4
|
+
|
|
5
|
+
var _models = require("../../../models");
|
|
6
|
+
|
|
7
|
+
var _getComponent = _interopRequireDefault(require("../getComponent"));
|
|
8
|
+
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
|
|
11
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
12
|
+
|
|
13
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
14
|
+
|
|
15
|
+
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); }
|
|
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
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
20
|
+
|
|
21
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
22
|
+
|
|
23
|
+
describe('utils.Component.get', function () {
|
|
24
|
+
it('should return an appropriately rendered textarea component', function () {
|
|
25
|
+
var ID = 'test-id';
|
|
26
|
+
var FIELD_ID = 'field-id';
|
|
27
|
+
var LABEL = 'label';
|
|
28
|
+
var ROWS = 13;
|
|
29
|
+
var ON_CHANGE_CALLS = [];
|
|
30
|
+
|
|
31
|
+
var ON_CHANGE = function ON_CHANGE(e) {
|
|
32
|
+
ON_CHANGE_CALLS.push(e.target);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
var COMPONENT = {
|
|
36
|
+
type: _models.ComponentTypes.TEXT_AREA,
|
|
37
|
+
id: ID,
|
|
38
|
+
fieldId: FIELD_ID,
|
|
39
|
+
label: LABEL,
|
|
40
|
+
rows: ROWS,
|
|
41
|
+
onChange: ON_CHANGE,
|
|
42
|
+
'data-testid': ID
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
var _render = (0, _react.render)((0, _getComponent.default)(COMPONENT)),
|
|
46
|
+
container = _render.container;
|
|
47
|
+
|
|
48
|
+
var _getAllByTestId = (0, _react.getAllByTestId)(container, ID),
|
|
49
|
+
_getAllByTestId2 = _slicedToArray(_getAllByTestId, 2),
|
|
50
|
+
formGroup = _getAllByTestId2[0],
|
|
51
|
+
textarea = _getAllByTestId2[1];
|
|
52
|
+
|
|
53
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
54
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
55
|
+
var label = formGroup.childNodes[0];
|
|
56
|
+
expect(label.innerHTML).toContain(LABEL);
|
|
57
|
+
expect(label.getAttribute('for')).toEqual(ID);
|
|
58
|
+
expect(textarea.tagName).toEqual('TEXTAREA');
|
|
59
|
+
expect(textarea.classList).toContain('govuk-textarea');
|
|
60
|
+
expect(textarea.getAttribute('rows')).toEqual("".concat(ROWS));
|
|
61
|
+
expect(textarea.id).toEqual(ID);
|
|
62
|
+
|
|
63
|
+
_react.fireEvent.change(textarea, {
|
|
64
|
+
target: {
|
|
65
|
+
name: FIELD_ID,
|
|
66
|
+
value: 'Some text'
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
expect(ON_CHANGE_CALLS.length).toEqual(1);
|
|
71
|
+
expect(ON_CHANGE_CALLS[0]).toMatchObject({
|
|
72
|
+
name: FIELD_ID,
|
|
73
|
+
value: 'Some text'
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _getComponent = _interopRequireDefault(require("../getComponent"));
|
|
4
|
+
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
+
|
|
7
|
+
// Local imports
|
|
8
|
+
describe('utils.Component.get', function () {
|
|
9
|
+
it('should return null for an unknown type', function () {
|
|
10
|
+
expect((0, _getComponent.default)({
|
|
11
|
+
type: 'unknown'
|
|
12
|
+
})).toBeNull();
|
|
13
|
+
});
|
|
14
|
+
});
|
|
@@ -8,7 +8,7 @@ exports.default = exports.EDITABLE_TYPES = void 0;
|
|
|
8
8
|
var _models = require("../../models");
|
|
9
9
|
|
|
10
10
|
// Local imports
|
|
11
|
-
var EDITABLE_TYPES = [_models.ComponentTypes.AUTOCOMPLETE, _models.ComponentTypes.EMAIL, _models.ComponentTypes.PHONE_NUMBER, _models.ComponentTypes.RADIOS, _models.ComponentTypes.TEXT, _models.ComponentTypes.TEXT_AREA];
|
|
11
|
+
var EDITABLE_TYPES = [_models.ComponentTypes.AUTOCOMPLETE, _models.ComponentTypes.CHECKBOXES, _models.ComponentTypes.DATE, _models.ComponentTypes.EMAIL, _models.ComponentTypes.PHONE_NUMBER, _models.ComponentTypes.RADIOS, _models.ComponentTypes.TEXT, _models.ComponentTypes.TEXT_AREA];
|
|
12
12
|
exports.EDITABLE_TYPES = EDITABLE_TYPES;
|
|
13
13
|
|
|
14
14
|
var isEditable = function isEditable(options) {
|
|
@@ -19,6 +19,10 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
19
19
|
var refDataToOptions = function refDataToOptions(refDataItems) {
|
|
20
20
|
if (Array.isArray(refDataItems)) {
|
|
21
21
|
return refDataItems.map(function (opt) {
|
|
22
|
+
if (typeof opt === 'string') {
|
|
23
|
+
return opt;
|
|
24
|
+
}
|
|
25
|
+
|
|
22
26
|
return _objectSpread(_objectSpread({}, opt), {}, {
|
|
23
27
|
value: opt.id || opt.value,
|
|
24
28
|
label: opt.name || opt.label
|
|
@@ -94,6 +94,36 @@ describe('utils', function () {
|
|
|
94
94
|
type: 'Delta'
|
|
95
95
|
}]);
|
|
96
96
|
});
|
|
97
|
+
it('can handle refData that contains strings and objects', function () {
|
|
98
|
+
var REF_DATA = [{
|
|
99
|
+
id: 'a',
|
|
100
|
+
name: 'Alpha',
|
|
101
|
+
type: 'Delta'
|
|
102
|
+
}, {
|
|
103
|
+
value: 'b',
|
|
104
|
+
label: 'Bravo'
|
|
105
|
+
}, 'Charlie', {
|
|
106
|
+
id: 'd',
|
|
107
|
+
name: 'Delta',
|
|
108
|
+
type: 'Delta'
|
|
109
|
+
}];
|
|
110
|
+
expect((0, _refDataToOptions.default)(REF_DATA)).toEqual([{
|
|
111
|
+
id: 'a',
|
|
112
|
+
name: 'Alpha',
|
|
113
|
+
value: 'a',
|
|
114
|
+
label: 'Alpha',
|
|
115
|
+
type: 'Delta'
|
|
116
|
+
}, {
|
|
117
|
+
value: 'b',
|
|
118
|
+
label: 'Bravo'
|
|
119
|
+
}, 'Charlie', {
|
|
120
|
+
id: 'd',
|
|
121
|
+
name: 'Delta',
|
|
122
|
+
value: 'd',
|
|
123
|
+
label: 'Delta',
|
|
124
|
+
type: 'Delta'
|
|
125
|
+
}]);
|
|
126
|
+
});
|
|
97
127
|
});
|
|
98
128
|
});
|
|
99
129
|
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _Component = _interopRequireDefault(require("../Component"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Gets all the editable components on a page.
|
|
14
|
+
* @param {object} page The page to consider.
|
|
15
|
+
* @returns An array of ONLY the editable components on a page.
|
|
16
|
+
*/
|
|
17
|
+
var getEditableComponents = function getEditableComponents(page) {
|
|
18
|
+
if (page && Array.isArray(page.components)) {
|
|
19
|
+
return page.components.filter(function (c) {
|
|
20
|
+
return _Component.default.editable(c);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return [];
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
var _default = getEditableComponents;
|
|
28
|
+
exports.default = _default;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _getEditableComponents = _interopRequireDefault(require("./getEditableComponents"));
|
|
4
|
+
|
|
5
|
+
var _isEditable = require("../Component/isEditable");
|
|
6
|
+
|
|
7
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
|
+
|
|
9
|
+
describe('utils', function () {
|
|
10
|
+
describe('FormPage', function () {
|
|
11
|
+
describe('getEditableComponents', function () {
|
|
12
|
+
var HTML = {
|
|
13
|
+
type: 'html',
|
|
14
|
+
tagName: 'p',
|
|
15
|
+
content: 'Alpha'
|
|
16
|
+
};
|
|
17
|
+
var INSET_TEXT = {
|
|
18
|
+
type: 'inset-text',
|
|
19
|
+
content: 'Bravo'
|
|
20
|
+
};
|
|
21
|
+
var HEADING = {
|
|
22
|
+
type: 'heading',
|
|
23
|
+
size: 'm',
|
|
24
|
+
content: 'Charlie'
|
|
25
|
+
};
|
|
26
|
+
it('should return an empty array for a null page', function () {
|
|
27
|
+
expect((0, _getEditableComponents.default)(null)).toEqual([]);
|
|
28
|
+
});
|
|
29
|
+
it('should return an empty array for a page with no components', function () {
|
|
30
|
+
expect((0, _getEditableComponents.default)({
|
|
31
|
+
components: []
|
|
32
|
+
})).toEqual([]);
|
|
33
|
+
});
|
|
34
|
+
it('should return an empty array for a page with only non-editable components', function () {
|
|
35
|
+
var COMPONENTS = [HTML, INSET_TEXT, HEADING];
|
|
36
|
+
expect((0, _getEditableComponents.default)({
|
|
37
|
+
components: COMPONENTS
|
|
38
|
+
})).toEqual([]);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
_isEditable.EDITABLE_TYPES.forEach(function (type) {
|
|
42
|
+
it("should return just the \"".concat(type, "\" component if it exists in the components but no non-editable ones"), function () {
|
|
43
|
+
var EDITABLE = {
|
|
44
|
+
type: type
|
|
45
|
+
};
|
|
46
|
+
var COMPONENTS = [HTML, EDITABLE, INSET_TEXT, HEADING];
|
|
47
|
+
expect((0, _getEditableComponents.default)({
|
|
48
|
+
components: COMPONENTS
|
|
49
|
+
})).toEqual([EDITABLE]);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('should return all editable components and no non-editable ones', function () {
|
|
54
|
+
var COMPONENTS = [HTML, INSET_TEXT, HEADING];
|
|
55
|
+
|
|
56
|
+
_isEditable.EDITABLE_TYPES.forEach(function (type) {
|
|
57
|
+
COMPONENTS.push({
|
|
58
|
+
type: type
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
var RESULT = (0, _getEditableComponents.default)({
|
|
63
|
+
components: COMPONENTS
|
|
64
|
+
});
|
|
65
|
+
expect(RESULT.length).toEqual(_isEditable.EDITABLE_TYPES.length);
|
|
66
|
+
|
|
67
|
+
_isEditable.EDITABLE_TYPES.forEach(function (type) {
|
|
68
|
+
expect(RESULT).toContainEqual({
|
|
69
|
+
type: type
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
});
|
|
@@ -7,6 +7,8 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _Data = _interopRequireDefault(require("../Data"));
|
|
9
9
|
|
|
10
|
+
var _getPageActions = _interopRequireDefault(require("./getPageActions"));
|
|
11
|
+
|
|
10
12
|
var _getParagraphFromText = _interopRequireDefault(require("./getParagraphFromText"));
|
|
11
13
|
|
|
12
14
|
var _useComponent = _interopRequireDefault(require("./useComponent"));
|
|
@@ -46,9 +48,11 @@ var getFormPage = function getFormPage(pageOptions, formComponents, formData) {
|
|
|
46
48
|
|
|
47
49
|
return formData && formData.urls ? _Data.default.refData.setupUrl(ret, formData) : ret;
|
|
48
50
|
});
|
|
51
|
+
var actions = (0, _getPageActions.default)(pageOptions);
|
|
49
52
|
return _objectSpread(_objectSpread({}, pageOptions), {}, {
|
|
50
53
|
formData: formData,
|
|
51
|
-
components: components
|
|
54
|
+
components: components,
|
|
55
|
+
actions: actions
|
|
52
56
|
});
|
|
53
57
|
};
|
|
54
58
|
|
|
@@ -0,0 +1,66 @@
|
|
|
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
|
+
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); }
|
|
11
|
+
|
|
12
|
+
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; }
|
|
13
|
+
|
|
14
|
+
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; }
|
|
15
|
+
|
|
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
|
+
|
|
18
|
+
var standardiseAction = function standardiseAction(obj) {
|
|
19
|
+
var action = _objectSpread({}, obj); // This is in place for backwards compatibility with version 1.
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
if (!action.page) {
|
|
23
|
+
if (action.href) {
|
|
24
|
+
action.page = action.href.split('/').pop();
|
|
25
|
+
} else if (action.url) {
|
|
26
|
+
action.page = action.url.split('/').pop();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return action;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Gets an array of standardised action objects for a page.
|
|
34
|
+
* @param {object} page The page to get the actions for.
|
|
35
|
+
* @returns Standardised action objects.
|
|
36
|
+
* @description Standardises actions specified on a page into ones suitable for this version of the
|
|
37
|
+
* Form Renderer.
|
|
38
|
+
*
|
|
39
|
+
* `action.href` and `action.url` have been deprecated in favour of `action.page` but this method
|
|
40
|
+
* will convert both by taking the final part of the relative path:
|
|
41
|
+
* - `href: '/bravo'` => `page: 'bravo'`
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
var getPageActions = function getPageActions(page) {
|
|
46
|
+
if (page && Array.isArray(page.actions)) {
|
|
47
|
+
return page.actions.map(function (a) {
|
|
48
|
+
if (typeof a === 'string') {
|
|
49
|
+
return _models.PageAction.DEFAULTS[a];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (a && _typeof(a) === 'object') {
|
|
53
|
+
return standardiseAction(a);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return undefined;
|
|
57
|
+
}).filter(function (a) {
|
|
58
|
+
return !!a;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return undefined;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
var _default = getPageActions;
|
|
66
|
+
exports.default = _default;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _models = require("../../models");
|
|
4
|
+
|
|
5
|
+
var _getPageActions = _interopRequireDefault(require("./getPageActions"));
|
|
6
|
+
|
|
7
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
|
+
|
|
9
|
+
// Local imports
|
|
10
|
+
describe('utils', function () {
|
|
11
|
+
describe('FormPage', function () {
|
|
12
|
+
describe('getPageActions', function () {
|
|
13
|
+
it('should handle a null or undefined page', function () {
|
|
14
|
+
expect((0, _getPageActions.default)(null)).toBeUndefined();
|
|
15
|
+
expect((0, _getPageActions.default)(undefined)).toBeUndefined();
|
|
16
|
+
});
|
|
17
|
+
it('should handle a null or undefined actions array', function () {
|
|
18
|
+
expect((0, _getPageActions.default)({
|
|
19
|
+
actions: null
|
|
20
|
+
})).toBeUndefined();
|
|
21
|
+
expect((0, _getPageActions.default)({
|
|
22
|
+
actions: undefined
|
|
23
|
+
})).toBeUndefined();
|
|
24
|
+
});
|
|
25
|
+
it('should handle an array of strings', function () {
|
|
26
|
+
var actions = [_models.PageAction.TYPES.SAVE_AND_CONTINUE, _models.PageAction.TYPES.SAVE_AND_RETURN];
|
|
27
|
+
expect((0, _getPageActions.default)({
|
|
28
|
+
actions: actions
|
|
29
|
+
})).toEqual([_models.PageAction.DEFAULTS.saveAndContinue, _models.PageAction.DEFAULTS.saveAndReturn]);
|
|
30
|
+
});
|
|
31
|
+
it('should handle a null entry in the array', function () {
|
|
32
|
+
var actions = [_models.PageAction.TYPES.SAVE_AND_CONTINUE, _models.PageAction.TYPES.SAVE_AND_RETURN, null];
|
|
33
|
+
expect((0, _getPageActions.default)({
|
|
34
|
+
actions: actions
|
|
35
|
+
})).toEqual([_models.PageAction.DEFAULTS.saveAndContinue, _models.PageAction.DEFAULTS.saveAndReturn]);
|
|
36
|
+
});
|
|
37
|
+
it('should handle an undefined entry in the array', function () {
|
|
38
|
+
var actions = [undefined, _models.PageAction.TYPES.SAVE_AND_CONTINUE, undefined, _models.PageAction.TYPES.SAVE_AND_RETURN];
|
|
39
|
+
expect((0, _getPageActions.default)({
|
|
40
|
+
actions: actions
|
|
41
|
+
})).toEqual([_models.PageAction.DEFAULTS.saveAndContinue, _models.PageAction.DEFAULTS.saveAndReturn]);
|
|
42
|
+
});
|
|
43
|
+
it('should handle an object entry in the array', function () {
|
|
44
|
+
var actions = [{
|
|
45
|
+
type: 'navigate',
|
|
46
|
+
page: 'alpha'
|
|
47
|
+
}];
|
|
48
|
+
expect((0, _getPageActions.default)({
|
|
49
|
+
actions: actions
|
|
50
|
+
})).toEqual(actions);
|
|
51
|
+
});
|
|
52
|
+
it('should convert an href to a page', function () {
|
|
53
|
+
var actions = [{
|
|
54
|
+
type: 'navigate',
|
|
55
|
+
href: '/alpha/bravo'
|
|
56
|
+
}];
|
|
57
|
+
expect((0, _getPageActions.default)({
|
|
58
|
+
actions: actions
|
|
59
|
+
})).toEqual([{
|
|
60
|
+
type: 'navigate',
|
|
61
|
+
page: 'bravo',
|
|
62
|
+
href: '/alpha/bravo'
|
|
63
|
+
}]);
|
|
64
|
+
});
|
|
65
|
+
it('should convert a url to a page', function () {
|
|
66
|
+
var actions = [{
|
|
67
|
+
type: 'navigate',
|
|
68
|
+
url: '/alpha/bravo'
|
|
69
|
+
}];
|
|
70
|
+
expect((0, _getPageActions.default)({
|
|
71
|
+
actions: actions
|
|
72
|
+
})).toEqual([{
|
|
73
|
+
type: 'navigate',
|
|
74
|
+
page: 'bravo',
|
|
75
|
+
url: '/alpha/bravo'
|
|
76
|
+
}]);
|
|
77
|
+
});
|
|
78
|
+
it('should handle an action without a page, href, or url', function () {
|
|
79
|
+
var actions = [{
|
|
80
|
+
type: 'submit',
|
|
81
|
+
label: 'Charlie'
|
|
82
|
+
}];
|
|
83
|
+
expect((0, _getPageActions.default)({
|
|
84
|
+
actions: actions
|
|
85
|
+
})).toEqual(actions);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -5,15 +5,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
+
var _getEditableComponents = _interopRequireDefault(require("./getEditableComponents"));
|
|
9
|
+
|
|
8
10
|
var _getFormPage = _interopRequireDefault(require("./getFormPage"));
|
|
9
11
|
|
|
10
12
|
var _getFormPages = _interopRequireDefault(require("./getFormPages"));
|
|
11
13
|
|
|
14
|
+
var _showFormPage = _interopRequireDefault(require("./showFormPage"));
|
|
15
|
+
|
|
12
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
17
|
|
|
14
18
|
var FormPage = {
|
|
19
|
+
editableComponents: _getEditableComponents.default,
|
|
15
20
|
get: _getFormPage.default,
|
|
16
|
-
getAll: _getFormPages.default
|
|
21
|
+
getAll: _getFormPages.default,
|
|
22
|
+
show: _showFormPage.default
|
|
17
23
|
};
|
|
18
24
|
var _default = FormPage;
|
|
19
25
|
exports.default = _default;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _Component = _interopRequireDefault(require("../Component"));
|
|
9
|
+
|
|
10
|
+
var _Data = _interopRequireDefault(require("../Data"));
|
|
11
|
+
|
|
12
|
+
var _meetsCondition = _interopRequireDefault(require("../meetsCondition"));
|
|
13
|
+
|
|
14
|
+
var _getEditableComponents = _interopRequireDefault(require("./getEditableComponents"));
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
|
|
18
|
+
// Local imports
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Evaluates the show_when condition(s) on a page.
|
|
22
|
+
* @param {object} page The page to consider.
|
|
23
|
+
* @param {object} data The top-level form data.
|
|
24
|
+
* @returns Boolean true if all show_when conditions are met; false otherwise.
|
|
25
|
+
*/
|
|
26
|
+
var evaluatePageShowWhen = function evaluatePageShowWhen(page, data) {
|
|
27
|
+
var show_when = Array.isArray(page.show_when) ? page.show_when : [page.show_when];
|
|
28
|
+
var allConditionsMet = true;
|
|
29
|
+
show_when.forEach(function (condition) {
|
|
30
|
+
var sourceDataValue = _Data.default.getSource(data, condition.field);
|
|
31
|
+
|
|
32
|
+
allConditionsMet = allConditionsMet && (0, _meetsCondition.default)(condition, sourceDataValue);
|
|
33
|
+
});
|
|
34
|
+
return allConditionsMet;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Checks whether any of the editable components on a page should be shown.
|
|
38
|
+
* @param {Array} editableComponents The editable components on the page.
|
|
39
|
+
* @param {object} data The top-level form data.
|
|
40
|
+
* @returns Boolean true if ANY of the editable components should be shown; false otherwise.
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
var showEditableComponent = function showEditableComponent(editableComponents, data) {
|
|
45
|
+
return editableComponents.reduce(function (shown, component) {
|
|
46
|
+
return shown || _Component.default.show(component, data);
|
|
47
|
+
}, false);
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Indicates whether or not a page should be shown.
|
|
51
|
+
* @param {object} page The page to consider.
|
|
52
|
+
* @param {object} data The top-level form data.
|
|
53
|
+
* @returns Boolean true if the page should be shown; false if not.
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
var showFormPage = function showFormPage(page, data) {
|
|
58
|
+
if (!page) {
|
|
59
|
+
return false;
|
|
60
|
+
} // If the page has a show_when condition, we should evaluate that.
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
if (page.show_when) {
|
|
64
|
+
return evaluatePageShowWhen(page, data);
|
|
65
|
+
} // If the page itself doesn't have a show_when, we need to make sure that if it
|
|
66
|
+
// contains ANY editable components, at least one of them is shown.
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
var editableComponents = (0, _getEditableComponents.default)(page);
|
|
70
|
+
|
|
71
|
+
if (editableComponents.length > 0) {
|
|
72
|
+
return showEditableComponent(editableComponents, data);
|
|
73
|
+
} // At this point, either the page has no show_when condition of its own, or
|
|
74
|
+
// the page has no editable components. In either case, it should be shown.
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
return true;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
var _default = showFormPage;
|
|
81
|
+
exports.default = _default;
|