@ukhomeoffice/cop-react-form-renderer 4.9.0 → 4.10.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/helpers/getComponentDisabled.js +2 -4
- package/dist/components/FormComponent/helpers/getComponentDisabled.test.js +2 -0
- package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.test.js +1 -1
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.js +3 -6
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +1 -0
- package/dist/utils/Operate/getIndexOfMatchingValueIn.js +12 -2
- package/dist/utils/Operate/getIndexOfMatchingValueIn.test.js +19 -1
- package/dist/utils/Operate/persistValueInFormData.test.js +1 -0
- package/dist/utils/Operate/runPageOperations.test.js +2 -0
- package/dist/utils/Operate/setValueInFormData.test.js +1 -0
- package/package.json +1 -1
|
@@ -5,13 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
|
+
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
11
9
|
|
|
12
10
|
var getComponentDisabled = function getComponentDisabled(disabled, formData) {
|
|
13
11
|
if (typeof disabled === 'string') {
|
|
14
|
-
return !!
|
|
12
|
+
return !!_copReactComponents.Utils.interpolateString(disabled, formData);
|
|
15
13
|
}
|
|
16
14
|
|
|
17
15
|
return !!disabled;
|
|
@@ -18,9 +18,11 @@ describe('components.FormComponent.helpers.getComponentDisabled', function () {
|
|
|
18
18
|
expect((0, _getComponentDisabled.default)(true, DATA)).toEqual(true);
|
|
19
19
|
});
|
|
20
20
|
it('should interpolate correctly if disabled is a field path', function () {
|
|
21
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
21
22
|
expect((0, _getComponentDisabled.default)('${shouldDisable}', DATA)).toEqual(true);
|
|
22
23
|
});
|
|
23
24
|
it('should return false if interpolating a field that does not exist', function () {
|
|
25
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
24
26
|
expect((0, _getComponentDisabled.default)('${notARealField}', DATA)).toEqual(false);
|
|
25
27
|
});
|
|
26
28
|
});
|
|
@@ -38,7 +38,7 @@ describe('utils', function () {
|
|
|
38
38
|
it('should remove selected item from the form data', function () {
|
|
39
39
|
var data = null;
|
|
40
40
|
|
|
41
|
-
var ON_ACTION = function ON_ACTION(
|
|
41
|
+
var ON_ACTION = function ON_ACTION(_, call_back) {
|
|
42
42
|
data = call_back(TEST_DATA);
|
|
43
43
|
};
|
|
44
44
|
|
|
@@ -9,6 +9,8 @@ var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
|
9
9
|
|
|
10
10
|
var _models = require("../../models");
|
|
11
11
|
|
|
12
|
+
var _getCYAAction = _interopRequireDefault(require("./getCYAAction"));
|
|
13
|
+
|
|
12
14
|
var _getCYARowsForContainer = _interopRequireDefault(require("./getCYARowsForContainer"));
|
|
13
15
|
|
|
14
16
|
var _showComponentCYA = _interopRequireDefault(require("./showComponentCYA"));
|
|
@@ -28,12 +30,7 @@ var getEntryToCollectionRow = function getEntryToCollectionRow(page, onAction) {
|
|
|
28
30
|
pageId: page.id,
|
|
29
31
|
key: ((_page$components$0$la = page.components[0].labels) === null || _page$components$0$la === void 0 ? void 0 : _page$components$0$la.empty) || 'Nothing entered',
|
|
30
32
|
required: page.required,
|
|
31
|
-
action:
|
|
32
|
-
page: page.id,
|
|
33
|
-
label: "Change",
|
|
34
|
-
aria_suffix: page.cya_link.aria_suffix,
|
|
35
|
-
onAction: onAction
|
|
36
|
-
}
|
|
33
|
+
action: (0, _getCYAAction.default)(false, page, onAction)
|
|
37
34
|
}];
|
|
38
35
|
};
|
|
39
36
|
|
|
@@ -54,9 +54,19 @@ var getIndexOfMatchingValueIn = function getIndexOfMatchingValueIn(config, data)
|
|
|
54
54
|
|
|
55
55
|
if (index === ignore) {
|
|
56
56
|
return true;
|
|
57
|
-
}
|
|
57
|
+
} // Here we're simply checking if value matches the entry itself. This
|
|
58
|
+
// will be enough of a check for arrays of simple values.
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
if (entry === value) {
|
|
62
|
+
result = index;
|
|
63
|
+
return false;
|
|
64
|
+
} // If the last check failed and there is a config.key defined, then
|
|
65
|
+
// we're most likely checking an array of objects and should use the
|
|
66
|
+
// key to index in and find a matching value.
|
|
67
|
+
|
|
58
68
|
|
|
59
|
-
if (
|
|
69
|
+
if (config.key && (0, _getSourceData.default)(entry, config.key) === value) {
|
|
60
70
|
result = index;
|
|
61
71
|
return false;
|
|
62
72
|
}
|
|
@@ -6,7 +6,11 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
6
6
|
|
|
7
7
|
describe('Utils.Operate.getIndexOfPriorMatchingValueIn', function () {
|
|
8
8
|
var DATA = {
|
|
9
|
-
arrayOfValues: ['abc', 'bcd', 'cde', 'def'
|
|
9
|
+
arrayOfValues: ['abc', 'bcd', 'cde', 'def', {
|
|
10
|
+
root: {
|
|
11
|
+
branch: 'leaf'
|
|
12
|
+
}
|
|
13
|
+
}],
|
|
10
14
|
cutoffIndex: 1,
|
|
11
15
|
ignoreIndex: 2,
|
|
12
16
|
valueToSearchFor: 'cde',
|
|
@@ -32,6 +36,7 @@ describe('Utils.Operate.getIndexOfPriorMatchingValueIn', function () {
|
|
|
32
36
|
expect(result).toEqual('2');
|
|
33
37
|
});
|
|
34
38
|
it('Should handle interpolated string for field', function () {
|
|
39
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
35
40
|
var CONFIG = {
|
|
36
41
|
target: 'arrayOfValues',
|
|
37
42
|
field: '${fieldName}'
|
|
@@ -39,6 +44,16 @@ describe('Utils.Operate.getIndexOfPriorMatchingValueIn', function () {
|
|
|
39
44
|
var result = (0, _getIndexOfMatchingValueIn.default)(CONFIG, DATA);
|
|
40
45
|
expect(result).toEqual('2');
|
|
41
46
|
});
|
|
47
|
+
it('Should handle interpolated string for key', function () {
|
|
48
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
49
|
+
var CONFIG = {
|
|
50
|
+
target: 'arrayOfValues',
|
|
51
|
+
key: 'root.branch',
|
|
52
|
+
value: 'leaf'
|
|
53
|
+
};
|
|
54
|
+
var result = (0, _getIndexOfMatchingValueIn.default)(CONFIG, DATA);
|
|
55
|
+
expect(result).toEqual('4');
|
|
56
|
+
});
|
|
42
57
|
it('Should handle a cutoff value being specified', function () {
|
|
43
58
|
var CONFIG = {
|
|
44
59
|
target: 'arrayOfValues',
|
|
@@ -62,6 +77,7 @@ describe('Utils.Operate.getIndexOfPriorMatchingValueIn', function () {
|
|
|
62
77
|
expect(result).toEqual(null); // Cutoff occurs before matching value is reached.
|
|
63
78
|
});
|
|
64
79
|
it('Should handle interpolated string for cutoff.field', function () {
|
|
80
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
65
81
|
var CONFIG = {
|
|
66
82
|
target: 'arrayOfValues',
|
|
67
83
|
value: 'cde',
|
|
@@ -95,6 +111,7 @@ describe('Utils.Operate.getIndexOfPriorMatchingValueIn', function () {
|
|
|
95
111
|
expect(result).toEqual(null); // Should ignore the matching value.
|
|
96
112
|
});
|
|
97
113
|
it('Should handle interpolated string for ignore.field', function () {
|
|
114
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
98
115
|
var CONFIG = {
|
|
99
116
|
target: 'arrayOfValues',
|
|
100
117
|
value: 'cde',
|
|
@@ -106,6 +123,7 @@ describe('Utils.Operate.getIndexOfPriorMatchingValueIn', function () {
|
|
|
106
123
|
expect(result).toEqual(null); // Should ignore the matching value.
|
|
107
124
|
});
|
|
108
125
|
it('Should handle interpolated string for target', function () {
|
|
126
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
109
127
|
var CONFIG = {
|
|
110
128
|
target: '${targetName}',
|
|
111
129
|
value: 'cde'
|
|
@@ -90,6 +90,7 @@ describe('Utils.Operate.persistValueInFormData', function () {
|
|
|
90
90
|
expect(ON_CHANGE_COUNT).toEqual(0);
|
|
91
91
|
});
|
|
92
92
|
it('Should correctly interpolate a field value', function () {
|
|
93
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
93
94
|
var CONFIG = {
|
|
94
95
|
name: 'alpha',
|
|
95
96
|
field: '${beta}'
|
|
@@ -63,6 +63,7 @@ describe('Utils.Operate.runPageOperations', function () {
|
|
|
63
63
|
}, {
|
|
64
64
|
output: 'secondOpResult',
|
|
65
65
|
function: 'setValueInFormData',
|
|
66
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
66
67
|
field: '${firstOpResult}'
|
|
67
68
|
}]
|
|
68
69
|
};
|
|
@@ -77,6 +78,7 @@ describe('Utils.Operate.runPageOperations', function () {
|
|
|
77
78
|
operations: [{
|
|
78
79
|
function: 'setValueInFormData',
|
|
79
80
|
value: 'leaf',
|
|
81
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
80
82
|
output: '${delta}.trunk.branch'
|
|
81
83
|
}]
|
|
82
84
|
};
|
|
@@ -25,6 +25,7 @@ describe('Utils.Operate.addToFormData', function () {
|
|
|
25
25
|
expect(result).toEqual(DATA.a);
|
|
26
26
|
});
|
|
27
27
|
it('Should handle interpolated field strings', function () {
|
|
28
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
28
29
|
var CONFIG = {
|
|
29
30
|
field: 'b[${indexOfThree}]'
|
|
30
31
|
};
|