@ukhomeoffice/cop-react-form-renderer 4.70.1 → 4.71.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.
|
@@ -9,7 +9,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
9
9
|
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); }
|
|
10
10
|
var getComparisonValue = function getComparisonValue(condition, data) {
|
|
11
11
|
var _condition$value;
|
|
12
|
-
if (['in', 'nin'].includes(condition.op)) {
|
|
12
|
+
if (['in', 'nin', 'includesAllOf', '!includesAllOf'].includes(condition.op)) {
|
|
13
13
|
return condition.values;
|
|
14
14
|
} else if (typeof condition.value === 'string' && (_condition$value = condition.value) !== null && _condition$value !== void 0 && _condition$value.startsWith('field::')) {
|
|
15
15
|
var comparisonField = condition.value.replace('field::', '');
|
|
@@ -107,6 +107,30 @@ var meetsCondition = function meetsCondition(condition, value, data) {
|
|
|
107
107
|
}
|
|
108
108
|
return true;
|
|
109
109
|
}
|
|
110
|
+
case 'includesAllOf':
|
|
111
|
+
{
|
|
112
|
+
if (Array.isArray(value)) {
|
|
113
|
+
// This will break if compare is not an array, meaning
|
|
114
|
+
// the form JSON has been written incorrectly. Seemed silly
|
|
115
|
+
// to try and hide the configuration error with type checking.
|
|
116
|
+
return compare.every(function (entry) {
|
|
117
|
+
return value.includes(entry);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
case '!includesAllOf':
|
|
123
|
+
{
|
|
124
|
+
if (Array.isArray(value)) {
|
|
125
|
+
// This will break if compare is not an array, meaning
|
|
126
|
+
// the form JSON has been written incorrectly. Seemed silly
|
|
127
|
+
// to try and hide the configuration error with type checking.
|
|
128
|
+
return !compare.every(function (entry) {
|
|
129
|
+
return value.includes(entry);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
110
134
|
default:
|
|
111
135
|
return false;
|
|
112
136
|
}
|
|
@@ -638,6 +638,90 @@ describe('utils.Condition.meetsCondition', function () {
|
|
|
638
638
|
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
639
639
|
});
|
|
640
640
|
});
|
|
641
|
+
describe('operator includesAllOf', function () {
|
|
642
|
+
it('should reject when value is not an array', function () {
|
|
643
|
+
var VALUE = 'Not an array';
|
|
644
|
+
var CONDITION = {
|
|
645
|
+
op: 'includesAllOf',
|
|
646
|
+
values: ['a', 'c']
|
|
647
|
+
};
|
|
648
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
649
|
+
});
|
|
650
|
+
it('should reject when value is an empty array', function () {
|
|
651
|
+
var VALUE = [];
|
|
652
|
+
var CONDITION = {
|
|
653
|
+
op: 'includesAllOf',
|
|
654
|
+
values: ['a', 'c']
|
|
655
|
+
};
|
|
656
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
657
|
+
});
|
|
658
|
+
it('should accept when the list of values is an empty array', function () {
|
|
659
|
+
var VALUE = ['a', 'b', 'c'];
|
|
660
|
+
var CONDITION = {
|
|
661
|
+
op: 'includesAllOf',
|
|
662
|
+
values: []
|
|
663
|
+
};
|
|
664
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
665
|
+
});
|
|
666
|
+
it('should accept a list of values that are all in field', function () {
|
|
667
|
+
var VALUE = ['a', 'b', 'c'];
|
|
668
|
+
var CONDITION = {
|
|
669
|
+
op: 'includesAllOf',
|
|
670
|
+
values: ['a', 'c']
|
|
671
|
+
};
|
|
672
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
673
|
+
});
|
|
674
|
+
it('should reject a list of values if any are missing from field', function () {
|
|
675
|
+
var VALUE = ['a', 'b', 'c'];
|
|
676
|
+
var CONDITION = {
|
|
677
|
+
op: 'includesAllOf',
|
|
678
|
+
values: ['a', 'd']
|
|
679
|
+
};
|
|
680
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
681
|
+
});
|
|
682
|
+
});
|
|
683
|
+
describe('operator !includesAllOf', function () {
|
|
684
|
+
it('should accept when value is not an array', function () {
|
|
685
|
+
var VALUE = 'Not an array';
|
|
686
|
+
var CONDITION = {
|
|
687
|
+
op: '!includesAllOf',
|
|
688
|
+
values: ['a', 'c']
|
|
689
|
+
};
|
|
690
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
691
|
+
});
|
|
692
|
+
it('should accept when value is an empty array', function () {
|
|
693
|
+
var VALUE = [];
|
|
694
|
+
var CONDITION = {
|
|
695
|
+
op: '!includesAllOf',
|
|
696
|
+
values: ['a', 'c']
|
|
697
|
+
};
|
|
698
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
699
|
+
});
|
|
700
|
+
it('should reject when the list of values is an empty array', function () {
|
|
701
|
+
var VALUE = ['a', 'b', 'c'];
|
|
702
|
+
var CONDITION = {
|
|
703
|
+
op: '!includesAllOf',
|
|
704
|
+
values: []
|
|
705
|
+
};
|
|
706
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
707
|
+
});
|
|
708
|
+
it('should reject a list of values that are all in value', function () {
|
|
709
|
+
var VALUE = ['a', 'b', 'c'];
|
|
710
|
+
var CONDITION = {
|
|
711
|
+
op: '!includesAllOf',
|
|
712
|
+
values: ['a', 'c']
|
|
713
|
+
};
|
|
714
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
|
|
715
|
+
});
|
|
716
|
+
it('should accept a list of values if any are missing from value', function () {
|
|
717
|
+
var VALUE = ['a', 'b', 'c'];
|
|
718
|
+
var CONDITION = {
|
|
719
|
+
op: '!includesAllOf',
|
|
720
|
+
values: ['a', 'd']
|
|
721
|
+
};
|
|
722
|
+
expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
|
|
723
|
+
});
|
|
724
|
+
});
|
|
641
725
|
describe('unknown operator', function () {
|
|
642
726
|
var op = 'definitely_not_a_real_operator';
|
|
643
727
|
it('should reject anything regardless of the value', function () {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ukhomeoffice/cop-react-form-renderer",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.71.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.14.
|
|
19
|
+
"@ukhomeoffice/cop-react-components": "^2.14.4",
|
|
20
20
|
"axios": "^0.23.0",
|
|
21
21
|
"dayjs": "^1.11.0",
|
|
22
22
|
"govuk-frontend": "^4.3.1",
|