@ukhomeoffice/cop-react-form-renderer 3.4.1-alpha → 3.5.2-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/CheckYourAnswers.test.js +4 -4
- package/dist/components/FormPage/FormPage.js +1 -1
- package/dist/components/FormRenderer/FormRenderer.js +5 -1
- package/dist/models/ComponentTypes.js +2 -0
- package/dist/utils/Component/getComponent.js +16 -0
- package/dist/utils/Component/getComponentTests/getComponent.select.test.js +88 -0
- package/dist/utils/Component/isEditable.js +1 -1
- package/package.json +2 -2
|
@@ -496,7 +496,7 @@ describe('components', function () {
|
|
|
496
496
|
}, _callee16);
|
|
497
497
|
})));
|
|
498
498
|
it('should show page components corrently with interpolated title and cya_label, if label is missing', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee18() {
|
|
499
|
-
var _PAGES, _COMPONENTS, T_PAGES, cya, _cya$childNodes5, cyaTitle, cyaChildNode, names, _names$childNodes3, firstName, surname, _firstName$childNodes, label
|
|
499
|
+
var _PAGES, _COMPONENTS, T_PAGES, cya, _cya$childNodes5, cyaTitle, cyaChildNode, names, _names$childNodes3, firstName, surname, _firstName$childNodes, label;
|
|
500
500
|
|
|
501
501
|
return regeneratorRuntime.wrap(function _callee18$(_context18) {
|
|
502
502
|
while (1) {
|
|
@@ -543,7 +543,7 @@ describe('components', function () {
|
|
|
543
543
|
expect(names.tagName).toEqual('DL');
|
|
544
544
|
expect(names.classList).toContain("govuk-!-margin-bottom-".concat(_CheckYourAnswers.DEFAULT_MARGIN_BOTTOM));
|
|
545
545
|
_names$childNodes3 = _slicedToArray(names.childNodes, 2), firstName = _names$childNodes3[0], surname = _names$childNodes3[1];
|
|
546
|
-
_firstName$childNodes = _slicedToArray(firstName.childNodes,
|
|
546
|
+
_firstName$childNodes = _slicedToArray(firstName.childNodes, 1), label = _firstName$childNodes[0];
|
|
547
547
|
expect(label.textContent).toEqual('Text Smith');
|
|
548
548
|
checkRow(surname, 'Last name', 'Smith', false);
|
|
549
549
|
|
|
@@ -555,7 +555,7 @@ describe('components', function () {
|
|
|
555
555
|
}, _callee18);
|
|
556
556
|
})));
|
|
557
557
|
it('should show page components corrently with no label, if label and cya_label are missing', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee20() {
|
|
558
|
-
var _PAGES, _COMPONENTS, T_PAGES, cya, _cya$childNodes6, cyaChildNode, names, _names$childNodes4, firstName, surname, _firstName$childNodes2, label
|
|
558
|
+
var _PAGES, _COMPONENTS, T_PAGES, cya, _cya$childNodes6, cyaChildNode, names, _names$childNodes4, firstName, surname, _firstName$childNodes2, label;
|
|
559
559
|
|
|
560
560
|
return regeneratorRuntime.wrap(function _callee20$(_context20) {
|
|
561
561
|
while (1) {
|
|
@@ -596,7 +596,7 @@ describe('components', function () {
|
|
|
596
596
|
expect(names.tagName).toEqual('DL');
|
|
597
597
|
expect(names.classList).toContain("govuk-!-margin-bottom-".concat(_CheckYourAnswers.DEFAULT_MARGIN_BOTTOM));
|
|
598
598
|
_names$childNodes4 = _slicedToArray(names.childNodes, 2), firstName = _names$childNodes4[0], surname = _names$childNodes4[1];
|
|
599
|
-
_firstName$childNodes2 = _slicedToArray(firstName.childNodes,
|
|
599
|
+
_firstName$childNodes2 = _slicedToArray(firstName.childNodes, 1), label = _firstName$childNodes2[0];
|
|
600
600
|
expect(label.textContent).toEqual("");
|
|
601
601
|
checkRow(surname, 'Last name', 'Smith', false);
|
|
602
602
|
|
|
@@ -100,7 +100,7 @@ var FormPage = function FormPage(_ref) {
|
|
|
100
100
|
key: index,
|
|
101
101
|
component: component,
|
|
102
102
|
onChange: onPageChange,
|
|
103
|
-
value: page.formData[component.fieldId],
|
|
103
|
+
value: page.formData[component.fieldId] || patch[component.fieldId],
|
|
104
104
|
formData: page.formData
|
|
105
105
|
});
|
|
106
106
|
}), /*#__PURE__*/_react.default.createElement(_PageActions.default, {
|
|
@@ -250,8 +250,12 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
250
250
|
|
|
251
251
|
|
|
252
252
|
var onPageAction = function onPageAction(action, patch) {
|
|
253
|
-
//
|
|
253
|
+
// Re-apply the patch to the page's formData.
|
|
254
|
+
// This should normally have no effect but will prevent issues
|
|
255
|
+
// with validation if formData happens to have been wiped.
|
|
256
|
+
formState.page.formData = _objectSpread(_objectSpread({}, formState.page.formData), patch); // Check to see whether the action is able to proceed, which in
|
|
254
257
|
// in the case of a submission will validate the fields in the page.
|
|
258
|
+
|
|
255
259
|
if (_helpers.default.canActionProceed(action, formState.page, validate.page)) {
|
|
256
260
|
patch = _helpers.default.cleanHiddenNestedData(patch, formState.page);
|
|
257
261
|
|
|
@@ -17,6 +17,7 @@ var TYPE_HTML = 'html';
|
|
|
17
17
|
var TYPE_INSET_TEXT = 'inset-text';
|
|
18
18
|
var TYPE_PHONE_NUMBER = 'phone-number';
|
|
19
19
|
var TYPE_RADIOS = 'radios';
|
|
20
|
+
var TYPE_SELECT = 'select';
|
|
20
21
|
var TYPE_TEXT = 'text';
|
|
21
22
|
var TYPE_TEXT_AREA = 'textarea';
|
|
22
23
|
var TYPE_TIME = 'time';
|
|
@@ -35,6 +36,7 @@ var ComponentTypes = {
|
|
|
35
36
|
INSET_TEXT: TYPE_INSET_TEXT,
|
|
36
37
|
PHONE_NUMBER: TYPE_PHONE_NUMBER,
|
|
37
38
|
RADIOS: TYPE_RADIOS,
|
|
39
|
+
SELECT: TYPE_SELECT,
|
|
38
40
|
TEXT: TYPE_TEXT,
|
|
39
41
|
TEXT_AREA: TYPE_TEXT_AREA,
|
|
40
42
|
TIME: TYPE_TIME,
|
|
@@ -120,6 +120,19 @@ var getTime = function getTime(config) {
|
|
|
120
120
|
return /*#__PURE__*/_react.default.createElement(_copReactComponents.TimeInput, attrs);
|
|
121
121
|
};
|
|
122
122
|
|
|
123
|
+
var getSelect = function getSelect(config) {
|
|
124
|
+
var options = [];
|
|
125
|
+
|
|
126
|
+
_Data.default.getOptions(config, function (val) {
|
|
127
|
+
options = val;
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
var attrs = (0, _cleanAttributes.default)(config);
|
|
131
|
+
return /*#__PURE__*/_react.default.createElement(_copReactComponents.Select, _extends({}, attrs, {
|
|
132
|
+
options: options
|
|
133
|
+
}));
|
|
134
|
+
};
|
|
135
|
+
|
|
123
136
|
var getWarningText = function getWarningText(config) {
|
|
124
137
|
var attrs = (0, _cleanAttributes.default)(config);
|
|
125
138
|
return /*#__PURE__*/_react.default.createElement(_copReactComponents.WarningText, attrs, config.content);
|
|
@@ -165,6 +178,9 @@ var getComponentByType = function getComponentByType(config) {
|
|
|
165
178
|
case _models.ComponentTypes.WARNING:
|
|
166
179
|
return getWarningText(config);
|
|
167
180
|
|
|
181
|
+
case _models.ComponentTypes.SELECT:
|
|
182
|
+
return getSelect(config);
|
|
183
|
+
|
|
168
184
|
case _models.ComponentTypes.DETAILS:
|
|
169
185
|
return getDetails(config);
|
|
170
186
|
|
|
@@ -0,0 +1,88 @@
|
|
|
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 select component', function () {
|
|
25
|
+
var ID = 'test-id';
|
|
26
|
+
var FIELD_ID = 'field-id';
|
|
27
|
+
var LABEL = 'label';
|
|
28
|
+
var NEW_VALUE = 'option2';
|
|
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.SELECT,
|
|
37
|
+
id: ID,
|
|
38
|
+
fieldId: FIELD_ID,
|
|
39
|
+
label: LABEL,
|
|
40
|
+
onChange: ON_CHANGE,
|
|
41
|
+
options: [{
|
|
42
|
+
label: 'Option 1',
|
|
43
|
+
value: 'option1'
|
|
44
|
+
}, {
|
|
45
|
+
label: 'Option 2',
|
|
46
|
+
value: NEW_VALUE
|
|
47
|
+
}],
|
|
48
|
+
'data-testid': ID
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
var _render = (0, _react.render)((0, _getComponent.default)(COMPONENT)),
|
|
52
|
+
container = _render.container;
|
|
53
|
+
|
|
54
|
+
var _getAllByTestId = (0, _react.getAllByTestId)(container, ID),
|
|
55
|
+
_getAllByTestId2 = _slicedToArray(_getAllByTestId, 2),
|
|
56
|
+
formGroup = _getAllByTestId2[0],
|
|
57
|
+
select = _getAllByTestId2[1];
|
|
58
|
+
|
|
59
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
60
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
61
|
+
var label = undefined;
|
|
62
|
+
formGroup.childNodes.forEach(function (node) {
|
|
63
|
+
// Check if it's an element.
|
|
64
|
+
if (node instanceof Element && node.tagName === 'LABEL') {
|
|
65
|
+
label = node;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
expect(label).toBeDefined();
|
|
69
|
+
expect(label.innerHTML).toContain(LABEL);
|
|
70
|
+
expect(label.getAttribute('for')).toEqual(ID);
|
|
71
|
+
expect(select.tagName).toEqual('SELECT');
|
|
72
|
+
expect(select.classList).toContain('govuk-select');
|
|
73
|
+
expect(select.id).toEqual(ID);
|
|
74
|
+
|
|
75
|
+
_react.fireEvent.change(select, {
|
|
76
|
+
target: {
|
|
77
|
+
name: FIELD_ID,
|
|
78
|
+
value: NEW_VALUE
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
expect(ON_CHANGE_CALLS.length).toEqual(1);
|
|
83
|
+
expect(ON_CHANGE_CALLS[0]).toMatchObject({
|
|
84
|
+
name: FIELD_ID,
|
|
85
|
+
value: NEW_VALUE
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
|
@@ -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.CHECKBOXES, _models.ComponentTypes.DATE, _models.ComponentTypes.EMAIL, _models.ComponentTypes.FILE, _models.ComponentTypes.PHONE_NUMBER, _models.ComponentTypes.RADIOS, _models.ComponentTypes.TEXT, _models.ComponentTypes.TEXT_AREA, _models.ComponentTypes.TIME];
|
|
11
|
+
var EDITABLE_TYPES = [_models.ComponentTypes.AUTOCOMPLETE, _models.ComponentTypes.CHECKBOXES, _models.ComponentTypes.DATE, _models.ComponentTypes.EMAIL, _models.ComponentTypes.FILE, _models.ComponentTypes.PHONE_NUMBER, _models.ComponentTypes.RADIOS, _models.ComponentTypes.SELECT, _models.ComponentTypes.TEXT, _models.ComponentTypes.TEXT_AREA, _models.ComponentTypes.TIME];
|
|
12
12
|
exports.EDITABLE_TYPES = EDITABLE_TYPES;
|
|
13
13
|
|
|
14
14
|
var isEditable = function isEditable(options) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ukhomeoffice/cop-react-form-renderer",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.2-alpha",
|
|
4
4
|
"private": false,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"clean": "rimraf dist",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"post-compile": "rimraf dist/*.test.* dist/**/*.test.* dist/**/*.stories.* dist/docs dist/assets"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@ukhomeoffice/cop-react-components": "1.
|
|
19
|
+
"@ukhomeoffice/cop-react-components": "1.9.0",
|
|
20
20
|
"axios": "^0.21.1",
|
|
21
21
|
"dayjs": "^1.11.0",
|
|
22
22
|
"govuk-frontend": "^3.13.0",
|