@ukhomeoffice/cop-react-form-renderer 4.22.6 → 4.25.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.
@@ -542,7 +542,10 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
542
542
  }
543
543
 
544
544
  if (action.type === _models.PageAction.TYPES.SAVE_AND_RETURN) {
545
- if (_helpers.default.canCYASubmit(currentTask.fullPages, validate.pages)) {
545
+ var shouldValidate = !(action.hasOwnProperty('validate') && !action.validate);
546
+ var canSubmit = shouldValidate ? _helpers.default.canCYASubmit(currentTask.fullPages, validate.pages) : true;
547
+
548
+ if (canSubmit) {
546
549
  var _submissionData3 = _utils.default.Format.form({
547
550
  pages: pages,
548
551
  components: components
@@ -7,8 +7,6 @@ exports.default = void 0;
7
7
 
8
8
  var _copReactComponents = require("@ukhomeoffice/cop-react-components");
9
9
 
10
- var _elevateNestedComponents = _interopRequireDefault(require("../Component/elevateNestedComponents"));
11
-
12
10
  var _models = require("../../models");
13
11
 
14
12
  var _getCYARowsForContainer = _interopRequireDefault(require("./getCYARowsForContainer"));
@@ -17,8 +15,6 @@ var _getCYACollectionDeleteAction = _interopRequireDefault(require("./getCYAColl
17
15
 
18
16
  var _getCYACollectionChangeAction = _interopRequireDefault(require("./getCYACollectionChangeAction"));
19
17
 
20
- var _showComponentCYA = _interopRequireDefault(require("./showComponentCYA"));
21
-
22
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
19
 
24
20
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
@@ -28,27 +24,13 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
28
24
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
29
25
 
30
26
  var getContainerForPage = function getContainerForPage(page, item, labelCount, full_path) {
31
- var allComponents = (0, _elevateNestedComponents.default)(page.components, item);
32
27
  return {
33
28
  id: item.id,
34
29
  fieldId: item.id,
35
30
  type: _models.ComponentTypes.CONTAINER,
36
31
  required: true,
37
32
  full_path: full_path,
38
- components: allComponents.map(function (component) {
39
- if ((0, _showComponentCYA.default)(component, item)) {
40
- return _objectSpread(_objectSpread({}, component), {}, {
41
- label: _copReactComponents.Utils.interpolateString(component.label, _objectSpread(_objectSpread({}, item), {}, {
42
- index: labelCount
43
- })),
44
- full_path: "".concat(full_path, ".").concat(component.fieldId)
45
- });
46
- }
47
-
48
- return undefined;
49
- }).filter(function (c) {
50
- return c;
51
- })
33
+ components: page.components
52
34
  };
53
35
  };
54
36
 
@@ -5,6 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
+ var _addShowWhen = _interopRequireDefault(require("../Component/addShowWhen"));
9
+
10
+ var _applyToComponentTree = _interopRequireDefault(require("../Component/applyToComponentTree"));
11
+
8
12
  var _showFormPageCYA = _interopRequireDefault(require("../FormPage/showFormPageCYA"));
9
13
 
10
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -15,15 +19,31 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
15
19
 
16
20
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
17
21
 
22
+ var getComponentsWithRouting = function getComponentsWithRouting(page) {
23
+ if (!page.collection.route) {
24
+ return page.components;
25
+ } // Apply show_whens to components on certain conditional pages.
26
+ // This ensures that those components aren't shown on the CYA
27
+ // screen if they were never visited by the user.
28
+
29
+
30
+ return page.components.map(function (component) {
31
+ return (0, _applyToComponentTree.default)(component, function (c) {
32
+ return (0, _addShowWhen.default)(c, page.collection.route);
33
+ });
34
+ });
35
+ };
36
+
18
37
  var createMasterPage = function createMasterPage(page) {
19
38
  return _objectSpread(_objectSpread({}, page), {}, {
20
- title: page.collection.name.charAt(0).toUpperCase() + page.collection.name.slice(1)
39
+ title: page.collection.name.charAt(0).toUpperCase() + page.collection.name.slice(1),
40
+ components: getComponentsWithRouting(page)
21
41
  });
22
42
  };
23
43
 
24
44
  var mergeIntoMasterPage = function mergeIntoMasterPage(page, masterPage) {
25
45
  masterPage.collection = _objectSpread(_objectSpread({}, masterPage.collection), page.collection);
26
- masterPage.components = [].concat(masterPage.components, page.components);
46
+ masterPage.components = [].concat(masterPage.components, getComponentsWithRouting(page));
27
47
  masterPage.formData = _objectSpread({}, page.formData);
28
48
  };
29
49
  /**
@@ -128,4 +128,74 @@ describe('utils.CollectionPage.mergeCollectionPages', function () {
128
128
  formData: {}
129
129
  });
130
130
  });
131
+ it('should add a defined route as a show_when to components on the page', function () {
132
+ var PAGES = [{
133
+ id: 'page1',
134
+ collection: {
135
+ name: 'collection',
136
+ route: {
137
+ field: 'field',
138
+ op: '=',
139
+ value: 'value'
140
+ }
141
+ },
142
+ components: [{
143
+ type: 'text'
144
+ }]
145
+ }, {
146
+ id: 'page2',
147
+ collection: {
148
+ name: 'collection',
149
+ route: {
150
+ field: 'field',
151
+ op: '=',
152
+ value: 'otherValue'
153
+ }
154
+ },
155
+ components: [{
156
+ type: 'container',
157
+ components: [{
158
+ type: 'date'
159
+ }]
160
+ }]
161
+ }];
162
+ var RESULT = (0, _mergeCollectionPages.default)(PAGES);
163
+ expect(RESULT.length).toEqual(1);
164
+ expect(RESULT[0]).toEqual({
165
+ id: 'page1',
166
+ title: 'Collection',
167
+ collection: {
168
+ name: 'collection',
169
+ route: {
170
+ field: 'field',
171
+ op: '=',
172
+ value: 'otherValue'
173
+ }
174
+ },
175
+ components: [{
176
+ type: 'text',
177
+ show_when: [{
178
+ field: 'field',
179
+ op: '=',
180
+ value: 'value'
181
+ }]
182
+ }, {
183
+ type: 'container',
184
+ components: [{
185
+ type: 'date',
186
+ show_when: [{
187
+ field: 'field',
188
+ op: '=',
189
+ value: 'otherValue'
190
+ }]
191
+ }],
192
+ show_when: [{
193
+ field: 'field',
194
+ op: '=',
195
+ value: 'otherValue'
196
+ }]
197
+ }],
198
+ formData: {}
199
+ });
200
+ });
131
201
  });
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
9
+
10
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
11
+
12
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
13
+
14
+ /**
15
+ * Adds a show_when to a component.
16
+ * If the component has no show_when, then an array is created
17
+ * with condition as the only entry.
18
+ * If the component has existing show_whens then condition is
19
+ * appended to the existing array.
20
+ * @param {*} component The component to add the show_when to.
21
+ * @param {*} condition The show_when condition to add.
22
+ * @returns The component with the new show_when added.
23
+ * null if component or condition are invalid.
24
+ */
25
+ var addShowWhen = function addShowWhen(component, condition) {
26
+ if (!component) {
27
+ return null;
28
+ }
29
+
30
+ if (!condition) {
31
+ return component;
32
+ }
33
+
34
+ var result = _objectSpread({}, component);
35
+
36
+ if (result.show_when) {
37
+ result.show_when = Array.isArray(result.show_when) ? [].concat(result.show_when, [_objectSpread({}, condition)]) : [result.show_when, _objectSpread({}, condition)];
38
+ } else {
39
+ result.show_when = [_objectSpread({}, condition)];
40
+ }
41
+
42
+ return result;
43
+ };
44
+
45
+ var _default = addShowWhen;
46
+ exports.default = _default;
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+
3
+ var _addShowWhen = _interopRequireDefault(require("./addShowWhen"));
4
+
5
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
+
7
+ // Local imports
8
+ describe('utils.Component.addShowWhen', function () {
9
+ var NEW_SHOW_WHEN = {
10
+ field: 'field',
11
+ op: '=',
12
+ value: 'value'
13
+ };
14
+ it('should return null when component is undefined', function () {
15
+ var result = (0, _addShowWhen.default)(undefined, {});
16
+ expect(result).toEqual(null);
17
+ });
18
+ it('should return null when component is null', function () {
19
+ var result = (0, _addShowWhen.default)(null, {});
20
+ expect(result).toEqual(null);
21
+ });
22
+ it('should return component when condition is undefined', function () {
23
+ var COMPONENT = {
24
+ alpha: 'bravo'
25
+ };
26
+ var result = (0, _addShowWhen.default)(COMPONENT, undefined);
27
+ expect(result).toEqual({
28
+ alpha: 'bravo'
29
+ });
30
+ });
31
+ it('should return component when condition is null', function () {
32
+ var COMPONENT = {
33
+ alpha: 'bravo'
34
+ };
35
+ var result = (0, _addShowWhen.default)(COMPONENT, null);
36
+ expect(result).toEqual({
37
+ alpha: 'bravo'
38
+ });
39
+ });
40
+ it('should add the show_when to a component with no existing show_whens', function () {
41
+ var COMPONENT = {
42
+ alpha: 'bravo'
43
+ };
44
+ var result = (0, _addShowWhen.default)(COMPONENT, NEW_SHOW_WHEN);
45
+ expect(result).toEqual({
46
+ alpha: 'bravo',
47
+ show_when: [NEW_SHOW_WHEN]
48
+ });
49
+ });
50
+ it('should add the show_when to a component with a single show_when', function () {
51
+ var COMPONENT = {
52
+ alpha: 'bravo',
53
+ show_when: {
54
+ field: 'abc',
55
+ op: '=',
56
+ value: 'bcd'
57
+ }
58
+ };
59
+ var result = (0, _addShowWhen.default)(COMPONENT, NEW_SHOW_WHEN);
60
+ expect(result).toEqual({
61
+ alpha: 'bravo',
62
+ show_when: [{
63
+ field: 'abc',
64
+ op: '=',
65
+ value: 'bcd'
66
+ }, NEW_SHOW_WHEN]
67
+ });
68
+ });
69
+ it('should add the show_when to a component with an array of show_whens', function () {
70
+ var COMPONENT = {
71
+ alpha: 'bravo',
72
+ show_when: [{
73
+ field: 'abc',
74
+ op: '=',
75
+ value: 'bcd'
76
+ }, {
77
+ field: 'cde',
78
+ op: '=',
79
+ value: 'efg'
80
+ }]
81
+ };
82
+ var result = (0, _addShowWhen.default)(COMPONENT, NEW_SHOW_WHEN);
83
+ expect(result).toEqual({
84
+ alpha: 'bravo',
85
+ show_when: [{
86
+ field: 'abc',
87
+ op: '=',
88
+ value: 'bcd'
89
+ }, {
90
+ field: 'cde',
91
+ op: '=',
92
+ value: 'efg'
93
+ }, NEW_SHOW_WHEN]
94
+ });
95
+ });
96
+ });
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _models = require("../../models");
9
+
10
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
11
+
12
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
13
+
14
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
15
+
16
+ /**
17
+ * Call a callback on a component and all of its child/nested components.
18
+ * At each stage, the value of the component is set to the returned value
19
+ * from the callback.
20
+ *
21
+ * @param {*} root The root component to call the callback on.
22
+ * @param {*} callback The callback to call. It should take a single
23
+ * component as an argument and return the new
24
+ * desired value for that component.
25
+ * @returns The result of calling callback on root.
26
+ * null if root is not valid.
27
+ * root if callback is not valid.
28
+ */
29
+ var applyToComponentTree = function applyToComponentTree(root, callback) {
30
+ var _root$data;
31
+
32
+ if (!root) {
33
+ return null;
34
+ }
35
+
36
+ if (!callback) {
37
+ return root;
38
+ }
39
+
40
+ var result = _objectSpread({}, root);
41
+
42
+ switch (root.type) {
43
+ case _models.ComponentTypes.CONTAINER:
44
+ result.components.forEach(function (c, index, array) {
45
+ array[index] = applyToComponentTree(c, callback);
46
+ });
47
+ break;
48
+
49
+ case _models.ComponentTypes.COLLECTION:
50
+ result.item.forEach(function (c, index, array) {
51
+ array[index] = applyToComponentTree(c, callback);
52
+ });
53
+ break;
54
+
55
+ case _models.ComponentTypes.CHECKBOXES:
56
+ case _models.ComponentTypes.RADIOS:
57
+ if (!((_root$data = root.data) !== null && _root$data !== void 0 && _root$data.options)) {
58
+ break;
59
+ }
60
+
61
+ result.data = _objectSpread({}, root.data);
62
+ result.data.options = root.data.options.map(function (option) {
63
+ var newOption = _objectSpread({}, option);
64
+
65
+ if (option.nested) {
66
+ newOption.nested = option.nested.map(function (c) {
67
+ return applyToComponentTree(c, callback);
68
+ });
69
+ }
70
+
71
+ return newOption;
72
+ });
73
+ break;
74
+
75
+ default:
76
+ break;
77
+ }
78
+
79
+ return callback(result);
80
+ };
81
+
82
+ var _default = applyToComponentTree;
83
+ exports.default = _default;
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+
3
+ var _applyToComponentTree = _interopRequireDefault(require("./applyToComponentTree"));
4
+
5
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
+
7
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
8
+
9
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
10
+
11
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
12
+
13
+ describe('utils.Component.applyToComponentTree', function () {
14
+ var SINGLE_COMP = {
15
+ type: 'text',
16
+ label: 'alpha'
17
+ };
18
+ var CONTAINER = {
19
+ type: 'container',
20
+ label: 'bravo',
21
+ components: [{
22
+ type: 'text',
23
+ label: 'charlie'
24
+ }]
25
+ };
26
+ var COLLECTION = {
27
+ type: 'collection',
28
+ label: 'delta',
29
+ item: [{
30
+ type: 'text',
31
+ label: 'echo'
32
+ }]
33
+ };
34
+ var COMP_WITH_NESTED = {
35
+ type: 'radios',
36
+ label: 'foxtrot',
37
+ data: {
38
+ options: [{
39
+ nested: [{
40
+ type: 'text',
41
+ label: 'golf'
42
+ }]
43
+ }, {
44
+ nested: [{
45
+ type: 'text',
46
+ label: 'hotel'
47
+ }]
48
+ }]
49
+ }
50
+ };
51
+
52
+ var CALLBACK = function CALLBACK(component) {
53
+ return _objectSpread(_objectSpread({}, component), {}, {
54
+ label: component.label.toUpperCase()
55
+ });
56
+ };
57
+
58
+ it('should return null when root is undefined', function () {
59
+ var result = (0, _applyToComponentTree.default)(undefined, CALLBACK);
60
+ expect(result).toEqual(null);
61
+ });
62
+ it('should return null when root is null', function () {
63
+ var result = (0, _applyToComponentTree.default)(null, CALLBACK);
64
+ expect(result).toEqual(null);
65
+ });
66
+ it('should return root when callback is undefined', function () {
67
+ var result = (0, _applyToComponentTree.default)({
68
+ type: 'text'
69
+ }, undefined);
70
+ expect(result).toEqual({
71
+ type: 'text'
72
+ });
73
+ });
74
+ it('should return root when callback is null', function () {
75
+ var result = (0, _applyToComponentTree.default)({
76
+ type: 'text'
77
+ }, null);
78
+ expect(result).toEqual({
79
+ type: 'text'
80
+ });
81
+ });
82
+ it('should correctly call callback on a single component', function () {
83
+ var result = (0, _applyToComponentTree.default)(SINGLE_COMP, CALLBACK);
84
+ expect(result).toEqual({
85
+ type: 'text',
86
+ label: 'ALPHA'
87
+ });
88
+ });
89
+ it('should correctly call callback on a container component', function () {
90
+ var result = (0, _applyToComponentTree.default)(CONTAINER, CALLBACK);
91
+ expect(result).toEqual({
92
+ type: 'container',
93
+ label: 'BRAVO',
94
+ components: [{
95
+ type: 'text',
96
+ label: 'CHARLIE'
97
+ }]
98
+ });
99
+ });
100
+ it('should correctly call callback on a collection component', function () {
101
+ var result = (0, _applyToComponentTree.default)(COLLECTION, CALLBACK);
102
+ expect(result).toEqual({
103
+ type: 'collection',
104
+ label: 'DELTA',
105
+ item: [{
106
+ type: 'text',
107
+ label: 'ECHO'
108
+ }]
109
+ });
110
+ });
111
+ it('should correctly call callback on a component with nested components', function () {
112
+ var result = (0, _applyToComponentTree.default)(COMP_WITH_NESTED, CALLBACK);
113
+ expect(result).toEqual({
114
+ type: 'radios',
115
+ label: 'FOXTROT',
116
+ data: {
117
+ options: [{
118
+ nested: [{
119
+ type: 'text',
120
+ label: 'GOLF'
121
+ }]
122
+ }, {
123
+ nested: [{
124
+ type: 'text',
125
+ label: 'HOTEL'
126
+ }]
127
+ }]
128
+ }
129
+ });
130
+ });
131
+ });
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ /**
9
+ * Additional validator for the Container component type.
10
+ * @param {object} data the form data
11
+ * @param {object} config the config for the validation, must contain a property 'base' with the id of the conditionally required component and
12
+ * a property 'check' which if the corresponding component has a value will turn off the required check for 'base'
13
+ * @param {object} component the container component
14
+ * @returns true if the user has entered data into the 'base' field or entered a value into the 'check' field to turn off the validation
15
+ * otherwise returns false
16
+ */
17
+ var conditionallyRequired = function conditionallyRequired(data, config, component) {
18
+ var _data$component$id, _data$component$id2;
19
+
20
+ var conditional = (_data$component$id = data[component.id]) === null || _data$component$id === void 0 ? void 0 : _data$component$id[config.base];
21
+ var checkFieldvalue = (_data$component$id2 = data[component.id]) === null || _data$component$id2 === void 0 ? void 0 : _data$component$id2[config.check];
22
+ var checkHasValue = checkFieldvalue && (checkFieldvalue === null || checkFieldvalue === void 0 ? void 0 : checkFieldvalue.length) > 0;
23
+ return !!(conditional || checkHasValue);
24
+ };
25
+
26
+ var _default = conditionallyRequired;
27
+ exports.default = _default;
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+
3
+ var _conditionallyRequired = _interopRequireDefault(require("./conditionallyRequired"));
4
+
5
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
+
7
+ describe('utils', function () {
8
+ describe('Validate', function () {
9
+ describe('additional', function () {
10
+ describe('conditionallyRequired', function () {
11
+ var CONFIG = {
12
+ base: 'componentOne',
13
+ check: 'componentTwo'
14
+ };
15
+ var COMPONENT = {
16
+ id: 'containerComponent',
17
+ fieldId: 'containerComponent',
18
+ type: 'container',
19
+ components: [{
20
+ id: 'componentOne',
21
+ type: 'text',
22
+ fieldId: 'componentOne'
23
+ }, {
24
+ id: 'componentTwo',
25
+ fieldId: 'componentTwo',
26
+ type: 'checkboxes'
27
+ }]
28
+ };
29
+ test('should pass if only the base field has a value', function () {
30
+ var DATA = {
31
+ containerComponent: {
32
+ componentOne: 'value'
33
+ }
34
+ };
35
+ expect((0, _conditionallyRequired.default)(DATA, CONFIG, COMPONENT)).toEqual(true);
36
+ });
37
+ test('should pass if the base and check fields have values', function () {
38
+ var DATA = {
39
+ containerComponent: {
40
+ componentOne: 'value',
41
+ componentTwo: 'value'
42
+ }
43
+ };
44
+ expect((0, _conditionallyRequired.default)(DATA, CONFIG, COMPONENT)).toEqual(true);
45
+ });
46
+ test('should pass if only the check field has a value', function () {
47
+ var DATA = {
48
+ containerComponent: {
49
+ componentTwo: 'value'
50
+ }
51
+ };
52
+ expect((0, _conditionallyRequired.default)(DATA, CONFIG, COMPONENT)).toEqual(true);
53
+ });
54
+ test('should pass if only the check field has a value and that value is an array', function () {
55
+ var DATA = {
56
+ containerComponent: {
57
+ componentTwo: ['value']
58
+ }
59
+ };
60
+ expect((0, _conditionallyRequired.default)(DATA, CONFIG, COMPONENT)).toEqual(true);
61
+ });
62
+ test('should fail if neither field has a value', function () {
63
+ var DATA = {
64
+ containerComponent: {}
65
+ };
66
+ expect((0, _conditionallyRequired.default)(DATA, CONFIG, COMPONENT)).toEqual(false);
67
+ });
68
+ test('should fail if there is no data', function () {
69
+ var DATA = {};
70
+ expect((0, _conditionallyRequired.default)(DATA, CONFIG, COMPONENT)).toEqual(false);
71
+ });
72
+ });
73
+ });
74
+ });
75
+ });
@@ -25,6 +25,8 @@ var _mustBeNumbersOnly = _interopRequireDefault(require("./mustBeNumbersOnly"));
25
25
 
26
26
  var _mustBeLessThan = _interopRequireDefault(require("./mustBeLessThan"));
27
27
 
28
+ var _conditionallyRequired = _interopRequireDefault(require("./conditionallyRequired"));
29
+
28
30
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
31
 
30
32
  // Local imports
@@ -36,6 +38,7 @@ var functions = {
36
38
  mustBeInTheFuture: _mustBeInTheFuture.default,
37
39
  mustBeLongerThan: _mustBeLongerThan.default,
38
40
  mustBeShorterThan: _mustBeShorterThan.default,
41
+ conditionallyRequired: _conditionallyRequired.default,
39
42
  mustEnterAtLeastOne: _mustEnterAtLeastOne.default,
40
43
  mustBeNumbersOnly: _mustBeNumbersOnly.default,
41
44
  mustBeLessThan: _mustBeLessThan.default
@@ -17,7 +17,7 @@ var mustBeLessThan = function mustBeLessThan(string, config) {
17
17
  return true;
18
18
  }
19
19
 
20
- return string < config.value;
20
+ return parseFloat(string) < config.value;
21
21
  };
22
22
 
23
23
  var _default = mustBeLessThan;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "4.22.6",
3
+ "version": "4.25.0",
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": "2.3.4",
19
+ "@ukhomeoffice/cop-react-components": "2.4.0",
20
20
  "axios": "^0.23.0",
21
21
  "dayjs": "^1.11.0",
22
22
  "govuk-frontend": "^4.3.1",