@ukhomeoffice/cop-react-form-renderer 2.1.0 → 2.6.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/FormComponent/Container.test.js +250 -0
- package/dist/components/FormComponent/FormComponent.js +105 -21
- package/dist/components/FormComponent/FormComponent.test.js +67 -0
- package/dist/components/FormPage/FormPage.js +2 -1
- package/dist/components/FormRenderer/FormRenderer.js +105 -6
- package/dist/components/FormRenderer/FormRenderer.test.js +235 -0
- package/dist/components/FormRenderer/helpers/getNextPageId.js +3 -0
- package/dist/components/FormRenderer/helpers/getNextPageId.test.js +6 -0
- package/dist/components/FormRenderer/helpers/getPage.js +1 -1
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +18 -1
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +44 -6
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.js +50 -0
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.test.js +122 -0
- package/dist/components/FormRenderer/helpers/index.js +7 -1
- package/dist/components/TaskList/Task.js +83 -0
- package/dist/components/TaskList/Task.test.js +112 -0
- package/dist/components/TaskList/TaskList.js +112 -0
- package/dist/components/TaskList/TaskList.scss +70 -0
- package/dist/components/TaskList/TaskList.stories.mdx +57 -0
- package/dist/components/TaskList/TaskList.test.js +223 -0
- package/dist/components/TaskList/TaskState.js +42 -0
- package/dist/components/TaskList/TaskState.test.js +99 -0
- package/dist/components/TaskList/index.js +13 -0
- package/dist/hooks/index.js +19 -1
- package/dist/hooks/useHooks.js +5 -1
- package/dist/json/taskList.json +228 -0
- package/dist/json/userProfile.data.json +2 -1
- package/dist/models/ComponentTypes.js +5 -1
- package/dist/models/FormTypes.js +2 -0
- package/dist/models/HubFormats.js +3 -1
- package/dist/models/PageAction.js +5 -0
- package/dist/models/TaskStates.js +41 -0
- package/dist/models/index.js +8 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.js +40 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.test.js +257 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +9 -1
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +44 -0
- package/dist/utils/CheckYourAnswers/showComponentCYA.js +6 -0
- package/dist/utils/Component/cleanAttributes.js +1 -1
- package/dist/utils/Component/getComponent.js +26 -0
- package/dist/utils/Component/isEditable.js +1 -1
- package/dist/utils/Component/showComponent.js +2 -20
- package/dist/utils/Condition/index.js +19 -0
- package/dist/utils/Condition/meetsAllConditions.js +40 -0
- package/dist/utils/Condition/meetsAllConditions.test.js +62 -0
- package/dist/utils/{meetsCondition.js → Condition/meetsCondition.js} +0 -0
- package/dist/utils/Condition/meetsCondition.test.js +302 -0
- package/dist/utils/Condition/setupConditions.js +47 -0
- package/dist/utils/Condition/setupConditions.test.js +35 -0
- package/dist/utils/Container/getEditableComponents.js +38 -0
- package/dist/utils/Container/getEditableComponents.test.js +157 -0
- package/dist/utils/Container/index.js +22 -0
- package/dist/utils/Container/setupNesting.js +45 -0
- package/dist/utils/Container/setupNesting.test.js +92 -0
- package/dist/utils/Container/showContainer.js +61 -0
- package/dist/utils/Container/showContainer.test.js +128 -0
- package/dist/utils/Data/getDataPath.js +90 -0
- package/dist/utils/Data/getDataPath.test.js +52 -0
- package/dist/utils/Data/index.js +3 -0
- package/dist/utils/FormPage/getFormPage.js +4 -2
- package/dist/utils/FormPage/getFormPage.test.js +18 -7
- package/dist/utils/FormPage/getFormPages.test.js +5 -2
- package/dist/utils/FormPage/getPageActions.js +6 -0
- package/dist/utils/FormPage/index.js +0 -3
- package/dist/utils/FormPage/showFormPage.js +7 -27
- package/dist/utils/Hub/getFormHub.js +4 -0
- package/dist/utils/Hub/getFormHub.test.js +15 -4
- package/dist/utils/Validate/additional/index.js +55 -0
- package/dist/utils/Validate/additional/index.test.js +69 -0
- package/dist/utils/Validate/additional/mustBeAfter.js +37 -0
- package/dist/utils/Validate/additional/mustBeAfter.test.js +98 -0
- package/dist/utils/Validate/additional/mustBeBefore.js +35 -0
- package/dist/utils/Validate/additional/mustBeBefore.test.js +66 -0
- package/dist/utils/Validate/additional/mustBeInTheFuture.js +42 -0
- package/dist/utils/Validate/additional/mustBeInTheFuture.test.js +34 -0
- package/dist/utils/Validate/additional/mustBeInThePast.js +44 -0
- package/dist/utils/Validate/additional/mustBeInThePast.test.js +34 -0
- package/dist/utils/Validate/additional/utils.js +66 -0
- package/dist/utils/Validate/index.js +7 -1
- package/dist/utils/Validate/validateComponent.js +57 -0
- package/dist/utils/Validate/validateComponent.test.js +92 -2
- package/dist/utils/Validate/validateDate.js +155 -0
- package/dist/utils/Validate/validateDate.test.js +118 -0
- package/dist/utils/Validate/validatePage.js +6 -8
- package/dist/utils/Validate/validateTime.js +95 -0
- package/dist/utils/Validate/validateTime.test.js +61 -0
- package/dist/utils/index.js +6 -3
- package/package.json +3 -2
- package/dist/utils/FormPage/getEditableComponents.js +0 -28
- package/dist/utils/FormPage/getEditableComponents.test.js +0 -75
|
@@ -0,0 +1,250 @@
|
|
|
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 _models = require("../../models");
|
|
10
|
+
|
|
11
|
+
var _FormComponent = _interopRequireWildcard(require("./FormComponent"));
|
|
12
|
+
|
|
13
|
+
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); }
|
|
14
|
+
|
|
15
|
+
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; }
|
|
16
|
+
|
|
17
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
+
|
|
19
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
20
|
+
|
|
21
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
22
|
+
|
|
23
|
+
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; }
|
|
24
|
+
|
|
25
|
+
describe('components.FormComponent.Container', function () {
|
|
26
|
+
var _ID;
|
|
27
|
+
|
|
28
|
+
var ID = 'container';
|
|
29
|
+
var NESTED_ID = 'nested';
|
|
30
|
+
var TEXT_ID = 'text';
|
|
31
|
+
var TEXT_VALUE = 'alpha';
|
|
32
|
+
var NESTED_TEXT_VALUE = 'charlie';
|
|
33
|
+
|
|
34
|
+
var FORM_DATA = _defineProperty({}, ID, (_ID = {}, _defineProperty(_ID, TEXT_ID, TEXT_VALUE), _defineProperty(_ID, NESTED_ID, _defineProperty({}, TEXT_ID, NESTED_TEXT_VALUE)), _ID));
|
|
35
|
+
|
|
36
|
+
var TEXT_COMPONENT = {
|
|
37
|
+
id: TEXT_ID,
|
|
38
|
+
fieldId: TEXT_ID,
|
|
39
|
+
type: _models.ComponentTypes.TEXT,
|
|
40
|
+
label: 'Text component',
|
|
41
|
+
hint: 'Text hint'
|
|
42
|
+
};
|
|
43
|
+
it('should render a container component appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
44
|
+
var CONTAINER, _render, container, c, formGroup, label, hint, input;
|
|
45
|
+
|
|
46
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
47
|
+
while (1) {
|
|
48
|
+
switch (_context.prev = _context.next) {
|
|
49
|
+
case 0:
|
|
50
|
+
CONTAINER = {
|
|
51
|
+
id: ID,
|
|
52
|
+
fieldId: ID,
|
|
53
|
+
type: _models.ComponentTypes.CONTAINER,
|
|
54
|
+
components: [TEXT_COMPONENT]
|
|
55
|
+
};
|
|
56
|
+
_render = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
57
|
+
component: CONTAINER,
|
|
58
|
+
value: FORM_DATA[ID],
|
|
59
|
+
formData: FORM_DATA
|
|
60
|
+
})), container = _render.container; // Check the container itself.
|
|
61
|
+
|
|
62
|
+
c = container.childNodes[0];
|
|
63
|
+
expect(c.tagName).toEqual('DIV');
|
|
64
|
+
expect(c.classList).toContain(_FormComponent.DEFAULT_CONTAINER_CLASS); // And now check the single text component within it.
|
|
65
|
+
|
|
66
|
+
formGroup = c.childNodes[0];
|
|
67
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
68
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
69
|
+
label = formGroup.childNodes[0];
|
|
70
|
+
expect(label.tagName).toEqual('LABEL');
|
|
71
|
+
expect(label.classList).toContain('govuk-label');
|
|
72
|
+
expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
73
|
+
expect(label.getAttribute('for')).toEqual(TEXT_ID);
|
|
74
|
+
hint = formGroup.childNodes[1];
|
|
75
|
+
expect(hint.tagName).toEqual('SPAN');
|
|
76
|
+
expect(hint.classList).toContain('govuk-hint');
|
|
77
|
+
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
78
|
+
input = formGroup.childNodes[2];
|
|
79
|
+
expect(input.tagName).toEqual('INPUT');
|
|
80
|
+
expect(input.classList).toContain('govuk-input');
|
|
81
|
+
expect(input.id).toEqual(TEXT_ID);
|
|
82
|
+
expect(input.value).toEqual(TEXT_VALUE);
|
|
83
|
+
|
|
84
|
+
case 22:
|
|
85
|
+
case "end":
|
|
86
|
+
return _context.stop();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}, _callee);
|
|
90
|
+
})));
|
|
91
|
+
it('should render a nested container component appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
|
|
92
|
+
var CONTAINER, _render2, container, c, nested, formGroup, label, hint, input;
|
|
93
|
+
|
|
94
|
+
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
95
|
+
while (1) {
|
|
96
|
+
switch (_context2.prev = _context2.next) {
|
|
97
|
+
case 0:
|
|
98
|
+
CONTAINER = {
|
|
99
|
+
id: ID,
|
|
100
|
+
fieldId: ID,
|
|
101
|
+
type: _models.ComponentTypes.CONTAINER,
|
|
102
|
+
components: [{
|
|
103
|
+
id: NESTED_ID,
|
|
104
|
+
fieldId: NESTED_ID,
|
|
105
|
+
type: _models.ComponentTypes.CONTAINER,
|
|
106
|
+
components: [TEXT_COMPONENT]
|
|
107
|
+
}]
|
|
108
|
+
};
|
|
109
|
+
_render2 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
110
|
+
component: CONTAINER,
|
|
111
|
+
value: FORM_DATA[ID],
|
|
112
|
+
formData: FORM_DATA
|
|
113
|
+
})), container = _render2.container; // Check the container itself.
|
|
114
|
+
|
|
115
|
+
c = container.childNodes[0];
|
|
116
|
+
expect(c.tagName).toEqual('DIV');
|
|
117
|
+
expect(c.classList).toContain(_FormComponent.DEFAULT_CONTAINER_CLASS); // Check the nested container.
|
|
118
|
+
|
|
119
|
+
nested = c.childNodes[0];
|
|
120
|
+
expect(nested.tagName).toEqual('DIV');
|
|
121
|
+
expect(nested.classList).toContain(_FormComponent.DEFAULT_CONTAINER_CLASS); // And now check the single text component within the nested container.
|
|
122
|
+
|
|
123
|
+
formGroup = nested.childNodes[0];
|
|
124
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
125
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
126
|
+
label = formGroup.childNodes[0];
|
|
127
|
+
expect(label.tagName).toEqual('LABEL');
|
|
128
|
+
expect(label.classList).toContain('govuk-label');
|
|
129
|
+
expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
130
|
+
expect(label.getAttribute('for')).toEqual(TEXT_ID);
|
|
131
|
+
hint = formGroup.childNodes[1];
|
|
132
|
+
expect(hint.tagName).toEqual('SPAN');
|
|
133
|
+
expect(hint.classList).toContain('govuk-hint');
|
|
134
|
+
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
135
|
+
input = formGroup.childNodes[2];
|
|
136
|
+
expect(input.tagName).toEqual('INPUT');
|
|
137
|
+
expect(input.classList).toContain('govuk-input');
|
|
138
|
+
expect(input.id).toEqual(TEXT_ID);
|
|
139
|
+
expect(input.value).toEqual(NESTED_TEXT_VALUE);
|
|
140
|
+
|
|
141
|
+
case 25:
|
|
142
|
+
case "end":
|
|
143
|
+
return _context2.stop();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}, _callee2);
|
|
147
|
+
})));
|
|
148
|
+
it('should handle a change to a component appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
|
|
149
|
+
var ON_CHANGE_EVENTS, ON_CHANGE, CONTAINER, _render3, container, c, formGroup, input, NEW_TEXT_VALUE, EVENT;
|
|
150
|
+
|
|
151
|
+
return regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
152
|
+
while (1) {
|
|
153
|
+
switch (_context3.prev = _context3.next) {
|
|
154
|
+
case 0:
|
|
155
|
+
ON_CHANGE_EVENTS = [];
|
|
156
|
+
|
|
157
|
+
ON_CHANGE = function ON_CHANGE(e) {
|
|
158
|
+
ON_CHANGE_EVENTS.push(e);
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
CONTAINER = {
|
|
162
|
+
id: ID,
|
|
163
|
+
fieldId: ID,
|
|
164
|
+
type: _models.ComponentTypes.CONTAINER,
|
|
165
|
+
components: [{
|
|
166
|
+
id: TEXT_ID,
|
|
167
|
+
fieldId: TEXT_ID,
|
|
168
|
+
type: _models.ComponentTypes.TEXT,
|
|
169
|
+
label: 'Text component'
|
|
170
|
+
}]
|
|
171
|
+
};
|
|
172
|
+
_render3 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
173
|
+
component: CONTAINER,
|
|
174
|
+
value: FORM_DATA[ID],
|
|
175
|
+
formData: FORM_DATA,
|
|
176
|
+
onChange: ON_CHANGE
|
|
177
|
+
})), container = _render3.container; // Get hold of the text input.
|
|
178
|
+
|
|
179
|
+
c = container.childNodes[0];
|
|
180
|
+
formGroup = c.childNodes[0];
|
|
181
|
+
input = formGroup.childNodes[2];
|
|
182
|
+
NEW_TEXT_VALUE = 'bravo';
|
|
183
|
+
EVENT = {
|
|
184
|
+
target: {
|
|
185
|
+
name: TEXT_ID,
|
|
186
|
+
value: NEW_TEXT_VALUE
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
_react.fireEvent.change(input, EVENT); // And confirm the formData has been changed.
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
expect(ON_CHANGE_EVENTS.length).toEqual(1);
|
|
194
|
+
expect(ON_CHANGE_EVENTS[0].target.name).toEqual(ID);
|
|
195
|
+
expect(ON_CHANGE_EVENTS[0].target.value[TEXT_ID]).toEqual(NEW_TEXT_VALUE);
|
|
196
|
+
|
|
197
|
+
case 13:
|
|
198
|
+
case "end":
|
|
199
|
+
return _context3.stop();
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}, _callee3);
|
|
203
|
+
})));
|
|
204
|
+
it('should handle a null value appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
|
|
205
|
+
var CONTAINER, _render4, container, c, formGroup, label, hint, input;
|
|
206
|
+
|
|
207
|
+
return regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
208
|
+
while (1) {
|
|
209
|
+
switch (_context4.prev = _context4.next) {
|
|
210
|
+
case 0:
|
|
211
|
+
CONTAINER = {
|
|
212
|
+
id: ID,
|
|
213
|
+
fieldId: ID,
|
|
214
|
+
type: _models.ComponentTypes.CONTAINER,
|
|
215
|
+
components: [TEXT_COMPONENT]
|
|
216
|
+
};
|
|
217
|
+
_render4 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
218
|
+
component: CONTAINER
|
|
219
|
+
})), container = _render4.container; // Check the container itself.
|
|
220
|
+
|
|
221
|
+
c = container.childNodes[0];
|
|
222
|
+
expect(c.tagName).toEqual('DIV');
|
|
223
|
+
expect(c.classList).toContain(_FormComponent.DEFAULT_CONTAINER_CLASS); // And now check the single text component within it.
|
|
224
|
+
|
|
225
|
+
formGroup = c.childNodes[0];
|
|
226
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
227
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
228
|
+
label = formGroup.childNodes[0];
|
|
229
|
+
expect(label.tagName).toEqual('LABEL');
|
|
230
|
+
expect(label.classList).toContain('govuk-label');
|
|
231
|
+
expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
232
|
+
expect(label.getAttribute('for')).toEqual(TEXT_ID);
|
|
233
|
+
hint = formGroup.childNodes[1];
|
|
234
|
+
expect(hint.tagName).toEqual('SPAN');
|
|
235
|
+
expect(hint.classList).toContain('govuk-hint');
|
|
236
|
+
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
237
|
+
input = formGroup.childNodes[2];
|
|
238
|
+
expect(input.tagName).toEqual('INPUT');
|
|
239
|
+
expect(input.classList).toContain('govuk-input');
|
|
240
|
+
expect(input.id).toEqual(TEXT_ID);
|
|
241
|
+
expect(input.value).toEqual('');
|
|
242
|
+
|
|
243
|
+
case 22:
|
|
244
|
+
case "end":
|
|
245
|
+
return _context4.stop();
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}, _callee4);
|
|
249
|
+
})));
|
|
250
|
+
});
|
|
@@ -1,34 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
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
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
|
-
exports.default = void 0;
|
|
6
|
+
exports.default = exports.DEFAULT_CONTAINER_CLASS = void 0;
|
|
9
7
|
|
|
10
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
9
|
|
|
12
10
|
var _react = require("react");
|
|
13
11
|
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
var _utils = _interopRequireDefault(require("../../utils"));
|
|
12
|
+
var _hooks = require("../../hooks");
|
|
17
13
|
|
|
18
|
-
var
|
|
14
|
+
var _models = require("../../models");
|
|
19
15
|
|
|
20
|
-
|
|
16
|
+
var _utils = _interopRequireDefault(require("../../utils"));
|
|
21
17
|
|
|
22
|
-
|
|
18
|
+
var _excluded = ["container", "value", "formData", "onChange", "wrap"],
|
|
19
|
+
_excluded2 = ["component", "value", "formData", "wrap", "onChange"];
|
|
23
20
|
|
|
24
21
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
22
|
|
|
26
|
-
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; }
|
|
27
|
-
|
|
28
|
-
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; }
|
|
29
|
-
|
|
30
|
-
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; }
|
|
31
|
-
|
|
32
23
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
33
24
|
|
|
34
25
|
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."); }
|
|
@@ -41,18 +32,98 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
41
32
|
|
|
42
33
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
43
34
|
|
|
35
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
36
|
+
|
|
37
|
+
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; }
|
|
38
|
+
|
|
39
|
+
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; }
|
|
40
|
+
|
|
41
|
+
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; }
|
|
42
|
+
|
|
44
43
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
45
44
|
|
|
46
45
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
47
46
|
|
|
48
|
-
var
|
|
49
|
-
|
|
47
|
+
var DEFAULT_CONTAINER_CLASS = 'hods-form-container';
|
|
48
|
+
exports.DEFAULT_CONTAINER_CLASS = DEFAULT_CONTAINER_CLASS;
|
|
49
|
+
|
|
50
|
+
var Container = function Container(_ref) {
|
|
51
|
+
var container = _ref.container,
|
|
50
52
|
value = _ref.value,
|
|
51
|
-
|
|
53
|
+
formData = _ref.formData,
|
|
52
54
|
onChange = _ref.onChange,
|
|
55
|
+
wrap = _ref.wrap,
|
|
53
56
|
attrs = _objectWithoutProperties(_ref, _excluded);
|
|
54
57
|
|
|
55
|
-
var
|
|
58
|
+
var onComponentChange = function onComponentChange(_ref2) {
|
|
59
|
+
var target = _ref2.target;
|
|
60
|
+
|
|
61
|
+
var val = _objectSpread(_objectSpread({}, value), {}, _defineProperty({}, target.name, target.value));
|
|
62
|
+
|
|
63
|
+
if (typeof onChange === 'function') {
|
|
64
|
+
onChange({
|
|
65
|
+
target: {
|
|
66
|
+
name: container.fieldId,
|
|
67
|
+
value: val
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
var shouldShow = function shouldShow(options) {
|
|
74
|
+
if (options.type === _models.ComponentTypes.CONTAINER) {
|
|
75
|
+
return _utils.default.Container.show(options, formData);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return _utils.default.Component.show(options, formData);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
return /*#__PURE__*/React.createElement("div", _extends({}, attrs, {
|
|
82
|
+
className: DEFAULT_CONTAINER_CLASS,
|
|
83
|
+
id: container.id
|
|
84
|
+
}), container.components && container.components.filter(shouldShow).map(function (component, index) {
|
|
85
|
+
var val = value ? value[component.fieldId] : '';
|
|
86
|
+
return /*#__PURE__*/React.createElement(FormComponent, {
|
|
87
|
+
key: index,
|
|
88
|
+
component: component,
|
|
89
|
+
formData: formData,
|
|
90
|
+
value: val || '',
|
|
91
|
+
wrap: wrap,
|
|
92
|
+
onChange: onComponentChange
|
|
93
|
+
});
|
|
94
|
+
}));
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
Container.propTypes = {
|
|
98
|
+
container: _propTypes.default.shape({
|
|
99
|
+
id: _propTypes.default.string.isRequired,
|
|
100
|
+
fieldId: _propTypes.default.string.isRequired,
|
|
101
|
+
components: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
102
|
+
fieldId: _propTypes.default.string,
|
|
103
|
+
type: _propTypes.default.string
|
|
104
|
+
}))
|
|
105
|
+
}).isRequired,
|
|
106
|
+
value: _propTypes.default.any,
|
|
107
|
+
formData: _propTypes.default.any,
|
|
108
|
+
wrap: _propTypes.default.bool,
|
|
109
|
+
onChange: _propTypes.default.func
|
|
110
|
+
};
|
|
111
|
+
Container.defaultProps = {
|
|
112
|
+
wrap: true
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
var FormComponent = function FormComponent(_ref3) {
|
|
116
|
+
var component = _ref3.component,
|
|
117
|
+
value = _ref3.value,
|
|
118
|
+
formData = _ref3.formData,
|
|
119
|
+
wrap = _ref3.wrap,
|
|
120
|
+
onChange = _ref3.onChange,
|
|
121
|
+
attrs = _objectWithoutProperties(_ref3, _excluded2);
|
|
122
|
+
|
|
123
|
+
var _useHooks = (0, _hooks.useHooks)(),
|
|
124
|
+
hooks = _useHooks.hooks;
|
|
125
|
+
|
|
126
|
+
var _useRefData = (0, _hooks.useRefData)(component),
|
|
56
127
|
data = _useRefData.data,
|
|
57
128
|
status = _useRefData.status;
|
|
58
129
|
|
|
@@ -62,21 +133,33 @@ var FormComponent = function FormComponent(_ref) {
|
|
|
62
133
|
setOptions = _useState2[1];
|
|
63
134
|
|
|
64
135
|
(0, _react.useEffect)(function () {
|
|
65
|
-
if (status ===
|
|
136
|
+
if (status === _hooks.STATUS_COMPLETE) {
|
|
66
137
|
setOptions(data);
|
|
67
138
|
}
|
|
68
139
|
}, [component, data, status]);
|
|
140
|
+
|
|
141
|
+
if (component.type === _models.ComponentTypes.CONTAINER) {
|
|
142
|
+
return /*#__PURE__*/React.createElement(Container, {
|
|
143
|
+
container: component,
|
|
144
|
+
wrap: wrap,
|
|
145
|
+
onChange: onChange,
|
|
146
|
+
value: value,
|
|
147
|
+
formData: formData
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
69
151
|
return _utils.default.Component.get(_objectSpread(_objectSpread(_objectSpread({}, attrs), component), {}, {
|
|
70
152
|
label: component.label || '',
|
|
71
153
|
hint: component.hint || '',
|
|
72
154
|
options: options,
|
|
73
155
|
value: value || '',
|
|
74
156
|
onChange: onChange
|
|
75
|
-
}), wrap);
|
|
157
|
+
}), wrap, hooks.onGetComponent);
|
|
76
158
|
};
|
|
77
159
|
|
|
78
160
|
FormComponent.propTypes = {
|
|
79
161
|
component: _propTypes.default.shape({
|
|
162
|
+
fieldId: _propTypes.default.string,
|
|
80
163
|
label: _propTypes.default.string,
|
|
81
164
|
hint: _propTypes.default.string,
|
|
82
165
|
data: _propTypes.default.shape({
|
|
@@ -85,6 +168,7 @@ FormComponent.propTypes = {
|
|
|
85
168
|
})
|
|
86
169
|
}).isRequired,
|
|
87
170
|
value: _propTypes.default.any,
|
|
171
|
+
formData: _propTypes.default.any,
|
|
88
172
|
wrap: _propTypes.default.bool,
|
|
89
173
|
onChange: _propTypes.default.func
|
|
90
174
|
};
|
|
@@ -4,6 +4,8 @@ var _react = require("@testing-library/react");
|
|
|
4
4
|
|
|
5
5
|
var _react2 = _interopRequireDefault(require("react"));
|
|
6
6
|
|
|
7
|
+
var _useHooks = require("../../hooks/useHooks");
|
|
8
|
+
|
|
7
9
|
var _FormComponent = _interopRequireDefault(require("./FormComponent"));
|
|
8
10
|
|
|
9
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -14,6 +16,9 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
|
|
|
14
16
|
|
|
15
17
|
describe('components', function () {
|
|
16
18
|
describe('FormComponent', function () {
|
|
19
|
+
beforeEach(function () {
|
|
20
|
+
(0, _useHooks.resetHooks)();
|
|
21
|
+
});
|
|
17
22
|
it('should render a text component appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
18
23
|
var ID, VALUE, COMPONENT, ON_CHANGE, _render, container, formGroup, label, hint, input;
|
|
19
24
|
|
|
@@ -133,5 +138,67 @@ describe('components', function () {
|
|
|
133
138
|
}
|
|
134
139
|
}, _callee3);
|
|
135
140
|
})));
|
|
141
|
+
it('should render an overridden html component appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
|
|
142
|
+
var ID, COMPONENT, _render4, container, div;
|
|
143
|
+
|
|
144
|
+
return regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
145
|
+
while (1) {
|
|
146
|
+
switch (_context4.prev = _context4.next) {
|
|
147
|
+
case 0:
|
|
148
|
+
(0, _useHooks.addHook)('onGetComponent', function (config, wrap) {
|
|
149
|
+
return /*#__PURE__*/_react2.default.createElement("div", null, "".concat(config.type, " | ").concat(config.tagName, " | ").concat(config.content, " | ").concat(wrap));
|
|
150
|
+
});
|
|
151
|
+
ID = 'component';
|
|
152
|
+
COMPONENT = {
|
|
153
|
+
type: 'html',
|
|
154
|
+
tagName: 'p',
|
|
155
|
+
content: 'HTML content'
|
|
156
|
+
};
|
|
157
|
+
_render4 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
158
|
+
"data-testid": ID,
|
|
159
|
+
component: COMPONENT
|
|
160
|
+
})), container = _render4.container;
|
|
161
|
+
div = container.childNodes[0];
|
|
162
|
+
expect(div.tagName).toEqual('DIV');
|
|
163
|
+
expect(div.textContent).toEqual("".concat(COMPONENT.type, " | ").concat(COMPONENT.tagName, " | ").concat(COMPONENT.content, " | true"));
|
|
164
|
+
|
|
165
|
+
case 7:
|
|
166
|
+
case "end":
|
|
167
|
+
return _context4.stop();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}, _callee4);
|
|
171
|
+
})));
|
|
172
|
+
it('should render the correct html component when the override returns null', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
|
|
173
|
+
var ID, COMPONENT, _render5, container, p;
|
|
174
|
+
|
|
175
|
+
return regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
176
|
+
while (1) {
|
|
177
|
+
switch (_context5.prev = _context5.next) {
|
|
178
|
+
case 0:
|
|
179
|
+
(0, _useHooks.addHook)('onGetComponent', function () {
|
|
180
|
+
return null;
|
|
181
|
+
});
|
|
182
|
+
ID = 'component';
|
|
183
|
+
COMPONENT = {
|
|
184
|
+
type: 'html',
|
|
185
|
+
tagName: 'p',
|
|
186
|
+
content: 'HTML content'
|
|
187
|
+
};
|
|
188
|
+
_render5 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
189
|
+
"data-testid": ID,
|
|
190
|
+
component: COMPONENT
|
|
191
|
+
})), container = _render5.container;
|
|
192
|
+
p = container.childNodes[0];
|
|
193
|
+
expect(p.tagName).toEqual('P');
|
|
194
|
+
expect(p.textContent).toEqual(COMPONENT.content);
|
|
195
|
+
|
|
196
|
+
case 7:
|
|
197
|
+
case "end":
|
|
198
|
+
return _context5.stop();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}, _callee5);
|
|
202
|
+
})));
|
|
136
203
|
});
|
|
137
204
|
});
|
|
@@ -97,7 +97,8 @@ var FormPage = function FormPage(_ref) {
|
|
|
97
97
|
key: index,
|
|
98
98
|
component: component,
|
|
99
99
|
onChange: onPageChange,
|
|
100
|
-
value: page.formData[component.fieldId] || ''
|
|
100
|
+
value: page.formData[component.fieldId] || '',
|
|
101
|
+
formData: page.formData
|
|
101
102
|
});
|
|
102
103
|
}), /*#__PURE__*/_react.default.createElement(_PageActions.default, {
|
|
103
104
|
actions: page.actions,
|