@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
|
@@ -4,6 +4,8 @@ var _react = require("@testing-library/react");
|
|
|
4
4
|
|
|
5
5
|
var _react2 = _interopRequireDefault(require("react"));
|
|
6
6
|
|
|
7
|
+
var _models = require("../../models");
|
|
8
|
+
|
|
7
9
|
var _ActionButton = require("./ActionButton");
|
|
8
10
|
|
|
9
11
|
var _PageActions = _interopRequireDefault(require("./PageActions"));
|
|
@@ -67,7 +69,7 @@ describe('components', function () {
|
|
|
67
69
|
_react.fireEvent.click(submit, {});
|
|
68
70
|
|
|
69
71
|
expect(ON_ACTION_CALLS.length).toEqual(1);
|
|
70
|
-
expect(ON_ACTION_CALLS[0]).toEqual(
|
|
72
|
+
expect(ON_ACTION_CALLS[0]).toEqual(_models.PageAction.DEFAULTS.submit);
|
|
71
73
|
|
|
72
74
|
case 10:
|
|
73
75
|
case "end":
|
|
@@ -142,7 +144,7 @@ describe('components', function () {
|
|
|
142
144
|
|
|
143
145
|
expect(ON_ACTION_CALLS.length).toEqual(2);
|
|
144
146
|
expect(ON_ACTION_CALLS[0]).toEqual(NAVIGATE);
|
|
145
|
-
expect(ON_ACTION_CALLS[1]).toEqual(
|
|
147
|
+
expect(ON_ACTION_CALLS[1]).toEqual(_models.PageAction.DEFAULTS.submit);
|
|
146
148
|
|
|
147
149
|
case 16:
|
|
148
150
|
case "end":
|
|
@@ -12,23 +12,13 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
12
12
|
// Local imports
|
|
13
13
|
describe('components', function () {
|
|
14
14
|
describe('SummaryList.RowAction', function () {
|
|
15
|
-
it('should handle a null row', function () {
|
|
16
|
-
var ROW = null;
|
|
17
|
-
|
|
18
|
-
var _render = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_RowAction.default, {
|
|
19
|
-
row: ROW
|
|
20
|
-
})),
|
|
21
|
-
container = _render.container;
|
|
22
|
-
|
|
23
|
-
expect(container.childNodes.length).toEqual(0);
|
|
24
|
-
});
|
|
25
15
|
it('should handle a row without an action', function () {
|
|
26
16
|
var ROW = {};
|
|
27
17
|
|
|
28
|
-
var
|
|
18
|
+
var _render = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_RowAction.default, {
|
|
29
19
|
row: ROW
|
|
30
20
|
})),
|
|
31
|
-
container =
|
|
21
|
+
container = _render.container;
|
|
32
22
|
|
|
33
23
|
expect(container.childNodes.length).toEqual(0);
|
|
34
24
|
});
|
|
@@ -41,10 +31,10 @@ describe('components', function () {
|
|
|
41
31
|
}
|
|
42
32
|
};
|
|
43
33
|
|
|
44
|
-
var
|
|
34
|
+
var _render2 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_RowAction.default, {
|
|
45
35
|
row: ROW
|
|
46
36
|
})),
|
|
47
|
-
container =
|
|
37
|
+
container = _render2.container;
|
|
48
38
|
|
|
49
39
|
var link = container.childNodes[0];
|
|
50
40
|
expect(link.tagName).toEqual('A');
|
|
@@ -61,10 +51,10 @@ describe('components', function () {
|
|
|
61
51
|
}
|
|
62
52
|
};
|
|
63
53
|
|
|
64
|
-
var
|
|
54
|
+
var _render3 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_RowAction.default, {
|
|
65
55
|
row: ROW
|
|
66
56
|
})),
|
|
67
|
-
container =
|
|
57
|
+
container = _render3.container;
|
|
68
58
|
|
|
69
59
|
var link = container.childNodes[0];
|
|
70
60
|
expect(link.tagName).toEqual('A');
|
|
@@ -85,10 +75,10 @@ describe('components', function () {
|
|
|
85
75
|
}
|
|
86
76
|
};
|
|
87
77
|
|
|
88
|
-
var
|
|
78
|
+
var _render4 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_RowAction.default, {
|
|
89
79
|
row: ROW
|
|
90
80
|
})),
|
|
91
|
-
container =
|
|
81
|
+
container = _render4.container;
|
|
92
82
|
|
|
93
83
|
var link = container.childNodes[0];
|
|
94
84
|
expect(link.tagName).toEqual('A');
|
|
@@ -39,17 +39,17 @@ var SummaryList = function SummaryList(_ref) {
|
|
|
39
39
|
|
|
40
40
|
return /*#__PURE__*/_react.default.createElement("dl", _extends({}, attrs, {
|
|
41
41
|
className: classes()
|
|
42
|
-
}), rows.map(function (row
|
|
42
|
+
}), rows.map(function (row) {
|
|
43
43
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
44
|
-
key:
|
|
44
|
+
key: "".concat(row.pageId, "_").concat(row.fieldId),
|
|
45
45
|
className: classes('row')
|
|
46
46
|
}, /*#__PURE__*/_react.default.createElement("dt", {
|
|
47
47
|
className: classes('key')
|
|
48
48
|
}, row.key), /*#__PURE__*/_react.default.createElement("dd", {
|
|
49
49
|
className: classes('value')
|
|
50
|
-
}, row.value),
|
|
50
|
+
}, row.value), /*#__PURE__*/_react.default.createElement("dd", {
|
|
51
51
|
className: classes('actions')
|
|
52
|
-
}, /*#__PURE__*/_react.default.createElement(_RowAction.default, {
|
|
52
|
+
}, row.action && /*#__PURE__*/_react.default.createElement(_RowAction.default, {
|
|
53
53
|
row: row
|
|
54
54
|
})));
|
|
55
55
|
}));
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<!-- Global imports -->
|
|
2
|
+
import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
|
|
3
|
+
import { Details, Heading } from '@ukhomeoffice/cop-react-components';
|
|
4
|
+
|
|
5
|
+
<!-- Local imports -->
|
|
6
|
+
import Utils from '../../utils';
|
|
7
|
+
import SummaryList from './SummaryList';
|
|
8
|
+
|
|
9
|
+
<Meta title="Components/Summary list" id="D-SummaryList" component={ SummaryList } />
|
|
10
|
+
|
|
11
|
+
<Heading size="xl" caption="Components">Summary list</Heading>
|
|
12
|
+
|
|
13
|
+
Renders a list of key-value pairs, most commonly on the **Check your answers** screen, and optionally
|
|
14
|
+
display action links.
|
|
15
|
+
|
|
16
|
+
<Canvas withToolbar>
|
|
17
|
+
<Story name="Default">
|
|
18
|
+
{() => {
|
|
19
|
+
const onAction = (row) => {
|
|
20
|
+
console.log('action clicked', row);
|
|
21
|
+
};
|
|
22
|
+
const ROWS = [
|
|
23
|
+
{ pageId: 'p1', fieldId: 'forename', key: 'Forename(s)', value: 'John' },
|
|
24
|
+
{ pageId: 'p1', fieldId: 'surname', key: 'Surname', value: 'Smith' },
|
|
25
|
+
{ pageId: 'p2', fieldId: 'dob', key: 'Date of birth', value: '29/08/1993', action: { label: 'Change', onAction } },
|
|
26
|
+
];
|
|
27
|
+
return (
|
|
28
|
+
<SummaryList rows={ROWS} />
|
|
29
|
+
);
|
|
30
|
+
}}
|
|
31
|
+
</Story>
|
|
32
|
+
</Canvas>
|
|
33
|
+
|
|
34
|
+
<Details summary="Properties" className="no-indent">
|
|
35
|
+
<ArgsTable of={ SummaryList } />
|
|
36
|
+
</Details>
|
|
@@ -0,0 +1,197 @@
|
|
|
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 _react = require("@testing-library/react");
|
|
6
|
+
|
|
7
|
+
var _react2 = _interopRequireDefault(require("react"));
|
|
8
|
+
|
|
9
|
+
var _SummaryList = _interopRequireWildcard(require("./SummaryList"));
|
|
10
|
+
|
|
11
|
+
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); }
|
|
12
|
+
|
|
13
|
+
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; }
|
|
14
|
+
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
+
|
|
17
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
18
|
+
|
|
19
|
+
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."); }
|
|
20
|
+
|
|
21
|
+
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); }
|
|
22
|
+
|
|
23
|
+
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; }
|
|
24
|
+
|
|
25
|
+
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; }
|
|
26
|
+
|
|
27
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
28
|
+
|
|
29
|
+
describe('components', function () {
|
|
30
|
+
describe('SummaryList', function () {
|
|
31
|
+
var checkSummaryList = function checkSummaryList(container, id) {
|
|
32
|
+
var summaryList = (0, _react.getByTestId)(container, id);
|
|
33
|
+
expect(summaryList.tagName).toEqual('DL');
|
|
34
|
+
expect(summaryList.classList).toContain(_SummaryList.DEFAULT_CLASS);
|
|
35
|
+
return summaryList;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
var checkRow = function checkRow(summaryList, index) {
|
|
39
|
+
var row = summaryList.childNodes[index];
|
|
40
|
+
expect(row.tagName).toEqual('DIV');
|
|
41
|
+
expect(row.classList).toContain("".concat(_SummaryList.DEFAULT_CLASS, "__row"));
|
|
42
|
+
|
|
43
|
+
var _row$childNodes = _slicedToArray(row.childNodes, 3),
|
|
44
|
+
key = _row$childNodes[0],
|
|
45
|
+
value = _row$childNodes[1],
|
|
46
|
+
actions = _row$childNodes[2];
|
|
47
|
+
|
|
48
|
+
expect(key.tagName).toEqual('DT');
|
|
49
|
+
expect(key.classList).toContain("".concat(_SummaryList.DEFAULT_CLASS, "__key"));
|
|
50
|
+
expect(value.tagName).toEqual('DD');
|
|
51
|
+
expect(value.classList).toContain("".concat(_SummaryList.DEFAULT_CLASS, "__value"));
|
|
52
|
+
expect(actions.tagName).toEqual('DD');
|
|
53
|
+
expect(actions.classList).toContain("".concat(_SummaryList.DEFAULT_CLASS, "__actions"));
|
|
54
|
+
return [key, value, actions];
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
it('should handle an empty rows array', function () {
|
|
58
|
+
var ID = 'test-id';
|
|
59
|
+
var ROWS = [];
|
|
60
|
+
|
|
61
|
+
var _render = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_SummaryList.default, {
|
|
62
|
+
"data-testid": ID,
|
|
63
|
+
rows: ROWS
|
|
64
|
+
})),
|
|
65
|
+
container = _render.container;
|
|
66
|
+
|
|
67
|
+
var summaryList = checkSummaryList(container, ID);
|
|
68
|
+
expect(summaryList.childNodes.length).toEqual(0);
|
|
69
|
+
});
|
|
70
|
+
it('should handle rows with no actions and string values', function () {
|
|
71
|
+
var ID = 'test-id';
|
|
72
|
+
var ROWS = [{
|
|
73
|
+
pageId: 'p1',
|
|
74
|
+
fieldId: 'a',
|
|
75
|
+
key: 'Alpha',
|
|
76
|
+
value: 'Alpha value'
|
|
77
|
+
}, {
|
|
78
|
+
pageId: 'p2',
|
|
79
|
+
fieldId: 'b',
|
|
80
|
+
key: 'Bravo',
|
|
81
|
+
value: 'Bravo value'
|
|
82
|
+
}];
|
|
83
|
+
|
|
84
|
+
var _render2 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_SummaryList.default, {
|
|
85
|
+
"data-testid": ID,
|
|
86
|
+
rows: ROWS
|
|
87
|
+
})),
|
|
88
|
+
container = _render2.container;
|
|
89
|
+
|
|
90
|
+
var summaryList = checkSummaryList(container, ID);
|
|
91
|
+
expect(summaryList.childNodes.length).toEqual(ROWS.length);
|
|
92
|
+
ROWS.forEach(function (row, index) {
|
|
93
|
+
var _checkRow = checkRow(summaryList, index),
|
|
94
|
+
_checkRow2 = _slicedToArray(_checkRow, 3),
|
|
95
|
+
key = _checkRow2[0],
|
|
96
|
+
value = _checkRow2[1],
|
|
97
|
+
actions = _checkRow2[2];
|
|
98
|
+
|
|
99
|
+
expect(key.textContent).toEqual(row.key);
|
|
100
|
+
expect(value.textContent).toEqual(row.value);
|
|
101
|
+
expect(actions.childNodes.length).toEqual(0);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
it('should handle rows with no actions and component values', function () {
|
|
105
|
+
var ID = 'test-id';
|
|
106
|
+
var VALUES = ['Alpha component value', 'Bravo component value'];
|
|
107
|
+
var ROWS = [{
|
|
108
|
+
pageId: 'p1',
|
|
109
|
+
fieldId: 'a',
|
|
110
|
+
key: 'Alpha',
|
|
111
|
+
value: /*#__PURE__*/_react2.default.createElement("div", null, VALUES[0])
|
|
112
|
+
}, {
|
|
113
|
+
pageId: 'p2',
|
|
114
|
+
fieldId: 'b',
|
|
115
|
+
key: 'Bravo',
|
|
116
|
+
value: /*#__PURE__*/_react2.default.createElement("div", null, VALUES[1])
|
|
117
|
+
}];
|
|
118
|
+
|
|
119
|
+
var _render3 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_SummaryList.default, {
|
|
120
|
+
"data-testid": ID,
|
|
121
|
+
rows: ROWS
|
|
122
|
+
})),
|
|
123
|
+
container = _render3.container;
|
|
124
|
+
|
|
125
|
+
var summaryList = checkSummaryList(container, ID);
|
|
126
|
+
expect(summaryList.childNodes.length).toEqual(ROWS.length);
|
|
127
|
+
ROWS.forEach(function (row, index) {
|
|
128
|
+
var _checkRow3 = checkRow(summaryList, index),
|
|
129
|
+
_checkRow4 = _slicedToArray(_checkRow3, 3),
|
|
130
|
+
key = _checkRow4[0],
|
|
131
|
+
value = _checkRow4[1],
|
|
132
|
+
actions = _checkRow4[2];
|
|
133
|
+
|
|
134
|
+
expect(key.textContent).toEqual(row.key);
|
|
135
|
+
expect(value.childNodes.length).toEqual(1);
|
|
136
|
+
var valueDiv = value.childNodes[0];
|
|
137
|
+
expect(valueDiv.tagName).toEqual('DIV');
|
|
138
|
+
expect(valueDiv.textContent).toEqual(VALUES[index]);
|
|
139
|
+
expect(actions.childNodes.length).toEqual(0);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
it('should handle rows with actions', function () {
|
|
143
|
+
var ID = 'test-id';
|
|
144
|
+
var ON_ACTION_CALLS = [];
|
|
145
|
+
|
|
146
|
+
var ON_ACTION = function ON_ACTION(row) {
|
|
147
|
+
ON_ACTION_CALLS.push(row);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
var ROWS = [{
|
|
151
|
+
pageId: 'p1',
|
|
152
|
+
fieldId: 'a',
|
|
153
|
+
key: 'Alpha',
|
|
154
|
+
value: 'Alpha value',
|
|
155
|
+
action: {
|
|
156
|
+
label: 'Change A',
|
|
157
|
+
onAction: ON_ACTION
|
|
158
|
+
}
|
|
159
|
+
}, {
|
|
160
|
+
pageId: 'p2',
|
|
161
|
+
fieldId: 'b',
|
|
162
|
+
key: 'Bravo',
|
|
163
|
+
value: 'Bravo value',
|
|
164
|
+
action: {
|
|
165
|
+
label: 'Change B',
|
|
166
|
+
onAction: ON_ACTION
|
|
167
|
+
}
|
|
168
|
+
}];
|
|
169
|
+
|
|
170
|
+
var _render4 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_SummaryList.default, {
|
|
171
|
+
"data-testid": ID,
|
|
172
|
+
rows: ROWS
|
|
173
|
+
})),
|
|
174
|
+
container = _render4.container;
|
|
175
|
+
|
|
176
|
+
var summaryList = checkSummaryList(container, ID);
|
|
177
|
+
expect(summaryList.childNodes.length).toEqual(ROWS.length);
|
|
178
|
+
ROWS.forEach(function (row, index) {
|
|
179
|
+
var _checkRow5 = checkRow(summaryList, index),
|
|
180
|
+
_checkRow6 = _slicedToArray(_checkRow5, 3),
|
|
181
|
+
key = _checkRow6[0],
|
|
182
|
+
value = _checkRow6[1],
|
|
183
|
+
actions = _checkRow6[2];
|
|
184
|
+
|
|
185
|
+
expect(key.textContent).toEqual(row.key);
|
|
186
|
+
expect(value.textContent).toEqual(row.value);
|
|
187
|
+
var a = actions.childNodes[0];
|
|
188
|
+
expect(a.textContent).toEqual(row.action.label);
|
|
189
|
+
|
|
190
|
+
_react.fireEvent.click(a, {});
|
|
191
|
+
|
|
192
|
+
expect(ON_ACTION_CALLS.length).toEqual(index + 1);
|
|
193
|
+
expect(ON_ACTION_CALLS[index]).toEqual(row);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
});
|
package/dist/hooks/useHooks.js
CHANGED
|
@@ -3,32 +3,29 @@
|
|
|
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', 'onFormLoad', 'onPageChange', 'onSubmit'];
|
|
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 = {
|
|
9
|
-
|
|
10
|
-
return req;
|
|
11
|
-
},
|
|
10
|
+
onFormComplete: function onFormComplete() {},
|
|
12
11
|
onFormLoad: function onFormLoad() {},
|
|
13
12
|
onPageChange: function onPageChange(pageId) {
|
|
14
13
|
return pageId;
|
|
15
14
|
},
|
|
16
|
-
onSubmit: function onSubmit(type, payload, onSuccess, onError) {
|
|
17
|
-
onSuccess();
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
var hooks = {
|
|
21
15
|
onRequest: function onRequest(req) {
|
|
22
16
|
return req;
|
|
23
17
|
},
|
|
24
|
-
onFormLoad: function onFormLoad() {},
|
|
25
|
-
onPageChange: function onPageChange(pageId) {
|
|
26
|
-
return pageId;
|
|
27
|
-
},
|
|
28
18
|
onSubmit: function onSubmit(type, payload, onSuccess, onError) {
|
|
29
|
-
onSuccess();
|
|
19
|
+
if (typeof onSuccess === 'function') onSuccess();
|
|
30
20
|
}
|
|
31
21
|
};
|
|
22
|
+
var hooks = {
|
|
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
|
|
28
|
+
};
|
|
32
29
|
|
|
33
30
|
var addHook = function addHook(name, hook) {
|
|
34
31
|
if (ALLOWED_HOOKS.includes(name)) {
|
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) {
|
|
@@ -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 () {
|