@ukhomeoffice/cop-react-form-renderer 4.64.0 → 4.66.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/FormRenderer/FormRenderer.js +2 -1
- package/dist/components/FormRenderer/FormRenderer.test.js +3 -3
- package/dist/utils/Condition/meetsAllConditions.js +1 -1
- package/dist/utils/Condition/meetsCondition.js +12 -3
- package/dist/utils/Condition/meetsCondition.test.js +20 -0
- package/dist/utils/Condition/meetsOneCondition.js +1 -1
- package/dist/utils/Operate/getFirstOf.js +2 -3
- package/dist/utils/Operate/getFirstOf.test.js +9 -0
- package/package.json +2 -2
|
@@ -500,8 +500,9 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
500
500
|
|
|
501
501
|
if (currentTask.state === _models.TaskStates.TYPES.COMPLETE) {
|
|
502
502
|
if (hubDetails !== null && hubDetails !== void 0 && hubDetails.noTaskCYAs) {
|
|
503
|
+
// If the task is complete and there are no CYA's then show user first page
|
|
503
504
|
var currentPage = data.formStatus.tasks[currentTask.name].currentPage;
|
|
504
|
-
onPageChange(
|
|
505
|
+
onPageChange(currentTask.pages[0] || currentPage);
|
|
505
506
|
} else if (currentTask.customCYA) {
|
|
506
507
|
onPageChange(currentTask.customCYA);
|
|
507
508
|
} else {
|
|
@@ -990,7 +990,7 @@ describe('components', function () {
|
|
|
990
990
|
}
|
|
991
991
|
}, _callee28);
|
|
992
992
|
})));
|
|
993
|
-
it('should go to the
|
|
993
|
+
it('should go to the first page of a complete task if noTaskCYAs specified', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee30() {
|
|
994
994
|
var ON_SUBMIT, HOOKS, TASK_LIST_WITH_NO_TASK_CYAS, taskList, newPage;
|
|
995
995
|
return regeneratorRuntime.wrap(function _callee30$(_context30) {
|
|
996
996
|
while (1) {
|
|
@@ -1066,10 +1066,10 @@ describe('components', function () {
|
|
|
1066
1066
|
_react.fireEvent.click(newPage.childNodes[2].childNodes[0], {}); // Launch same task again
|
|
1067
1067
|
|
|
1068
1068
|
|
|
1069
|
-
_react.fireEvent.click(container.childNodes[0].childNodes[1].childNodes[3].childNodes[1].childNodes[0].childNodes[0], {}); // Should be on the
|
|
1069
|
+
_react.fireEvent.click(container.childNodes[0].childNodes[1].childNodes[3].childNodes[1].childNodes[0].childNodes[0], {}); // Should be on the first page
|
|
1070
1070
|
|
|
1071
1071
|
|
|
1072
|
-
expect(container.childNodes[0].childNodes[0].childNodes[0].textContent).toEqual('Event
|
|
1072
|
+
expect(container.childNodes[0].childNodes[0].childNodes[0].textContent).toEqual('Event Date');
|
|
1073
1073
|
|
|
1074
1074
|
case 19:
|
|
1075
1075
|
case "end":
|
|
@@ -29,7 +29,7 @@ var meetsAllConditions = function meetsAllConditions(options, data) {
|
|
|
29
29
|
return arr.every(function (condition) {
|
|
30
30
|
var sourceDataValue = _Data.default.getSource(data, condition.field);
|
|
31
31
|
|
|
32
|
-
return (0, _meetsCondition.default)(condition, sourceDataValue);
|
|
32
|
+
return (0, _meetsCondition.default)(condition, sourceDataValue, data);
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -5,11 +5,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
+
var _Data = _interopRequireDefault(require("../Data"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
8
12
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
9
13
|
|
|
10
|
-
var getComparisonValue = function getComparisonValue(condition) {
|
|
14
|
+
var getComparisonValue = function getComparisonValue(condition, data) {
|
|
15
|
+
var _condition$value;
|
|
16
|
+
|
|
11
17
|
if (['in', 'nin'].includes(condition.op)) {
|
|
12
18
|
return condition.values;
|
|
19
|
+
} else if (typeof condition.value === 'string' && (_condition$value = condition.value) !== null && _condition$value !== void 0 && _condition$value.startsWith('field::')) {
|
|
20
|
+
var comparisonField = condition.value.replace('field::', '');
|
|
21
|
+
return _Data.default.getSource(data, comparisonField);
|
|
13
22
|
}
|
|
14
23
|
|
|
15
24
|
return condition.value;
|
|
@@ -28,9 +37,9 @@ var getComparisonValue = function getComparisonValue(condition) {
|
|
|
28
37
|
*/
|
|
29
38
|
|
|
30
39
|
|
|
31
|
-
var meetsCondition = function meetsCondition(condition, value) {
|
|
40
|
+
var meetsCondition = function meetsCondition(condition, value, data) {
|
|
32
41
|
if (condition && _typeof(condition) === 'object') {
|
|
33
|
-
var compare = getComparisonValue(condition);
|
|
42
|
+
var compare = getComparisonValue(condition, data);
|
|
34
43
|
|
|
35
44
|
switch (condition.op) {
|
|
36
45
|
case '=':
|
|
@@ -64,6 +64,16 @@ describe('utils.Condition.meetsCondition', function () {
|
|
|
64
64
|
var VALUE = false;
|
|
65
65
|
var CONDITION = getCondition(op, false);
|
|
66
66
|
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
67
|
+
});
|
|
68
|
+
it('should match environmentContext value with data object', function () {
|
|
69
|
+
var VALUE = 'Bob';
|
|
70
|
+
var DATA = {
|
|
71
|
+
environmentContext: {
|
|
72
|
+
currentUser: 'Bob'
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
var CONDITION = getCondition(op, 'field::environmentContext.currentUser');
|
|
76
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE, DATA)).toBeTruthy();
|
|
67
77
|
}); // Should reject...
|
|
68
78
|
|
|
69
79
|
it('should reject a null and undefined', function () {
|
|
@@ -147,6 +157,16 @@ describe('utils.Condition.meetsCondition', function () {
|
|
|
147
157
|
var VALUE = false;
|
|
148
158
|
var CONDITION = getCondition(op, false);
|
|
149
159
|
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
160
|
+
});
|
|
161
|
+
it('should reject environmentContext value with data object', function () {
|
|
162
|
+
var VALUE = 'Bob';
|
|
163
|
+
var DATA = {
|
|
164
|
+
environmentContext: {
|
|
165
|
+
currentUser: 'Bob'
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
var CONDITION = getCondition(op, 'field::environmentContext.currentUser');
|
|
169
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE, DATA)).toBeFalsy();
|
|
150
170
|
}); // Should match...
|
|
151
171
|
|
|
152
172
|
it('should match a null and undefined', function () {
|
|
@@ -29,7 +29,7 @@ var meetsOneCondition = function meetsOneCondition(options, data) {
|
|
|
29
29
|
return arr.some(function (condition) {
|
|
30
30
|
var sourceDataValue = _Data.default.getSource(data, condition.field);
|
|
31
31
|
|
|
32
|
-
return (0, _meetsCondition.default)(condition, sourceDataValue);
|
|
32
|
+
return (0, _meetsCondition.default)(condition, sourceDataValue, data);
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -14,9 +14,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
14
14
|
// Global imports.
|
|
15
15
|
// Local imports.
|
|
16
16
|
var getFirstOf = function getFirstOf(config, data) {
|
|
17
|
-
var fieldValue;
|
|
18
|
-
|
|
19
17
|
if (config !== null && config !== void 0 && config.fields) {
|
|
18
|
+
var fieldValue;
|
|
20
19
|
config.fields.find(function (field) {
|
|
21
20
|
var fieldPath = _copReactComponents.Utils.interpolateString(field, data);
|
|
22
21
|
|
|
@@ -29,7 +28,7 @@ var getFirstOf = function getFirstOf(config, data) {
|
|
|
29
28
|
|
|
30
29
|
return false;
|
|
31
30
|
});
|
|
32
|
-
return fieldValue || '';
|
|
31
|
+
return fieldValue || (config.fallback ? _copReactComponents.Utils.interpolateString(config.fallback, data) : '');
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
return (config === null || config === void 0 ? void 0 : config.value) || null;
|
|
@@ -29,6 +29,15 @@ describe('Utils.Operate.addToFormData', function () {
|
|
|
29
29
|
var result = (0, _getFirstOf.default)(CONFIG, DATA);
|
|
30
30
|
expect(result).toEqual(CONFIG.value);
|
|
31
31
|
});
|
|
32
|
+
it('Should return the fallback if the requested fields are not found', function () {
|
|
33
|
+
var CONFIG = {
|
|
34
|
+
value: '2',
|
|
35
|
+
fields: ['nonExistent'],
|
|
36
|
+
fallback: "Test ${name}"
|
|
37
|
+
};
|
|
38
|
+
var result = (0, _getFirstOf.default)(CONFIG, DATA);
|
|
39
|
+
expect(result).toEqual("Test ".concat(DATA.name));
|
|
40
|
+
});
|
|
32
41
|
it('Should return the value of the passportNumber field given in config', function () {
|
|
33
42
|
var CONFIG = {
|
|
34
43
|
fields: ['passportNumber', 'anotherMadeUpId', 'otherIdDoc']
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ukhomeoffice/cop-react-form-renderer",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.66.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.11.
|
|
19
|
+
"@ukhomeoffice/cop-react-components": "^2.11.2",
|
|
20
20
|
"axios": "^0.23.0",
|
|
21
21
|
"dayjs": "^1.11.0",
|
|
22
22
|
"govuk-frontend": "^4.3.1",
|