@ukhomeoffice/cop-react-form-renderer 4.34.0 → 4.36.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/CollectionPage/CollectionPage.test.js +2 -2
- package/dist/components/FormComponent/Collection.test.js +2 -2
- package/dist/components/FormComponent/Container.test.js +4 -4
- package/dist/components/FormComponent/FormComponent.test.js +2 -2
- package/dist/components/FormPage/FormPage.test.js +2 -2
- package/dist/models/ComponentTypes.js +4 -0
- package/dist/utils/Component/getComponent.js +45 -0
- package/dist/utils/Component/getComponentTests/getComponent.list.test.js +50 -0
- package/dist/utils/Component/getComponentTests/getComponent.paragraph.test.js +49 -0
- package/package.json +2 -2
|
@@ -153,7 +153,7 @@ describe('components.CollectionPage', function () {
|
|
|
153
153
|
expect(label.textContent).toEqual(lbl);
|
|
154
154
|
expect(label.getAttribute('for')).toEqual(fieldId);
|
|
155
155
|
var hint = formGroup.childNodes[0].childNodes[1];
|
|
156
|
-
expect(hint.tagName).toEqual('
|
|
156
|
+
expect(hint.tagName).toEqual('DIV');
|
|
157
157
|
expect(hint.classList).toContain('govuk-hint');
|
|
158
158
|
expect(hint.textContent).toEqual(hnt);
|
|
159
159
|
var input = formGroup.childNodes[0].childNodes[2];
|
|
@@ -173,7 +173,7 @@ describe('components.CollectionPage', function () {
|
|
|
173
173
|
expect(label.textContent).toEqual(lbl);
|
|
174
174
|
expect(label.getAttribute('for')).toEqual(fieldId);
|
|
175
175
|
var hint = formGroup.childNodes[0].childNodes[1];
|
|
176
|
-
expect(hint.tagName).toEqual('
|
|
176
|
+
expect(hint.tagName).toEqual('DIV');
|
|
177
177
|
expect(hint.classList).toContain('govuk-hint');
|
|
178
178
|
expect(hint.textContent).toEqual(hnt);
|
|
179
179
|
var outerWrapper = formGroup.childNodes[0].childNodes[2];
|
|
@@ -94,7 +94,7 @@ describe('components.FormComponent.Collection', function () {
|
|
|
94
94
|
expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
95
95
|
expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
96
96
|
hint = formGroup.childNodes[0].childNodes[1];
|
|
97
|
-
expect(hint.tagName).toEqual('
|
|
97
|
+
expect(hint.tagName).toEqual('DIV');
|
|
98
98
|
expect(hint.classList).toContain('govuk-hint');
|
|
99
99
|
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
100
100
|
input = formGroup.childNodes[0].childNodes[2];
|
|
@@ -360,7 +360,7 @@ describe('components.FormComponent.Collection', function () {
|
|
|
360
360
|
expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
361
361
|
expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
362
362
|
hint = formGroup.childNodes[0].childNodes[1];
|
|
363
|
-
expect(hint.tagName).toEqual('
|
|
363
|
+
expect(hint.tagName).toEqual('DIV');
|
|
364
364
|
expect(hint.classList).toContain('govuk-hint');
|
|
365
365
|
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
366
366
|
input = formGroup.childNodes[0].childNodes[2];
|
|
@@ -82,7 +82,7 @@ describe('components.FormComponent.Container', function () {
|
|
|
82
82
|
expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
83
83
|
expect(label.getAttribute('for')).toEqual("".concat(ID, ".").concat(TEXT_ID));
|
|
84
84
|
hint = formGroup.childNodes[0].childNodes[1];
|
|
85
|
-
expect(hint.tagName).toEqual('
|
|
85
|
+
expect(hint.tagName).toEqual('DIV');
|
|
86
86
|
expect(hint.classList).toContain('govuk-hint');
|
|
87
87
|
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
88
88
|
input = formGroup.childNodes[0].childNodes[2];
|
|
@@ -139,7 +139,7 @@ describe('components.FormComponent.Container', function () {
|
|
|
139
139
|
expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
140
140
|
expect(label.getAttribute('for')).toEqual("".concat(ID, ".").concat(NESTED_ID, ".").concat(TEXT_ID));
|
|
141
141
|
hint = formGroup.childNodes[0].childNodes[1];
|
|
142
|
-
expect(hint.tagName).toEqual('
|
|
142
|
+
expect(hint.tagName).toEqual('DIV');
|
|
143
143
|
expect(hint.classList).toContain('govuk-hint');
|
|
144
144
|
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
145
145
|
input = formGroup.childNodes[0].childNodes[2];
|
|
@@ -320,7 +320,7 @@ describe('components.FormComponent.Container', function () {
|
|
|
320
320
|
expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
321
321
|
expect(label.getAttribute('for')).toEqual("".concat(ID, ".").concat(TEXT_ID));
|
|
322
322
|
hint = formGroup.childNodes[0].childNodes[1];
|
|
323
|
-
expect(hint.tagName).toEqual('
|
|
323
|
+
expect(hint.tagName).toEqual('DIV');
|
|
324
324
|
expect(hint.classList).toContain('govuk-hint');
|
|
325
325
|
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
326
326
|
input = formGroup.childNodes[0].childNodes[2];
|
|
@@ -402,7 +402,7 @@ describe('components.FormComponent.Container', function () {
|
|
|
402
402
|
expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
403
403
|
expect(label.getAttribute('for')).toEqual("".concat(ID, ".").concat(TEXT_ID));
|
|
404
404
|
hint = formGroup.childNodes[0].childNodes[1];
|
|
405
|
-
expect(hint.tagName).toEqual('
|
|
405
|
+
expect(hint.tagName).toEqual('DIV');
|
|
406
406
|
expect(hint.classList).toContain('govuk-hint');
|
|
407
407
|
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
408
408
|
input = formGroup.childNodes[0].childNodes[2];
|
|
@@ -49,7 +49,7 @@ describe('components', function () {
|
|
|
49
49
|
expect(label.textContent).toEqual("".concat(COMPONENT.label, " (optional)"));
|
|
50
50
|
expect(label.getAttribute('for')).toEqual(ID);
|
|
51
51
|
hint = formGroup.childNodes[0].childNodes[1];
|
|
52
|
-
expect(hint.tagName).toEqual('
|
|
52
|
+
expect(hint.tagName).toEqual('DIV');
|
|
53
53
|
expect(hint.classList).toContain('govuk-hint');
|
|
54
54
|
expect(hint.textContent).toEqual(COMPONENT.hint);
|
|
55
55
|
input = formGroup.childNodes[0].childNodes[2];
|
|
@@ -244,7 +244,7 @@ describe('components', function () {
|
|
|
244
244
|
expect(label.textContent).toEqual('Interpolated Text component (optional)');
|
|
245
245
|
expect(label.getAttribute('for')).toEqual(ID);
|
|
246
246
|
hint = formGroup.childNodes[0].childNodes[1];
|
|
247
|
-
expect(hint.tagName).toEqual('
|
|
247
|
+
expect(hint.tagName).toEqual('DIV');
|
|
248
248
|
expect(hint.classList).toContain('govuk-hint');
|
|
249
249
|
expect(hint.textContent).toEqual(COMPONENT.hint);
|
|
250
250
|
input = formGroup.childNodes[0].childNodes[2];
|
|
@@ -141,7 +141,7 @@ describe('components.FormPage', function () {
|
|
|
141
141
|
expect(label.textContent).toEqual(lbl);
|
|
142
142
|
expect(label.getAttribute('for')).toEqual(fieldId);
|
|
143
143
|
var hint = formGroup.childNodes[0].childNodes[1];
|
|
144
|
-
expect(hint.tagName).toEqual('
|
|
144
|
+
expect(hint.tagName).toEqual('DIV');
|
|
145
145
|
expect(hint.classList).toContain('govuk-hint');
|
|
146
146
|
expect(hint.textContent).toEqual(hnt);
|
|
147
147
|
var input = formGroup.childNodes[0].childNodes[2];
|
|
@@ -161,7 +161,7 @@ describe('components.FormPage', function () {
|
|
|
161
161
|
expect(label.textContent).toEqual(lbl);
|
|
162
162
|
expect(label.getAttribute('for')).toEqual(fieldId);
|
|
163
163
|
var hint = formGroup.childNodes[0].childNodes[1];
|
|
164
|
-
expect(hint.tagName).toEqual('
|
|
164
|
+
expect(hint.tagName).toEqual('DIV');
|
|
165
165
|
expect(hint.classList).toContain('govuk-hint');
|
|
166
166
|
expect(hint.textContent).toEqual(hnt);
|
|
167
167
|
var outerWrapper = formGroup.childNodes[0].childNodes[2];
|
|
@@ -17,6 +17,8 @@ var TYPE_FILE = 'file';
|
|
|
17
17
|
var TYPE_HEADING = 'heading';
|
|
18
18
|
var TYPE_HTML = 'html';
|
|
19
19
|
var TYPE_INSET_TEXT = 'inset-text';
|
|
20
|
+
var TYPE_LIST = 'list';
|
|
21
|
+
var TYPE_PARAGRAPH = 'paragraph';
|
|
20
22
|
var TYPE_PHONE_NUMBER = 'phone-number';
|
|
21
23
|
var TYPE_RADIOS = 'radios';
|
|
22
24
|
var TYPE_SELECT = 'select';
|
|
@@ -38,6 +40,8 @@ var ComponentTypes = {
|
|
|
38
40
|
HEADING: TYPE_HEADING,
|
|
39
41
|
HTML: TYPE_HTML,
|
|
40
42
|
INSET_TEXT: TYPE_INSET_TEXT,
|
|
43
|
+
LIST: TYPE_LIST,
|
|
44
|
+
PARAGRAPH: TYPE_PARAGRAPH,
|
|
41
45
|
PHONE_NUMBER: TYPE_PHONE_NUMBER,
|
|
42
46
|
RADIOS: TYPE_RADIOS,
|
|
43
47
|
SELECT: TYPE_SELECT,
|
|
@@ -23,14 +23,23 @@ var _wrapInFormGroup = _interopRequireDefault(require("./wrapInFormGroup"));
|
|
|
23
23
|
|
|
24
24
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
25
|
|
|
26
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); 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 = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : 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
|
+
|
|
26
32
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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); }
|
|
27
33
|
|
|
34
|
+
var LIST_CLASS = 'govuk-list';
|
|
35
|
+
var BODY_CLASS = 'govuk-body';
|
|
28
36
|
/**
|
|
29
37
|
* Separate function for each component type for the sake of
|
|
30
38
|
* code clarity - having the additional bits and pieces in the
|
|
31
39
|
* switch statement increases the cyclomatic complexity and
|
|
32
40
|
* makes it much harder to follow what's going on.
|
|
33
41
|
*/
|
|
42
|
+
|
|
34
43
|
var getAlert = function getAlert(config) {
|
|
35
44
|
var attrs = (0, _cleanAttributes.default)(config);
|
|
36
45
|
|
|
@@ -118,6 +127,36 @@ var getInsetText = function getInsetText(config) {
|
|
|
118
127
|
return /*#__PURE__*/_react.default.createElement(_copReactComponents.InsetText, attrs, config.content);
|
|
119
128
|
};
|
|
120
129
|
|
|
130
|
+
var getList = function getList(config) {
|
|
131
|
+
var _attrs$items;
|
|
132
|
+
|
|
133
|
+
var attrs = (0, _cleanAttributes.default)(config);
|
|
134
|
+
var tagName = attrs.ordered ? 'ol' : 'ul';
|
|
135
|
+
var bullet = attrs.ordered ? 'number' : 'bullet';
|
|
136
|
+
|
|
137
|
+
var classes = _copReactComponents.Utils.classBuilder(LIST_CLASS, bullet);
|
|
138
|
+
|
|
139
|
+
var content = (_attrs$items = attrs.items) === null || _attrs$items === void 0 ? void 0 : _attrs$items.map(function (item) {
|
|
140
|
+
return "<li>".concat(item, "</li>");
|
|
141
|
+
}).join('');
|
|
142
|
+
return getHTML(_objectSpread(_objectSpread({}, attrs), {}, {
|
|
143
|
+
className: classes(),
|
|
144
|
+
tagName: tagName,
|
|
145
|
+
content: content,
|
|
146
|
+
type: _models.ComponentTypes.HTML
|
|
147
|
+
}));
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
var getParagraph = function getParagraph(config) {
|
|
151
|
+
var attrs = (0, _cleanAttributes.default)(config);
|
|
152
|
+
return getHTML(_objectSpread(_objectSpread({
|
|
153
|
+
className: BODY_CLASS
|
|
154
|
+
}, attrs), {}, {
|
|
155
|
+
tagName: 'p',
|
|
156
|
+
type: _models.ComponentTypes.HTML
|
|
157
|
+
}));
|
|
158
|
+
};
|
|
159
|
+
|
|
121
160
|
var getRadios = function getRadios(config) {
|
|
122
161
|
var options = [];
|
|
123
162
|
|
|
@@ -223,6 +262,12 @@ var getComponentByType = function getComponentByType(config) {
|
|
|
223
262
|
case _models.ComponentTypes.ALERT:
|
|
224
263
|
return getAlert(config);
|
|
225
264
|
|
|
265
|
+
case _models.ComponentTypes.PARAGRAPH:
|
|
266
|
+
return getParagraph(config);
|
|
267
|
+
|
|
268
|
+
case _models.ComponentTypes.LIST:
|
|
269
|
+
return getList(config);
|
|
270
|
+
|
|
226
271
|
default:
|
|
227
272
|
{
|
|
228
273
|
return null;
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
// Global imports
|
|
12
|
+
// Local imports
|
|
13
|
+
describe('utils.Component.get', function () {
|
|
14
|
+
it('should return a ul tag and correct className for an unordered list component', function () {
|
|
15
|
+
var ID = 'test-id';
|
|
16
|
+
var ITEMS = ['paragraph content1', 'paragraph content2'];
|
|
17
|
+
var COMPONENT = {
|
|
18
|
+
type: _models.ComponentTypes.LIST,
|
|
19
|
+
ordered: false,
|
|
20
|
+
items: ITEMS,
|
|
21
|
+
'data-testid': ID
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
var _render = (0, _react.render)((0, _getComponent.default)(COMPONENT)),
|
|
25
|
+
container = _render.container;
|
|
26
|
+
|
|
27
|
+
var ul = (0, _react.getByTestId)(container, ID);
|
|
28
|
+
expect(ul.innerHTML).toContain('<li>paragraph content1</li><li>paragraph content2</li>');
|
|
29
|
+
expect(ul.tagName).toEqual('UL');
|
|
30
|
+
expect(ul.className).toEqual('govuk-list govuk-list--bullet');
|
|
31
|
+
});
|
|
32
|
+
it('should return a ol tag and correct className for an ordered list component', function () {
|
|
33
|
+
var ID = 'test-id';
|
|
34
|
+
var ITEMS = ['paragraph content1', 'paragraph content2'];
|
|
35
|
+
var COMPONENT = {
|
|
36
|
+
type: _models.ComponentTypes.LIST,
|
|
37
|
+
ordered: true,
|
|
38
|
+
items: ITEMS,
|
|
39
|
+
'data-testid': ID
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
var _render2 = (0, _react.render)((0, _getComponent.default)(COMPONENT)),
|
|
43
|
+
container = _render2.container;
|
|
44
|
+
|
|
45
|
+
var ol = (0, _react.getByTestId)(container, ID);
|
|
46
|
+
expect(ol.innerHTML).toContain('<li>paragraph content1</li><li>paragraph content2</li>');
|
|
47
|
+
expect(ol.tagName).toEqual('OL');
|
|
48
|
+
expect(ol.className).toEqual('govuk-list govuk-list--number');
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
// Global imports
|
|
12
|
+
// Local imports
|
|
13
|
+
describe('utils.Component.get', function () {
|
|
14
|
+
it('should return a p tag and correct className for a paragraph component', function () {
|
|
15
|
+
var ID = 'test-id';
|
|
16
|
+
var CONTENT = 'paragraph content';
|
|
17
|
+
var COMPONENT = {
|
|
18
|
+
type: _models.ComponentTypes.PARAGRAPH,
|
|
19
|
+
content: CONTENT,
|
|
20
|
+
'data-testid': ID
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
var _render = (0, _react.render)((0, _getComponent.default)(COMPONENT)),
|
|
24
|
+
container = _render.container;
|
|
25
|
+
|
|
26
|
+
var p = (0, _react.getByTestId)(container, ID);
|
|
27
|
+
expect(p.innerHTML).toContain(CONTENT);
|
|
28
|
+
expect(p.tagName).toEqual('P');
|
|
29
|
+
expect(p.className).toEqual('govuk-body');
|
|
30
|
+
});
|
|
31
|
+
it('should override default className for a paragraph component', function () {
|
|
32
|
+
var ID = 'test-id';
|
|
33
|
+
var CONTENT = 'paragraph content';
|
|
34
|
+
var COMPONENT = {
|
|
35
|
+
type: _models.ComponentTypes.PARAGRAPH,
|
|
36
|
+
content: CONTENT,
|
|
37
|
+
'data-testid': ID,
|
|
38
|
+
className: 'govuk-body highlight'
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
var _render2 = (0, _react.render)((0, _getComponent.default)(COMPONENT)),
|
|
42
|
+
container = _render2.container;
|
|
43
|
+
|
|
44
|
+
var p = (0, _react.getByTestId)(container, ID);
|
|
45
|
+
expect(p.innerHTML).toContain(CONTENT);
|
|
46
|
+
expect(p.tagName).toEqual('P');
|
|
47
|
+
expect(p.className).toEqual('govuk-body highlight');
|
|
48
|
+
});
|
|
49
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ukhomeoffice/cop-react-form-renderer",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.36.0",
|
|
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": "2.
|
|
19
|
+
"@ukhomeoffice/cop-react-components": "2.7.1",
|
|
20
20
|
"axios": "^0.23.0",
|
|
21
21
|
"dayjs": "^1.11.0",
|
|
22
22
|
"govuk-frontend": "^4.3.1",
|