@ukhomeoffice/cop-react-form-renderer 4.70.2 → 4.72.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.
@@ -88,7 +88,10 @@ var getChangeActionForPage = function getChangeActionForPage(page, item, onActio
88
88
  };
89
89
  };
90
90
  var getCYARowsForCollectionPage = function getCYARowsForCollectionPage(page, onAction) {
91
- var _page$formData, _page$formData$page$c;
91
+ var _page$formData, _page$formData$page$c, _page$formData2, _page$formData2$page$;
92
+ if (!((_page$formData = page.formData) !== null && _page$formData !== void 0 && (_page$formData$page$c = _page$formData[page.collection.name]) !== null && _page$formData$page$c !== void 0 && _page$formData$page$c.length)) {
93
+ return [];
94
+ }
92
95
  var rows = [];
93
96
  if (!page.collection.hideNameFromCYA) {
94
97
  rows.push({
@@ -100,7 +103,7 @@ var getCYARowsForCollectionPage = function getCYARowsForCollectionPage(page, onA
100
103
  size: 'm'
101
104
  });
102
105
  }
103
- (_page$formData = page.formData) === null || _page$formData === void 0 ? void 0 : (_page$formData$page$c = _page$formData[page.collection.name]) === null || _page$formData$page$c === void 0 ? void 0 : _page$formData$page$c.forEach(function (item, index) {
106
+ (_page$formData2 = page.formData) === null || _page$formData2 === void 0 ? void 0 : (_page$formData2$page$ = _page$formData2[page.collection.name]) === null || _page$formData2$page$ === void 0 ? void 0 : _page$formData2$page$.forEach(function (item, index) {
104
107
  var _page$collection2;
105
108
  var labelCount = index + 1;
106
109
  var actionPosition = ((_page$collection2 = page.collection) === null || _page$collection2 === void 0 ? void 0 : _page$collection2.actionPosition) || 'top';
@@ -55,25 +55,39 @@ describe('utils.CheckYourAnswers.getCYARowsForCollectionPage', function () {
55
55
  },
56
56
  collectionPages: PAGES
57
57
  };
58
- it('should return just a heading for the collection if it has no entries', function () {
58
+ it('should return no rows for a collection if it does not exist in formData', function () {
59
59
  var FORM_DATA = {};
60
60
  var PAGE = _objectSpread(_objectSpread({}, MASTER_PAGE), {}, {
61
61
  formData: FORM_DATA
62
62
  });
63
63
  var ROWS = (0, _getCYARowsForCollectionPage.default)(PAGE, null);
64
- expect(ROWS.length).toEqual(1);
65
- expect(ROWS[0].key).toEqual('Collection');
64
+ expect(ROWS.length).toEqual(0);
65
+ });
66
+ it('should return no rows for a collection if it has no entries', function () {
67
+ var FORM_DATA = {
68
+ collection: []
69
+ };
70
+ var PAGE = _objectSpread(_objectSpread({}, MASTER_PAGE), {}, {
71
+ formData: FORM_DATA
72
+ });
73
+ var ROWS = (0, _getCYARowsForCollectionPage.default)(PAGE, null);
74
+ expect(ROWS.length).toEqual(0);
66
75
  });
67
76
  it('should accept the hideNameFromCYA collection flag', function () {
68
- var FORM_DATA = {};
77
+ var FORM_DATA = {
78
+ collection: [{
79
+ testText: 'hello'
80
+ }]
81
+ };
69
82
  var PAGE = _objectSpread(_objectSpread({}, MASTER_PAGE), {}, {
70
83
  formData: FORM_DATA,
71
84
  collection: _objectSpread(_objectSpread({}, MASTER_PAGE.collection), {}, {
72
85
  hideNameFromCYA: true
73
86
  })
74
87
  });
88
+ var TITLE_FIELD_ID = "".concat(PAGE.collection.name, "Title");
75
89
  var ROWS = (0, _getCYARowsForCollectionPage.default)(PAGE, null);
76
- expect(ROWS.length).toEqual(0);
90
+ expect(ROWS[0].fieldId).not.toEqual(TITLE_FIELD_ID);
77
91
  });
78
92
  it('should format titles correctly when collection.labels.item is specified', function () {
79
93
  var FORM_DATA = {
@@ -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.70.2",
3
+ "version": "4.72.0",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",