@ukhomeoffice/cop-react-form-renderer 5.10.0 → 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.
|
@@ -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
|
});
|