@ukhomeoffice/cop-react-form-renderer 5.69.0 → 5.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.
@@ -117,6 +117,15 @@ var meetsCondition = function meetsCondition(condition, value, data) {
117
117
  }
118
118
  return false;
119
119
  }
120
+ case '!includesObjectProp':
121
+ {
122
+ if (Array.isArray(value)) {
123
+ return !value.some(function (v) {
124
+ return v[condition.key] === compare;
125
+ });
126
+ }
127
+ return true;
128
+ }
120
129
  case 'includesAllOf':
121
130
  {
122
131
  if (Array.isArray(value)) {
@@ -702,6 +702,56 @@ describe('utils.Condition.meetsCondition', function () {
702
702
  expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
703
703
  });
704
704
  });
705
+ describe('operator !includesObjectProp', function () {
706
+ it('should reject a property that exists within one of the objects in the value', function () {
707
+ var VALUE = [{
708
+ id: 1
709
+ }, {
710
+ id: 2
711
+ }, {
712
+ id: 3
713
+ }];
714
+ var CONDITION = {
715
+ op: '!includesObjectProp',
716
+ key: 'id',
717
+ value: 2
718
+ };
719
+ expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeFalsy();
720
+ });
721
+ it('should accept a property that doesnt exist within one of the objects in the value', function () {
722
+ var VALUE = [{
723
+ id: 1
724
+ }, {
725
+ id: 2
726
+ }, {
727
+ id: 3
728
+ }];
729
+ var CONDITION = {
730
+ op: '!includesObjectProp',
731
+ key: 'id',
732
+ value: 4
733
+ };
734
+ expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
735
+ });
736
+ it('should accept a value that is not an array', function () {
737
+ var VALUE = 'badValue';
738
+ var CONDITION = {
739
+ op: '!includesObjectProp',
740
+ key: 'id',
741
+ value: 7
742
+ };
743
+ expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
744
+ });
745
+ it('should accept an empty array', function () {
746
+ var VALUE = [];
747
+ var CONDITION = {
748
+ op: '!includesObjectProp',
749
+ key: 'id',
750
+ value: 7
751
+ };
752
+ expect((0, _meetsCondition.default)(CONDITION, VALUE)).toBeTruthy();
753
+ });
754
+ });
705
755
  describe('operator includesAllOf', function () {
706
756
  it('should reject when value is not an array', function () {
707
757
  var VALUE = 'Not an array';
@@ -26,6 +26,10 @@ var interpolateOptions = function interpolateOptions(config, options) {
26
26
  if (typeof opt === 'string') {
27
27
  return opt;
28
28
  }
29
+ if (config.alternativeHintField) {
30
+ // eslint-disable-next-line no-param-reassign
31
+ opt.hint = opt[config.alternativeHintField];
32
+ }
29
33
  return _objectSpread(_objectSpread({}, opt), {}, {
30
34
  value: _copReactComponents.Utils.interpolateString(opt.value, config.formData),
31
35
  label: _copReactComponents.Utils.interpolateString(opt.label, config.formData)
@@ -190,6 +190,24 @@ describe('utils', function () {
190
190
  expect(options).toEqual(MERGED_CONFIG);
191
191
  });
192
192
  });
193
+ it('should override the hint if specified in the config', function () {
194
+ var CONFIG = {
195
+ alternativeHintField: 'description',
196
+ options: [{
197
+ value: 'a',
198
+ label: 'Alpha',
199
+ description: 'first'
200
+ }, {
201
+ value: 'b',
202
+ label: 'Bravo',
203
+ description: 'second'
204
+ }]
205
+ };
206
+ (0, _getOptions.default)(CONFIG, function (options) {
207
+ expect(options[0].hint).toEqual(CONFIG.options[0].description);
208
+ expect(options[1].hint).toEqual(CONFIG.options[1].description);
209
+ });
210
+ });
193
211
  });
194
212
  });
195
213
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "5.69.0",
3
+ "version": "5.71.0",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",