@ukhomeoffice/cop-react-form-renderer 5.11.0-bravo → 5.11.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 +1 -1
- package/dist/components/FormComponent/Collection.test.js +11 -12
- package/dist/components/FormComponent/Container.test.js +3 -3
- package/dist/components/FormComponent/FormComponent.test.js +3 -3
- package/dist/components/FormPage/FormPage.test.js +1 -1
- package/dist/utils/Component/getComponentTests/getComponent.calculation.test.js +2 -2
- package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +6 -6
- package/dist/utils/Component/getDefaultValue.js +9 -3
- package/dist/utils/Component/getDefaultValue.test.js +12 -0
- package/dist/utils/Data/setupRefDataUrlForComponent.js +2 -1
- package/dist/utils/Data/setupRefDataUrlForComponent.test.js +18 -0
- package/package.json +2 -2
|
@@ -150,7 +150,7 @@ describe('components.CollectionPage', function () {
|
|
|
150
150
|
expect(input.tagName).toEqual('INPUT');
|
|
151
151
|
expect(input.classList).toContain('govuk-input');
|
|
152
152
|
expect(input.id).toEqual(fieldId);
|
|
153
|
-
expect(input.
|
|
153
|
+
expect(input.value).toEqual(val);
|
|
154
154
|
return input;
|
|
155
155
|
};
|
|
156
156
|
var checkAutoCompleteField = function checkAutoCompleteField(formGroup, fieldId, lbl, hnt, val) {
|
|
@@ -84,7 +84,7 @@ describe('components.FormComponent.Collection', function () {
|
|
|
84
84
|
expect(input.tagName).toEqual('INPUT');
|
|
85
85
|
expect(input.classList).toContain('govuk-input');
|
|
86
86
|
expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
87
|
-
expect(input.
|
|
87
|
+
expect(input.value).toEqual(TEXT_VALUE);
|
|
88
88
|
case 30:
|
|
89
89
|
case "end":
|
|
90
90
|
return _context.stop();
|
|
@@ -390,12 +390,11 @@ describe('components.FormComponent.Collection', function () {
|
|
|
390
390
|
expect(hint.classList).toContain('govuk-hint');
|
|
391
391
|
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
392
392
|
input = formGroup.childNodes[2];
|
|
393
|
-
_react.screen.debug();
|
|
394
393
|
expect(input.tagName).toEqual('DIV'); // Now readonly, so a DIV.
|
|
395
394
|
expect(input.classList).toContain('hods-readonly'); // Now readonly, so hods-readonly
|
|
396
|
-
expect(input.
|
|
395
|
+
expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
397
396
|
expect(input.textContent).toEqual(TEXT_VALUE);
|
|
398
|
-
case
|
|
397
|
+
case 30:
|
|
399
398
|
case "end":
|
|
400
399
|
return _context9.stop();
|
|
401
400
|
}
|
|
@@ -519,7 +518,7 @@ describe('components.FormComponent.Collection', function () {
|
|
|
519
518
|
expect(input.tagName).toEqual('INPUT');
|
|
520
519
|
expect(input.classList).toContain('govuk-input');
|
|
521
520
|
expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
522
|
-
expect(input.
|
|
521
|
+
expect(input.value).toEqual(TEXT_VALUE);
|
|
523
522
|
|
|
524
523
|
// First item component 2
|
|
525
524
|
formGroup = itemContainer.childNodes[1];
|
|
@@ -538,7 +537,7 @@ describe('components.FormComponent.Collection', function () {
|
|
|
538
537
|
expect(input.tagName).toEqual('INPUT');
|
|
539
538
|
expect(input.classList).toContain('govuk-input');
|
|
540
539
|
expect(input.id).toEqual("".concat(ID, "[0].textTwo"));
|
|
541
|
-
expect(input.
|
|
540
|
+
expect(input.value).toEqual('charlie');
|
|
542
541
|
|
|
543
542
|
// Check the second item and confirm there is no hint
|
|
544
543
|
itemTwo = c.childNodes[1];
|
|
@@ -565,7 +564,7 @@ describe('components.FormComponent.Collection', function () {
|
|
|
565
564
|
expect(inputTwo.tagName).toEqual('INPUT');
|
|
566
565
|
expect(inputTwo.classList).toContain('govuk-input');
|
|
567
566
|
expect(inputTwo.id).toEqual("".concat(ID, "[1].").concat(TEXT_ID));
|
|
568
|
-
expect(inputTwo.
|
|
567
|
+
expect(inputTwo.value).toEqual('beta');
|
|
569
568
|
|
|
570
569
|
// Second item second component
|
|
571
570
|
formGroupTwo = itemContainerTwo.childNodes[1];
|
|
@@ -582,7 +581,7 @@ describe('components.FormComponent.Collection', function () {
|
|
|
582
581
|
expect(inputTwo.tagName).toEqual('INPUT');
|
|
583
582
|
expect(inputTwo.classList).toContain('govuk-input');
|
|
584
583
|
expect(inputTwo.id).toEqual("".concat(ID, "[1].textTwo"));
|
|
585
|
-
expect(inputTwo.
|
|
584
|
+
expect(inputTwo.value).toEqual('delta');
|
|
586
585
|
case 87:
|
|
587
586
|
case "end":
|
|
588
587
|
return _context11.stop();
|
|
@@ -659,7 +658,7 @@ describe('components.FormComponent.Collection', function () {
|
|
|
659
658
|
expect(input.tagName).toEqual('INPUT');
|
|
660
659
|
expect(input.classList).toContain('govuk-input');
|
|
661
660
|
expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
662
|
-
expect(input.
|
|
661
|
+
expect(input.value).toEqual(TEXT_VALUE);
|
|
663
662
|
|
|
664
663
|
// First item component 2
|
|
665
664
|
formGroup = itemContainer.childNodes[1];
|
|
@@ -678,7 +677,7 @@ describe('components.FormComponent.Collection', function () {
|
|
|
678
677
|
expect(input.tagName).toEqual('INPUT');
|
|
679
678
|
expect(input.classList).toContain('govuk-input');
|
|
680
679
|
expect(input.id).toEqual("".concat(ID, "[0].textTwo"));
|
|
681
|
-
expect(input.
|
|
680
|
+
expect(input.value).toEqual('charlie');
|
|
682
681
|
|
|
683
682
|
// Check the second item and confirm there is no hint
|
|
684
683
|
itemTwo = c.childNodes[1];
|
|
@@ -705,7 +704,7 @@ describe('components.FormComponent.Collection', function () {
|
|
|
705
704
|
expect(inputTwo.tagName).toEqual('INPUT');
|
|
706
705
|
expect(inputTwo.classList).toContain('govuk-input');
|
|
707
706
|
expect(inputTwo.id).toEqual("".concat(ID, "[1].").concat(TEXT_ID));
|
|
708
|
-
expect(inputTwo.
|
|
707
|
+
expect(inputTwo.value).toEqual('beta');
|
|
709
708
|
|
|
710
709
|
// Second item second component
|
|
711
710
|
formGroupTwo = itemContainerTwo.childNodes[1];
|
|
@@ -722,7 +721,7 @@ describe('components.FormComponent.Collection', function () {
|
|
|
722
721
|
expect(inputTwo.tagName).toEqual('INPUT');
|
|
723
722
|
expect(inputTwo.classList).toContain('govuk-input');
|
|
724
723
|
expect(inputTwo.id).toEqual("".concat(ID, "[1].textTwo"));
|
|
725
|
-
expect(inputTwo.
|
|
724
|
+
expect(inputTwo.value).toEqual('delta');
|
|
726
725
|
case 89:
|
|
727
726
|
case "end":
|
|
728
727
|
return _context12.stop();
|
|
@@ -76,7 +76,7 @@ describe('components.FormComponent.Container', function () {
|
|
|
76
76
|
expect(input.tagName).toEqual('INPUT');
|
|
77
77
|
expect(input.classList).toContain('govuk-input');
|
|
78
78
|
expect(input.id).toEqual("".concat(ID, ".").concat(TEXT_ID));
|
|
79
|
-
expect(input.
|
|
79
|
+
expect(input.value).toEqual(TEXT_VALUE);
|
|
80
80
|
case 22:
|
|
81
81
|
case "end":
|
|
82
82
|
return _context.stop();
|
|
@@ -130,7 +130,7 @@ describe('components.FormComponent.Container', function () {
|
|
|
130
130
|
expect(input.tagName).toEqual('INPUT');
|
|
131
131
|
expect(input.classList).toContain('govuk-input');
|
|
132
132
|
expect(input.id).toEqual("".concat(ID, ".").concat(NESTED_ID, ".").concat(TEXT_ID));
|
|
133
|
-
expect(input.
|
|
133
|
+
expect(input.value).toEqual(NESTED_TEXT_VALUE);
|
|
134
134
|
case 25:
|
|
135
135
|
case "end":
|
|
136
136
|
return _context2.stop();
|
|
@@ -359,7 +359,7 @@ describe('components.FormComponent.Container', function () {
|
|
|
359
359
|
input = formGroup.childNodes[2];
|
|
360
360
|
expect(input.tagName).toEqual('DIV'); // Now readonly, so a DIV.
|
|
361
361
|
expect(input.classList).toContain('hods-readonly'); // Now readonly, so hods-readonly
|
|
362
|
-
expect(input.
|
|
362
|
+
expect(input.id).toEqual("".concat(ID, ".").concat(TEXT_ID));
|
|
363
363
|
expect(input.textContent).toEqual(TEXT_VALUE);
|
|
364
364
|
case 22:
|
|
365
365
|
case "end":
|
|
@@ -47,7 +47,7 @@ describe('components', function () {
|
|
|
47
47
|
expect(input.tagName).toEqual('INPUT');
|
|
48
48
|
expect(input.classList).toContain('govuk-input');
|
|
49
49
|
expect(input.id).toEqual(ID);
|
|
50
|
-
expect(input.
|
|
50
|
+
expect(input.value).toEqual(VALUE);
|
|
51
51
|
case 22:
|
|
52
52
|
case "end":
|
|
53
53
|
return _context.stop();
|
|
@@ -80,7 +80,7 @@ describe('components', function () {
|
|
|
80
80
|
expect(input.tagName).toEqual('INPUT');
|
|
81
81
|
expect(input.classList).toContain('govuk-input');
|
|
82
82
|
expect(input.id).toEqual(ID);
|
|
83
|
-
expect(input.
|
|
83
|
+
expect(input.value).toEqual(VALUE);
|
|
84
84
|
case 10:
|
|
85
85
|
case "end":
|
|
86
86
|
return _context2.stop();
|
|
@@ -215,7 +215,7 @@ describe('components', function () {
|
|
|
215
215
|
expect(input.tagName).toEqual('INPUT');
|
|
216
216
|
expect(input.classList).toContain('govuk-input');
|
|
217
217
|
expect(input.id).toEqual(ID);
|
|
218
|
-
expect(input.
|
|
218
|
+
expect(input.value).toEqual(VALUE);
|
|
219
219
|
case 23:
|
|
220
220
|
case "end":
|
|
221
221
|
return _context6.stop();
|
|
@@ -138,7 +138,7 @@ describe('components.FormPage', function () {
|
|
|
138
138
|
expect(input.tagName).toEqual('INPUT');
|
|
139
139
|
expect(input.classList).toContain('govuk-input');
|
|
140
140
|
expect(input.id).toEqual(fieldId);
|
|
141
|
-
expect(input.
|
|
141
|
+
expect(input.value).toEqual(val);
|
|
142
142
|
return input;
|
|
143
143
|
};
|
|
144
144
|
var checkAutoCompleteField = function checkAutoCompleteField(formGroup, fieldId, lbl, hnt, val) {
|
|
@@ -148,7 +148,7 @@ describe('utils.Component.get', function () {
|
|
|
148
148
|
expect(formGroup.classList).toContain('govuk-form-group');
|
|
149
149
|
expect(input.tagName).toEqual('DIV');
|
|
150
150
|
expect(input.classList).toContain('hods-readonly');
|
|
151
|
-
expect(input.
|
|
151
|
+
expect(input.id).toEqual(ID);
|
|
152
152
|
expect("".concat(COMPONENT.formData[FIELD_ID])).toEqual(test.result);
|
|
153
153
|
case 13:
|
|
154
154
|
case "end":
|
|
@@ -258,7 +258,7 @@ describe('utils.Component.get', function () {
|
|
|
258
258
|
expect(formGroup.classList).toContain('govuk-form-group');
|
|
259
259
|
expect(input.tagName).toEqual('DIV');
|
|
260
260
|
expect(input.classList).toContain('hods-readonly');
|
|
261
|
-
expect(input.
|
|
261
|
+
expect(input.id).toEqual(ID);
|
|
262
262
|
expect(error).toBeCalledTimes(1);
|
|
263
263
|
expect(error).toBeCalledWith(test.error);
|
|
264
264
|
});
|
|
@@ -51,7 +51,7 @@ describe('utils.Component.get', function () {
|
|
|
51
51
|
expect(input.tagName).toEqual('INPUT');
|
|
52
52
|
expect(input.classList).toContain('govuk-input');
|
|
53
53
|
expect(input.id).toEqual(ID);
|
|
54
|
-
expect(input.
|
|
54
|
+
expect(input.value).toEqual(VALUE);
|
|
55
55
|
child2 = container.childNodes[1];
|
|
56
56
|
expect(child2.childNodes[0].childNodes.length).toEqual(3);
|
|
57
57
|
expect(child2.classList).toContain('govuk-form-group');
|
|
@@ -62,9 +62,9 @@ describe('utils.Component.get', function () {
|
|
|
62
62
|
expect(input2.tagName).toEqual('DIV');
|
|
63
63
|
expect(input2.classList).toContain('govuk-date-input');
|
|
64
64
|
expect(input2.id).toEqual(ID2);
|
|
65
|
-
expect(input2.childNodes[0].childNodes[1].
|
|
66
|
-
expect(input2.childNodes[1].childNodes[1].
|
|
67
|
-
expect(input2.childNodes[2].childNodes[1].
|
|
65
|
+
expect(input2.childNodes[0].childNodes[1].value).toEqual('1');
|
|
66
|
+
expect(input2.childNodes[1].childNodes[1].value).toEqual('2');
|
|
67
|
+
expect(input2.childNodes[2].childNodes[1].value).toEqual('2022');
|
|
68
68
|
case 35:
|
|
69
69
|
case "end":
|
|
70
70
|
return _context.stop();
|
|
@@ -133,7 +133,7 @@ describe('utils.Component.get', function () {
|
|
|
133
133
|
expect(input.tagName).toEqual('INPUT');
|
|
134
134
|
expect(input.classList).toContain('govuk-input');
|
|
135
135
|
expect(input.id).toEqual("".concat(CONTAINER_ID, ".").concat(FIELD_ID));
|
|
136
|
-
expect(input.
|
|
136
|
+
expect(input.value).toEqual(VALUE);
|
|
137
137
|
case 19:
|
|
138
138
|
case "end":
|
|
139
139
|
return _context3.stop();
|
|
@@ -172,7 +172,7 @@ describe('utils.Component.get', function () {
|
|
|
172
172
|
expect(input.tagName).toEqual('INPUT');
|
|
173
173
|
expect(input.classList).toContain('govuk-input');
|
|
174
174
|
expect(input.id).toEqual("".concat(COLLECTION_ID, "[0].").concat(FIELD_ID));
|
|
175
|
-
expect(input.
|
|
175
|
+
expect(input.value).toEqual(VALUE);
|
|
176
176
|
case 19:
|
|
177
177
|
case "end":
|
|
178
178
|
return _context4.stop();
|
|
@@ -12,10 +12,16 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _ty
|
|
|
12
12
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
13
13
|
var DEFAULT_VALUES = (_DEFAULT_VALUES = {}, _defineProperty(_DEFAULT_VALUES, _models.ComponentTypes.COLLECTION, []), _defineProperty(_DEFAULT_VALUES, _models.ComponentTypes.CONTAINER, {}), _defineProperty(_DEFAULT_VALUES, _models.ComponentTypes.FILE, {}), _DEFAULT_VALUES);
|
|
14
14
|
var getDefaultValue = function getDefaultValue(component) {
|
|
15
|
-
if (component) {
|
|
16
|
-
return
|
|
15
|
+
if (!component) {
|
|
16
|
+
return '';
|
|
17
17
|
}
|
|
18
|
-
|
|
18
|
+
if ('defaultValue' in component) {
|
|
19
|
+
return component.defaultValue;
|
|
20
|
+
}
|
|
21
|
+
if ('defaultObjectValue' in component) {
|
|
22
|
+
return component.defaultObjectValue;
|
|
23
|
+
}
|
|
24
|
+
return DEFAULT_VALUES[component.type] || '';
|
|
19
25
|
};
|
|
20
26
|
var _default = getDefaultValue;
|
|
21
27
|
exports.default = _default;
|
|
@@ -38,6 +38,18 @@ describe('utils.Component.defaultValue', function () {
|
|
|
38
38
|
type: _models.ComponentTypes.FILE
|
|
39
39
|
})).toEqual({});
|
|
40
40
|
});
|
|
41
|
+
it('should return defaultValue if the component has defaultValue prop', function () {
|
|
42
|
+
expect((0, _getDefaultValue.default)({
|
|
43
|
+
type: _models.ComponentTypes.AUTOCOMPLETE,
|
|
44
|
+
defaultValue: 'test'
|
|
45
|
+
})).toEqual('test');
|
|
46
|
+
});
|
|
47
|
+
it('should return defaultObjectValue if the component has defaultObjectValue prop', function () {
|
|
48
|
+
expect((0, _getDefaultValue.default)({
|
|
49
|
+
type: _models.ComponentTypes.AUTOCOMPLETE,
|
|
50
|
+
defaultObjectValue: 'test'
|
|
51
|
+
})).toEqual('test');
|
|
52
|
+
});
|
|
41
53
|
Object.values(_models.ComponentTypes).forEach(function (value) {
|
|
42
54
|
if (![_models.ComponentTypes.COLLECTION, _models.ComponentTypes.CONTAINER, _models.ComponentTypes.FILE].includes(value)) {
|
|
43
55
|
it("should return an empty object if the component type is '".concat(value, "'"), function () {
|
|
@@ -29,6 +29,7 @@ var setupRefDataUrlForComponents = function setupRefDataUrlForComponents(compone
|
|
|
29
29
|
};
|
|
30
30
|
var setupRefDataUrlForComponent = function setupRefDataUrlForComponent(component, data) {
|
|
31
31
|
if (component) {
|
|
32
|
+
var _component$data, _component$data2;
|
|
32
33
|
if (component.type === _models.ComponentTypes.CONTAINER) {
|
|
33
34
|
return setupRefDataForContainer(component, data);
|
|
34
35
|
}
|
|
@@ -38,7 +39,7 @@ var setupRefDataUrlForComponent = function setupRefDataUrlForComponent(component
|
|
|
38
39
|
if (component.type === _models.ComponentTypes.SELECT) {
|
|
39
40
|
return component;
|
|
40
41
|
}
|
|
41
|
-
if (component.data && component.data.
|
|
42
|
+
if ((_component$data = component.data) !== null && _component$data !== void 0 && _component$data.url && !((_component$data2 = component.data) !== null && _component$data2 !== void 0 && _component$data2.skipUrlInterpolation)) {
|
|
42
43
|
return _objectSpread(_objectSpread({}, component), {}, {
|
|
43
44
|
data: _objectSpread(_objectSpread({}, component.data), {}, {
|
|
44
45
|
url: _copReactComponents.Utils.interpolateString(component.data.url, data)
|
|
@@ -126,6 +126,24 @@ describe('utils', function () {
|
|
|
126
126
|
}]
|
|
127
127
|
});
|
|
128
128
|
});
|
|
129
|
+
it('should not update the component URL when skipUrlInterpolation prop is true', function () {
|
|
130
|
+
var COMPONENT = {
|
|
131
|
+
id: 'component',
|
|
132
|
+
data: {
|
|
133
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
134
|
+
url: '${urls.refData}/v1/teams',
|
|
135
|
+
skipUrlInterpolation: true
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
expect((0, _setupRefDataUrlForComponent.default)(COMPONENT, DATA)).toEqual({
|
|
139
|
+
id: COMPONENT.id,
|
|
140
|
+
data: {
|
|
141
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
142
|
+
url: '${urls.refData}/v1/teams',
|
|
143
|
+
skipUrlInterpolation: true
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
});
|
|
129
147
|
});
|
|
130
148
|
});
|
|
131
149
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ukhomeoffice/cop-react-form-renderer",
|
|
3
|
-
"version": "5.11.0
|
|
3
|
+
"version": "5.11.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": "3.
|
|
19
|
+
"@ukhomeoffice/cop-react-components": "^3.3.1",
|
|
20
20
|
"axios": "^0.23.0",
|
|
21
21
|
"dayjs": "^1.11.0",
|
|
22
22
|
"govuk-frontend": "^4.3.1",
|