@ukhomeoffice/cop-react-form-renderer 3.1.1 → 3.2.2

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.
@@ -246,6 +246,27 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
246
246
  var onPageAction = function onPageAction(action, patch) {
247
247
  // Check to see whether the action is able to proceed, which in
248
248
  // in the case of a submission will validate the fields in the page.
249
+ if (action.type === _models.PageAction.TYPES.SUBMIT) {
250
+ if (_helpers.default.canCYASubmit(pages, validate.pages)) {
251
+ // Submit.
252
+ var submissionData = _utils.default.Format.form({
253
+ pages: pages,
254
+ components: components
255
+ }, _objectSpread({}, data), _models.EventTypes.SUBMIT);
256
+
257
+ submissionData.formStatus = _helpers.default.getSubmissionStatus(type, pages, pageId, action, submissionData, currentTask, true);
258
+ setData(submissionData); // Now submit the data to the backend...
259
+
260
+ hooks.onSubmit(action.type, submissionData, function () {
261
+ return hooks.onFormComplete();
262
+ }, function (errors) {
263
+ return _handlers.default.submissionError(errors, addErrors);
264
+ });
265
+ }
266
+ } // Check to see whether the action is able to proceed, which in
267
+ // in the case of a submission will validate the fields in the page.
268
+
269
+
249
270
  if (_helpers.default.canActionProceed(action, formState.page, validate.page)) {
250
271
  patch = _helpers.default.cleanHiddenNestedData(patch, formState.page);
251
272
 
@@ -253,15 +274,15 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
253
274
  _handlers.default.navigate(action, pageId, onPageChange);
254
275
  } else {
255
276
  // Save draft or submit.
256
- var submissionData = _utils.default.Format.form({
277
+ var _submissionData = _utils.default.Format.form({
257
278
  pages: pages,
258
279
  components: components
259
280
  }, _objectSpread(_objectSpread({}, data), patch), _models.EventTypes.SUBMIT);
260
281
 
261
- submissionData.formStatus = _helpers.default.getSubmissionStatus(type, pages, pageId, action, submissionData, currentTask, true);
282
+ _submissionData.formStatus = _helpers.default.getSubmissionStatus(type, pages, pageId, action, _submissionData, currentTask, true);
262
283
 
263
284
  if (patch) {
264
- setData(submissionData);
285
+ setData(_submissionData);
265
286
  }
266
287
 
267
288
  var pageUpdate = function pageUpdate(next) {
@@ -277,10 +298,10 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
277
298
  } // Now submit the data to the backend...
278
299
 
279
300
 
280
- hooks.onSubmit(action.type, submissionData, function (response) {
301
+ hooks.onSubmit(action.type, _submissionData, function (response) {
281
302
  // The backend response may well contain data we need so apply it...
282
303
  // ... but this needs to happen in a useEffect, not right away.
283
- var sData = _objectSpread(_objectSpread({}, submissionData), response);
304
+ var sData = _objectSpread(_objectSpread({}, _submissionData), response);
284
305
 
285
306
  setSubmitted({
286
307
  data: sData
@@ -343,14 +364,14 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
343
364
 
344
365
  if (action.type === _models.PageAction.TYPES.SAVE_AND_CONTINUE && hub === _models.HubFormats.TASK) {
345
366
  if (_helpers.default.canCYASubmit(currentTask.fullPages, validate.pages)) {
346
- var _submissionData = _utils.default.Format.form({
367
+ var _submissionData2 = _utils.default.Format.form({
347
368
  pages: pages,
348
369
  components: components
349
370
  }, _objectSpread({}, data), _models.EventTypes.SUBMIT);
350
371
 
351
- _submissionData.formStatus = _helpers.default.getSubmissionStatus(type, pages, pageId, action, _submissionData, currentTask, true);
352
- setData(_submissionData);
353
- hooks.onSubmit(action.type, _submissionData, function () {
372
+ _submissionData2.formStatus = _helpers.default.getSubmissionStatus(type, pages, pageId, action, _submissionData2, currentTask, true);
373
+ setData(_submissionData2);
374
+ hooks.onSubmit(action.type, _submissionData2, function () {
354
375
  return onPageChange(_models.FormPages.HUB);
355
376
  }, function (errors) {
356
377
  return _handlers.default.submissionError(errors, addErrors);
@@ -360,14 +381,14 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
360
381
 
361
382
  if (action.type === _models.PageAction.TYPES.SAVE_AND_RETURN) {
362
383
  if (_helpers.default.canCYASubmit(currentTask.fullPages, validate.pages)) {
363
- var _submissionData2 = _utils.default.Format.form({
384
+ var _submissionData3 = _utils.default.Format.form({
364
385
  pages: pages,
365
386
  components: components
366
387
  }, _objectSpread({}, data), _models.EventTypes.SUBMIT);
367
388
 
368
- _submissionData2.formStatus = _helpers.default.getSubmissionStatus(type, pages, pageId, action, _submissionData2, currentTask);
369
- setData(_submissionData2);
370
- hooks.onSubmit(action.type, _submissionData2, function () {
389
+ _submissionData3.formStatus = _helpers.default.getSubmissionStatus(type, pages, pageId, action, _submissionData3, currentTask);
390
+ setData(_submissionData3);
391
+ hooks.onSubmit(action.type, _submissionData3, function () {
371
392
  if (type === _models.FormTypes.TASK) {
372
393
  onPageChange(undefined);
373
394
  } else {
@@ -224,8 +224,7 @@ var getComponent = function getComponent(config) {
224
224
  var component = getComponentByType(config);
225
225
 
226
226
  if (component && wrap && (0, _isEditable.default)(config)) {
227
- var attrs = (0, _cleanAttributes.default)(config, ['fieldId', 'displayMenu']);
228
- return (0, _wrapInFormGroup.default)(attrs, component);
227
+ return (0, _wrapInFormGroup.default)(config, component);
229
228
  }
230
229
 
231
230
  return component;
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+
3
+ var _react = require("@testing-library/react");
4
+
5
+ var _models = require("../../../models");
6
+
7
+ var _getComponent = _interopRequireDefault(require("../getComponent"));
8
+
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+
11
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
12
+
13
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
14
+
15
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
16
+
17
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
18
+
19
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
20
+
21
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
22
+
23
+ describe('utils.Component.get', function () {
24
+ it('should return an appropriately rendered time component', function () {
25
+ var ID = 'test-id';
26
+ var FIELD_ID = 'field-id';
27
+ var LABEL = 'label';
28
+ var ON_CHANGE_CALLS = [];
29
+
30
+ var ON_CHANGE = function ON_CHANGE(e) {
31
+ ON_CHANGE_CALLS.push(e.target);
32
+ };
33
+
34
+ var COMPONENT = {
35
+ type: _models.ComponentTypes.TIME,
36
+ id: ID,
37
+ fieldId: FIELD_ID,
38
+ label: LABEL,
39
+ onChange: ON_CHANGE,
40
+ 'data-testid': ID
41
+ };
42
+
43
+ var _render = (0, _react.render)((0, _getComponent.default)(COMPONENT)),
44
+ container = _render.container;
45
+
46
+ var _getAllByTestId = (0, _react.getAllByTestId)(container, ID),
47
+ _getAllByTestId2 = _slicedToArray(_getAllByTestId, 2),
48
+ formGroup = _getAllByTestId2[0],
49
+ timeInput = _getAllByTestId2[1];
50
+
51
+ expect(formGroup.tagName).toEqual('DIV');
52
+ expect(formGroup.classList).toContain('govuk-form-group');
53
+ var label = formGroup.childNodes[0];
54
+ expect(label.innerHTML).toContain(LABEL);
55
+ expect(label.getAttribute('for')).toEqual(ID);
56
+ expect(timeInput.tagName).toEqual('DIV');
57
+ expect(timeInput.classList).toContain('govuk-date-input');
58
+ expect(timeInput.id).toEqual(ID);
59
+ var onChangeCalls = ON_CHANGE_CALLS.length;
60
+
61
+ var _timeInput$childNodes = _slicedToArray(timeInput.childNodes, 2),
62
+ hourItem = _timeInput$childNodes[0],
63
+ minuteItem = _timeInput$childNodes[1];
64
+
65
+ [{
66
+ id: 'hour',
67
+ label: 'Hour',
68
+ item: hourItem,
69
+ value: '5',
70
+ expectedValue: '5:'
71
+ }, {
72
+ id: 'minute',
73
+ label: 'Minute',
74
+ item: minuteItem,
75
+ value: '11',
76
+ expectedValue: '5:11'
77
+ }].forEach(function (part) {
78
+ expect(part.item.tagName).toEqual('DIV');
79
+ expect(part.item.classList).toContain('govuk-date-input__item');
80
+
81
+ var _part$item$childNodes = _slicedToArray(part.item.childNodes, 2),
82
+ label = _part$item$childNodes[0],
83
+ input = _part$item$childNodes[1];
84
+
85
+ expect(label.tagName).toEqual('LABEL');
86
+ expect(label.classList).toContain('govuk-label');
87
+ expect(label.textContent).toEqual(part.label);
88
+ expect(input.tagName).toEqual('INPUT');
89
+ expect(input.id).toEqual("".concat(ID, "-").concat(part.id)); // Put something in the input and make sure it fires.
90
+
91
+ _react.fireEvent.change(input, {
92
+ target: {
93
+ name: "".concat(FIELD_ID, "-").concat(part.id),
94
+ value: part.value
95
+ }
96
+ });
97
+
98
+ onChangeCalls++;
99
+ expect(ON_CHANGE_CALLS.length).toEqual(onChangeCalls);
100
+ expect(ON_CHANGE_CALLS[onChangeCalls - 1]).toMatchObject({
101
+ name: FIELD_ID,
102
+ value: part.expectedValue
103
+ });
104
+ });
105
+ });
106
+ });
@@ -11,6 +11,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
11
11
 
12
12
  // Local imports
13
13
  var showComponent = function showComponent(component, data) {
14
+ var _component$show_when;
15
+
14
16
  if (!component) {
15
17
  return false;
16
18
  }
@@ -19,6 +21,10 @@ var showComponent = function showComponent(component, data) {
19
21
  return false;
20
22
  }
21
23
 
24
+ if (((_component$show_when = component.show_when) === null || _component$show_when === void 0 ? void 0 : _component$show_when.type) === "or") {
25
+ return _Condition.default.meetsOne(component, data);
26
+ }
27
+
22
28
  return _Condition.default.meetsAll(component, data);
23
29
  };
24
30
 
@@ -89,6 +89,69 @@ describe('utils', function () {
89
89
  };
90
90
  expect((0, _showComponent.default)(COMPONENT, DATA)).toBeFalsy();
91
91
  });
92
+ it('SHOULD be shown when the component has multiple show_when conditions, with type "or" provided and ALL are matched', function () {
93
+ var COMPONENT = {
94
+ show_when: {
95
+ "type": "or",
96
+ "conditions": [{
97
+ field: 'alpha',
98
+ op: '=',
99
+ value: 'Alpha'
100
+ }, {
101
+ field: 'bravo',
102
+ op: '=',
103
+ value: 'Bravo'
104
+ }]
105
+ }
106
+ };
107
+ var DATA = {
108
+ alpha: 'Alpha',
109
+ bravo: 'Bravo'
110
+ };
111
+ expect((0, _showComponent.default)(COMPONENT, DATA)).toBeTruthy();
112
+ });
113
+ it('SHOULD be shown when the component has multiple show_when conditions, with type "or" provided and at least ONE is matched', function () {
114
+ var COMPONENT = {
115
+ show_when: {
116
+ "type": "or",
117
+ "conditions": [{
118
+ field: 'alpha',
119
+ op: '=',
120
+ value: 'Alpha'
121
+ }, {
122
+ field: 'charlie',
123
+ op: '=',
124
+ value: 'Charlie'
125
+ }]
126
+ }
127
+ };
128
+ var DATA = {
129
+ alpha: 'Alpha',
130
+ bravo: 'Bravo'
131
+ };
132
+ expect((0, _showComponent.default)(COMPONENT, DATA)).toBeTruthy();
133
+ });
134
+ it('should NOT be shown when the component has multiple show_when conditions, with type "or" provided and NONE are matched', function () {
135
+ var COMPONENT = {
136
+ show_when: {
137
+ "type": "or",
138
+ "conditions": [{
139
+ field: 'alpha',
140
+ op: '!=',
141
+ value: 'Alpha'
142
+ }, {
143
+ field: 'charlie',
144
+ op: '=',
145
+ value: 'Charlie'
146
+ }]
147
+ }
148
+ };
149
+ var DATA = {
150
+ alpha: 'Alpha',
151
+ bravo: 'Bravo'
152
+ };
153
+ expect((0, _showComponent.default)(COMPONENT, DATA)).toBeFalsy();
154
+ });
92
155
  });
93
156
  });
94
157
  });
@@ -5,16 +5,19 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
+ var _copReactComponents = require("@ukhomeoffice/cop-react-components");
9
+
8
10
  var _react = _interopRequireDefault(require("react"));
9
11
 
10
- var _copReactComponents = require("@ukhomeoffice/cop-react-components");
12
+ var _cleanAttributes = _interopRequireDefault(require("./cleanAttributes"));
11
13
 
12
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
15
 
14
16
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
15
17
 
16
18
  var wrapInFormGroup = function wrapInFormGroup(config, children) {
17
- return /*#__PURE__*/_react.default.createElement(_copReactComponents.FormGroup, _extends({}, config, {
19
+ var attrs = (0, _cleanAttributes.default)(config, ['fieldId', 'displayMenu']);
20
+ return /*#__PURE__*/_react.default.createElement(_copReactComponents.FormGroup, _extends({}, attrs, {
18
21
  onChange: null
19
22
  }), children);
20
23
  };
@@ -9,9 +9,12 @@ var _meetsAllConditions = _interopRequireDefault(require("./meetsAllConditions")
9
9
 
10
10
  var _meetsCondition = _interopRequireDefault(require("./meetsCondition"));
11
11
 
12
+ var _meetsOneCondition = _interopRequireDefault(require("./meetsOneCondition"));
13
+
12
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
15
 
14
16
  var Condition = {
17
+ meetsOne: _meetsOneCondition.default,
15
18
  meetsAll: _meetsAllConditions.default,
16
19
  met: _meetsCondition.default
17
20
  };
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _Data = _interopRequireDefault(require("../Data"));
9
+
10
+ var _meetsCondition = _interopRequireDefault(require("./meetsCondition"));
11
+
12
+ var _setupConditions = _interopRequireDefault(require("./setupConditions"));
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ // Local imports
17
+
18
+ /**
19
+ * Evaluates all condition(s) on a page, container, or component.
20
+ * @param {object} options The container to consider.
21
+ * @param {object} data The top-level form data.
22
+ * @returns Boolean true if at least one conditions is met; false otherwise.
23
+ */
24
+ var meetsOneCondition = function meetsOneCondition(options, data) {
25
+ var conditions = (0, _setupConditions.default)(options);
26
+
27
+ if (conditions) {
28
+ var arr = Array.isArray(conditions) ? conditions : [conditions];
29
+ return arr.some(function (condition) {
30
+ var sourceDataValue = _Data.default.getSource(data, condition.field);
31
+
32
+ return (0, _meetsCondition.default)(condition, sourceDataValue);
33
+ });
34
+ }
35
+
36
+ return true;
37
+ };
38
+
39
+ var _default = meetsOneCondition;
40
+ exports.default = _default;
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+
3
+ var _meetsOneCondition = _interopRequireDefault(require("./meetsOneCondition"));
4
+
5
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
+
7
+ // Local imports
8
+ describe('utils.Condition.meetsOneCondition', function () {
9
+ var DATA = {
10
+ alpha: 'bravo',
11
+ charlie: 'delta'
12
+ };
13
+ it('should evaluate to true when conditions are null', function () {
14
+ expect((0, _meetsOneCondition.default)(null, DATA)).toBeTruthy();
15
+ });
16
+ it('should evaluate to true when conditions are undefined', function () {
17
+ expect((0, _meetsOneCondition.default)(undefined, DATA)).toBeTruthy();
18
+ });
19
+ it('should evaluate to true when conditions is an empty array', function () {
20
+ var CONDITION = {
21
+ "type": "or",
22
+ "conditions": []
23
+ };
24
+ expect((0, _meetsOneCondition.default)(CONDITION, DATA)).toBeTruthy();
25
+ });
26
+ it('should evaluate to true when one condition is provided and one condition is met', function () {
27
+ var CONDITION = {
28
+ "type": "or",
29
+ "conditions": [{
30
+ field: 'alpha',
31
+ op: 'eq',
32
+ value: 'bravo'
33
+ }]
34
+ };
35
+ expect((0, _meetsOneCondition.default)(CONDITION, DATA)).toBeTruthy();
36
+ });
37
+ it('should evaluate to true when two conditions are provided and one condition is met', function () {
38
+ var CONDITION = {
39
+ "type": "or",
40
+ "conditions": [{
41
+ field: 'alpha',
42
+ op: 'eq',
43
+ value: 'bravo'
44
+ }, {
45
+ field: 'alpha',
46
+ op: 'eq',
47
+ value: "charlie"
48
+ }]
49
+ };
50
+ expect((0, _meetsOneCondition.default)(CONDITION, DATA)).toBeTruthy();
51
+ });
52
+ it('should evaluate to true when three conditions are provided and two conditions are met', function () {
53
+ var CONDITION = {
54
+ "type": "or",
55
+ "conditions": [{
56
+ field: 'alpha',
57
+ op: 'eq',
58
+ value: 'bravo'
59
+ }, {
60
+ field: 'charlie',
61
+ op: 'eq',
62
+ value: 'delta'
63
+ }, {
64
+ field: 'alpha',
65
+ op: 'eq',
66
+ value: "charlie"
67
+ }]
68
+ };
69
+ expect((0, _meetsOneCondition.default)(CONDITION, DATA)).toBeTruthy();
70
+ });
71
+ it('should evaluate to true when all conditions are met', function () {
72
+ var CONDITION = {
73
+ "type": "or",
74
+ "conditions": [{
75
+ field: 'alpha',
76
+ op: 'eq',
77
+ value: 'bravo'
78
+ }, {
79
+ field: 'charlie',
80
+ op: 'eq',
81
+ value: 'delta'
82
+ }]
83
+ };
84
+ expect((0, _meetsOneCondition.default)(CONDITION, DATA)).toBeTruthy();
85
+ });
86
+ it('should evaluate to false when no conditions are met', function () {
87
+ var CONDITION = {
88
+ "type": "or",
89
+ "conditions": [{
90
+ field: 'alpha',
91
+ op: 'eq',
92
+ value: 'delta'
93
+ }, {
94
+ field: 'charlie',
95
+ op: 'eq',
96
+ value: 'bravo'
97
+ }]
98
+ };
99
+ expect((0, _meetsOneCondition.default)(CONDITION, DATA)).toBeTruthy();
100
+ });
101
+ });
@@ -17,12 +17,13 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
17
17
 
18
18
  var makeComponentFieldsAbsolute = function makeComponentFieldsAbsolute(component) {
19
19
  if (component.show_when) {
20
+ var conditions = component.show_when.type ? component.show_when.conditions : component.show_when;
20
21
  var full_path = component.full_path;
21
- var show_when = Array.isArray(component.show_when) ? component.show_when : [component.show_when];
22
- return show_when.map(function (sw) {
23
- var field = _Data.default.getDataPath(sw.field, full_path);
22
+ conditions = Array.isArray(conditions) ? conditions : [conditions];
23
+ return conditions.map(function (condition) {
24
+ var field = _Data.default.getDataPath(condition.field, full_path);
24
25
 
25
- return _objectSpread(_objectSpread({}, sw), {}, {
26
+ return _objectSpread(_objectSpread({}, condition), {}, {
26
27
  field: field
27
28
  });
28
29
  });
@@ -41,6 +41,10 @@ var showContainer = function showContainer(container, data) {
41
41
 
42
42
 
43
43
  if (container.show_when) {
44
+ if (container.show_when.type === "or") {
45
+ return _Condition.default.meetsOne(container, data);
46
+ }
47
+
44
48
  return _Condition.default.meetsAll(container, data);
45
49
  } // If the container itself doesn't have a show_when, we need to make sure that if it
46
50
  // contains ANY editable components, at least one of them is shown.
@@ -125,4 +125,55 @@ describe('utils.Container.showContainer', function () {
125
125
  };
126
126
  expect((0, _showContainer.default)(CONTAINER, DATA)).toBeTruthy();
127
127
  });
128
+ it('SHOULD be shown when the container has multiple show_when conditions, with type "or" provided and ALL are matched', function () {
129
+ var CONTAINER = {
130
+ show_when: {
131
+ "type": "or",
132
+ "conditions": [{
133
+ field: 'alpha',
134
+ op: '=',
135
+ value: 'Alpha'
136
+ }, {
137
+ field: 'bravo',
138
+ op: '=',
139
+ value: 'Bravo'
140
+ }]
141
+ }
142
+ };
143
+ expect((0, _showContainer.default)(CONTAINER, DATA)).toBeTruthy();
144
+ });
145
+ it('SHOULD be shown when the container has multiple show_when conditions, with type "or" provided and at least ONE is matched', function () {
146
+ var CONTAINER = {
147
+ show_when: {
148
+ "type": "or",
149
+ "conditions": [{
150
+ field: 'alpha',
151
+ op: '=',
152
+ value: 'Alpha'
153
+ }, {
154
+ field: 'charlie',
155
+ op: '=',
156
+ value: 'Charlie'
157
+ }]
158
+ }
159
+ };
160
+ expect((0, _showContainer.default)(CONTAINER, DATA)).toBeTruthy();
161
+ });
162
+ it('should NOT be shown when the container has multiple show_when conditions, with type "or" provided and NONE are matched', function () {
163
+ var CONTAINER = {
164
+ show_when: {
165
+ "type": "or",
166
+ "conditions": [{
167
+ field: 'alpha',
168
+ op: '!=',
169
+ value: 'Alpha'
170
+ }, {
171
+ field: 'charlie',
172
+ op: '=',
173
+ value: 'Charlie'
174
+ }]
175
+ }
176
+ };
177
+ expect((0, _showContainer.default)(CONTAINER, DATA)).toBeFalsy();
178
+ });
128
179
  });
@@ -41,6 +41,10 @@ var showFormPage = function showFormPage(page, data) {
41
41
 
42
42
 
43
43
  if (page.show_when) {
44
+ if (page.show_when.type === "or") {
45
+ return _Condition.default.meetsOne(page, data);
46
+ }
47
+
44
48
  return _Condition.default.meetsAll(page, data);
45
49
  } // If the page itself doesn't have a show_when, we need to make sure that if it
46
50
  // contains ANY editable components, at least one of them is shown.
@@ -126,6 +126,57 @@ describe('utils', function () {
126
126
  };
127
127
  expect((0, _showFormPage.default)(PAGE, DATA)).toBeTruthy();
128
128
  });
129
+ it('SHOULD be shown when the page has multiple show_when conditions, with type "or" provided and ALL are matched', function () {
130
+ var PAGE = {
131
+ show_when: {
132
+ "type": "or",
133
+ "conditions": [{
134
+ field: 'alpha',
135
+ op: '=',
136
+ value: 'Alpha'
137
+ }, {
138
+ field: 'bravo',
139
+ op: '=',
140
+ value: 'Bravo'
141
+ }]
142
+ }
143
+ };
144
+ expect((0, _showFormPage.default)(PAGE, DATA)).toBeTruthy();
145
+ });
146
+ it('SHOULD be shown when the page has multiple show_when conditions, with type "or" provided and at least ONE is matched', function () {
147
+ var PAGE = {
148
+ show_when: {
149
+ "type": "or",
150
+ "conditions": [{
151
+ field: 'alpha',
152
+ op: '=',
153
+ value: 'Alpha'
154
+ }, {
155
+ field: 'charlie',
156
+ op: '=',
157
+ value: 'Charlie'
158
+ }]
159
+ }
160
+ };
161
+ expect((0, _showFormPage.default)(PAGE, DATA)).toBeTruthy();
162
+ });
163
+ it('should NOT be shown when the page has multiple show_when conditions, with type "or" provided and NONE are matched', function () {
164
+ var PAGE = {
165
+ show_when: {
166
+ "type": "or",
167
+ "conditions": [{
168
+ field: 'alpha',
169
+ op: '!=',
170
+ value: 'Alpha'
171
+ }, {
172
+ field: 'charlie',
173
+ op: '=',
174
+ value: 'Charlie'
175
+ }]
176
+ }
177
+ };
178
+ expect((0, _showFormPage.default)(PAGE, DATA)).toBeFalsy();
179
+ });
129
180
  });
130
181
  });
131
182
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "3.1.1",
3
+ "version": "3.2.2",
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": "1.7.3",
19
+ "@ukhomeoffice/cop-react-components": "1.7.4",
20
20
  "axios": "^0.21.1",
21
21
  "dayjs": "^1.11.0",
22
22
  "govuk-frontend": "^3.13.0",