@ukhomeoffice/cop-react-form-renderer 5.68.2 → 5.69.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.
@@ -108,6 +108,15 @@ var meetsCondition = function meetsCondition(condition, value, data) {
108
108
  }
109
109
  return true;
110
110
  }
111
+ case 'includesObjectProp':
112
+ {
113
+ if (Array.isArray(value)) {
114
+ return value.some(function (v) {
115
+ return v[condition.key] === compare;
116
+ });
117
+ }
118
+ return false;
119
+ }
111
120
  case 'includesAllOf':
112
121
  {
113
122
  if (Array.isArray(value)) {
@@ -652,6 +652,56 @@ describe('utils.Condition.meetsCondition', function () {
652
652
  expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
653
653
  });
654
654
  });
655
+ describe('operator includesObjectProp', function () {
656
+ it('should accept a property that exists within one of the objects in the value', function () {
657
+ var VALUE = [{
658
+ id: 1
659
+ }, {
660
+ id: 2
661
+ }, {
662
+ id: 3
663
+ }];
664
+ var CONDITION = {
665
+ op: 'includesObjectProp',
666
+ key: 'id',
667
+ value: 2
668
+ };
669
+ expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
670
+ });
671
+ it('should reject a property that doesnt exist within one of the objects in the value', function () {
672
+ var VALUE = [{
673
+ id: 1
674
+ }, {
675
+ id: 2
676
+ }, {
677
+ id: 3
678
+ }];
679
+ var CONDITION = {
680
+ op: 'includesObjectProp',
681
+ key: 'id',
682
+ value: 4
683
+ };
684
+ expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
685
+ });
686
+ it('should reject a value that is not an array', function () {
687
+ var VALUE = 'badValue';
688
+ var CONDITION = {
689
+ op: 'includesObjectProp',
690
+ key: 'id',
691
+ value: 7
692
+ };
693
+ expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
694
+ });
695
+ it('should reject an empty array', function () {
696
+ var VALUE = [];
697
+ var CONDITION = {
698
+ op: 'includesObjectProp',
699
+ key: 'id',
700
+ value: 7
701
+ };
702
+ expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
703
+ });
704
+ });
655
705
  describe('operator includesAllOf', function () {
656
706
  it('should reject when value is not an array', function () {
657
707
  var VALUE = 'Not an array';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "5.68.2",
3
+ "version": "5.69.0",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",