@ukhomeoffice/cop-react-form-renderer 4.36.1 → 4.37.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.
@@ -103,6 +103,24 @@ var meetsCondition = function meetsCondition(condition, value) {
103
103
  return (_value$toString$toLow = !(value !== null && value !== void 0 && value.toString().toLowerCase().includes(compare))) !== null && _value$toString$toLow !== void 0 ? _value$toString$toLow : true; // If no value is provided, the field cannot contain it, so it must meet the condition.
104
104
  }
105
105
 
106
+ case 'includes':
107
+ {
108
+ if (Array.isArray(value)) {
109
+ return value.includes(compare);
110
+ }
111
+
112
+ return false;
113
+ }
114
+
115
+ case '!includes':
116
+ {
117
+ if (Array.isArray(value)) {
118
+ return !value.includes(compare);
119
+ }
120
+
121
+ return true;
122
+ }
123
+
106
124
  default:
107
125
  return false;
108
126
  }
@@ -511,6 +511,106 @@ describe('utils.Condition.meetsCondition', function () {
511
511
  expect((0, _meetsCondition.default)(CONDITION, '101')).toBeTruthy();
512
512
  });
513
513
  });
514
+ describe('operator includes', function () {
515
+ it('should accept a string that exists within the value', function () {
516
+ var VALUE = ['red', 'green', 'blue'];
517
+ var CONDITION = {
518
+ op: 'includes',
519
+ value: 'blue'
520
+ };
521
+ expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
522
+ });
523
+ it('should accept a number that exists within the value', function () {
524
+ var VALUE = [4, 5, 6];
525
+ var CONDITION = {
526
+ op: 'includes',
527
+ value: 6
528
+ };
529
+ expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
530
+ });
531
+ it('should reject a string that doesnt exist within the value', function () {
532
+ var VALUE = ['red', 'green', 'blue'];
533
+ var CONDITION = {
534
+ op: 'includes',
535
+ value: 'purple'
536
+ };
537
+ expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
538
+ });
539
+ it('should reject a number that doesnt exist within the value', function () {
540
+ var VALUE = [4, 5, 6];
541
+ var CONDITION = {
542
+ op: 'includes',
543
+ value: 7
544
+ };
545
+ expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
546
+ });
547
+ it('should reject a value that is not an array', function () {
548
+ var VALUE = 'badValue';
549
+ var CONDITION = {
550
+ op: 'includes',
551
+ value: 7
552
+ };
553
+ expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
554
+ });
555
+ it('should reject an empty array', function () {
556
+ var VALUE = [];
557
+ var CONDITION = {
558
+ op: 'includes',
559
+ value: 7
560
+ };
561
+ expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
562
+ });
563
+ });
564
+ describe('operator !includes', function () {
565
+ it('should reject a string that exists within the value', function () {
566
+ var VALUE = ['red', 'green', 'blue'];
567
+ var CONDITION = {
568
+ op: '!includes',
569
+ value: 'blue'
570
+ };
571
+ expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
572
+ });
573
+ it('should reject a number that exists within the value', function () {
574
+ var VALUE = [4, 5, 6];
575
+ var CONDITION = {
576
+ op: '!includes',
577
+ value: 6
578
+ };
579
+ expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
580
+ });
581
+ it('should accept a string that doesnt exist within the value', function () {
582
+ var VALUE = ['red', 'green', 'blue'];
583
+ var CONDITION = {
584
+ op: '!includes',
585
+ value: 'purple'
586
+ };
587
+ expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
588
+ });
589
+ it('should accept a number that doesnt exist within the value', function () {
590
+ var VALUE = [4, 5, 6];
591
+ var CONDITION = {
592
+ op: '!includes',
593
+ value: 7
594
+ };
595
+ expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
596
+ });
597
+ it('should accept a value that is not an array', function () {
598
+ var VALUE = 'badValue';
599
+ var CONDITION = {
600
+ op: '!includes',
601
+ value: 7
602
+ };
603
+ expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
604
+ });
605
+ it('should accept an empty array', function () {
606
+ var VALUE = [];
607
+ var CONDITION = {
608
+ op: '!includes',
609
+ value: 7
610
+ };
611
+ expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
612
+ });
613
+ });
514
614
  describe('unknown operator', function () {
515
615
  var op = 'definitely_not_a_real_operator';
516
616
  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.36.1",
3
+ "version": "4.37.0",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",