@ukhomeoffice/cop-react-form-renderer 5.41.1 → 5.43.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.
@@ -35,7 +35,8 @@ var CollectionPage = function CollectionPage(_ref) {
35
35
  hashLink = _ref.hashLink,
36
36
  classBlock = _ref.classBlock,
37
37
  classModifiers = _ref.classModifiers,
38
- className = _ref.className;
38
+ className = _ref.className,
39
+ submitting = _ref.submitting;
39
40
  var _useState = (0, _react.useState)({}),
40
41
  _useState2 = _slicedToArray(_useState, 2),
41
42
  patch = _useState2[0],
@@ -123,7 +124,8 @@ var CollectionPage = function CollectionPage(_ref) {
123
124
  hashLink: hashLink,
124
125
  classBlock: classBlock,
125
126
  classModifiers: classModifiers,
126
- className: className
127
+ className: className,
128
+ submitting: submitting
127
129
  });
128
130
  };
129
131
  CollectionPage.propTypes = {
@@ -142,13 +144,15 @@ CollectionPage.propTypes = {
142
144
  hashLink: _propTypes.default.bool,
143
145
  classBlock: _propTypes.default.string,
144
146
  classModifiers: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
145
- className: _propTypes.default.string
147
+ className: _propTypes.default.string,
148
+ submitting: _propTypes.default.bool
146
149
  };
147
150
  CollectionPage.defaultProps = {
148
151
  onCollectionChange: undefined,
149
152
  hashLink: false,
150
153
  classBlock: DEFAULT_CLASS,
151
154
  classModifiers: [],
152
- className: ''
155
+ className: '',
156
+ submitting: false
153
157
  };
154
158
  var _default = exports.default = CollectionPage;
@@ -193,7 +193,7 @@ var Collection = function Collection(_ref) {
193
193
  onTopLevelChange: onTopLevelChange,
194
194
  wrap: wrap
195
195
  }), removeStyle === 'end' && /*#__PURE__*/_react.default.createElement(_copReactComponents.ButtonGroup, {
196
- className: "govuk-!-margin-top-1"
196
+ className: "govuk-!-margin-top-2"
197
197
  }, /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {
198
198
  onClick: function onClick() {
199
199
  return onRemoveItem(item);
@@ -15,7 +15,7 @@ var _CollectionSummary = _interopRequireDefault(require("../CollectionSummary"))
15
15
  var _Collection = _interopRequireDefault(require("./Collection"));
16
16
  var _Container = _interopRequireDefault(require("./Container"));
17
17
  var _helpers = require("./helpers");
18
- var _excluded = ["component", "value", "formData", "wrap", "onAction", "onChange", "onTopLevelChange", "pages"]; // Global imports
18
+ var _excluded = ["component", "value", "formData", "wrap", "onAction", "onChange", "onTopLevelChange", "pages", "submitting"]; // Global imports
19
19
  // Local imports
20
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
21
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
@@ -43,6 +43,7 @@ var FormComponent = function FormComponent(_ref) {
43
43
  onChange = _ref.onChange,
44
44
  onTopLevelChange = _ref.onTopLevelChange,
45
45
  pages = _ref.pages,
46
+ submitting = _ref.submitting,
46
47
  attrs = _objectWithoutProperties(_ref, _excluded);
47
48
  var _useHooks = (0, _hooks.useHooks)(),
48
49
  hooks = _useHooks.hooks;
@@ -166,7 +167,8 @@ var FormComponent = function FormComponent(_ref) {
166
167
  value: value,
167
168
  onChange: onComponentChangeExtended,
168
169
  formData: formData,
169
- onAction: onAction
170
+ onAction: onAction,
171
+ submitting: submitting
170
172
  }), wrap, hooks.onGetComponent);
171
173
  };
172
174
  FormComponent.propTypes = {
@@ -201,7 +203,8 @@ FormComponent.propTypes = {
201
203
  onAction: _propTypes.default.func,
202
204
  onChange: _propTypes.default.func,
203
205
  onTopLevelChange: _propTypes.default.func,
204
- pages: _propTypes.default.arrayOf(_propTypes.default.shape({}))
206
+ pages: _propTypes.default.arrayOf(_propTypes.default.shape({})),
207
+ submitting: _propTypes.default.bool
205
208
  };
206
209
  FormComponent.defaultProps = {
207
210
  formData: null,
@@ -210,6 +213,7 @@ FormComponent.defaultProps = {
210
213
  onTopLevelChange: undefined,
211
214
  value: null,
212
215
  wrap: true,
213
- pages: []
216
+ pages: [],
217
+ submitting: false
214
218
  };
215
219
  var _default = exports.default = FormComponent;
@@ -41,7 +41,8 @@ var FormPage = function FormPage(_ref) {
41
41
  hashLink = _ref.hashLink,
42
42
  classBlock = _ref.classBlock,
43
43
  classModifiers = _ref.classModifiers,
44
- className = _ref.className;
44
+ className = _ref.className,
45
+ submitting = _ref.submitting;
45
46
  var _useState = (0, _react.useState)({}),
46
47
  _useState2 = _slicedToArray(_useState, 2),
47
48
  patch = _useState2[0],
@@ -104,7 +105,8 @@ var FormPage = function FormPage(_ref) {
104
105
  onTopLevelChange: onTopLevelChange || onPageChange,
105
106
  value: page.formData[component.fieldId] || patch[component.fieldId],
106
107
  formData: page.formData,
107
- pages: pages
108
+ pages: pages,
109
+ submitting: submitting
108
110
  });
109
111
  });
110
112
  return /*#__PURE__*/_react.default.createElement("div", {
@@ -150,7 +152,8 @@ FormPage.propTypes = {
150
152
  actions: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.shape({}), _propTypes.default.string])),
151
153
  formData: _propTypes.default.shape({}).isRequired
152
154
  }).isRequired,
153
- pages: _propTypes.default.arrayOf(_propTypes.default.shape({}))
155
+ pages: _propTypes.default.arrayOf(_propTypes.default.shape({})),
156
+ submitting: _propTypes.default.bool
154
157
  };
155
158
  FormPage.defaultProps = {
156
159
  classBlock: DEFAULT_CLASS,
@@ -160,6 +163,7 @@ FormPage.defaultProps = {
160
163
  onChange: undefined,
161
164
  onTopLevelChange: undefined,
162
165
  onWrapperChange: undefined,
163
- pages: []
166
+ pages: [],
167
+ submitting: false
164
168
  };
165
169
  var _default = exports.default = FormPage;
@@ -357,7 +357,8 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
357
357
  onChange: onChange,
358
358
  hashLink: hashLink,
359
359
  classModifiers: formState.page.classModifiers,
360
- className: formState.page.className
360
+ className: formState.page.className,
361
+ submitting: submitting
361
362
  }), formState.page && !formState.cya && formState.page.collection && /*#__PURE__*/_react.default.createElement(_CollectionPage.default, {
362
363
  page: formState.page,
363
364
  onCollectionChange: onChange,
@@ -366,7 +367,8 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
366
367
  },
367
368
  hashLink: hashLink,
368
369
  classModifiers: formState.page.classModifiers,
369
- className: formState.page.className
370
+ className: formState.page.className,
371
+ submitting: submitting
370
372
  }));
371
373
  };
372
374
  var propTypes = {
@@ -19,24 +19,58 @@ var getAutocompleteSource = function getAutocompleteSource(config) {
19
19
  var labelMaker = config !== null && config !== void 0 && config.item ? _copReactComponents.Utils.itemLabel(config.item) : null;
20
20
  return function (query, populateResults) {
21
21
  var lcQuery = query ? query.toLowerCase() : '';
22
- populateResults(options.filter(function (opt) {
23
- var _config$item;
22
+
23
+ // go through all options and give them a grade
24
+
25
+ var results = options.map(function (opt) {
24
26
  var label = labelMaker ? labelMaker(opt) : opt.label || '';
25
- if (label.toLowerCase().includes(lcQuery)) {
26
- return true;
27
- }
28
- var matchingSynonym = opt.synonyms ? opt.synonyms.some(function (synonym) {
29
- return synonym.toLowerCase().includes(lcQuery);
30
- }) : false;
31
- if (matchingSynonym) {
32
- return true;
33
- }
34
- return config !== null && config !== void 0 && (_config$item = config.item) !== null && _config$item !== void 0 && _config$item.extraFieldsToSearch ? config.item.extraFieldsToSearch.some(function (field) {
35
- if (typeof opt[field] !== 'string') {
36
- return false;
27
+ var lcLabel = label.toLowerCase();
28
+
29
+ // result 'score'
30
+ var grade = 0;
31
+
32
+ // highest result - match at start of string
33
+ var index = lcLabel.indexOf(lcQuery);
34
+ if (index === 0) {
35
+ grade = 1;
36
+ } else if (index > 0) {
37
+ grade = lcLabel.substring(index - 1).startsWith(" ") ? 2 : 3;
38
+ } else {
39
+ var _config$item;
40
+ if (opt.synonyms) {
41
+ var match = opt.synonyms.some(function (synonym) {
42
+ return synonym.toLowerCase().includes(lcQuery);
43
+ });
44
+ if (match) {
45
+ grade = 4;
46
+ }
47
+ }
48
+ if (!grade && (_config$item = config.item) !== null && _config$item !== void 0 && _config$item.extraFieldsToSearch) {
49
+ var found = config.item.extraFieldsToSearch.some(function (field) {
50
+ if (typeof opt[field] !== 'string') {
51
+ return false;
52
+ }
53
+ return opt[field].toLowerCase().includes(lcQuery);
54
+ });
55
+ if (found) grade = 5;
37
56
  }
38
- return opt[field].toLowerCase().includes(lcQuery);
39
- }) : false;
57
+ }
58
+ return {
59
+ grade: grade,
60
+ label: label,
61
+ opt: opt
62
+ };
63
+ }).filter(function (result) {
64
+ return result.grade > 0;
65
+ });
66
+
67
+ // sort results and then map to just opts
68
+ populateResults(results
69
+ // the sort prioritises grade but also sorts by string value
70
+ .sort(function (r1, r2) {
71
+ return (r1.grade - r2.grade) * 16 + r1.label.localeCompare(r2.label);
72
+ }).map(function (r) {
73
+ return r.opt;
40
74
  }));
41
75
  };
42
76
  };
@@ -2,10 +2,49 @@
2
2
 
3
3
  var _getAutocompleteSource = _interopRequireDefault(require("./getAutocompleteSource"));
4
4
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
5
- // Local imports
6
-
5
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
6
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
7
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
8
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
10
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } // Local imports
7
11
  describe('utils', function () {
8
12
  describe('Data', function () {
13
+ // test data
14
+ var gbCurrency = {
15
+ currencyName: 'Great British Pounds',
16
+ currencyCode: 'GBP',
17
+ value: 'GBP',
18
+ label: 'GBP',
19
+ slangTerm: 'quid'
20
+ };
21
+ var usCurrency = {
22
+ currencyName: 'United States Dollars',
23
+ currencyCode: 'USD',
24
+ value: 'USD',
25
+ label: 'USD',
26
+ slangTerm: 'bucks',
27
+ synonyms: ['greenbacks']
28
+ };
29
+ var options = {
30
+ alpha: {
31
+ value: 'a',
32
+ label: 'Alpha'
33
+ },
34
+ bravo: {
35
+ value: 'b',
36
+ label: 'Bravo'
37
+ },
38
+ alIncluded: {
39
+ value: 'c',
40
+ label: 'Call me alan'
41
+ },
42
+ alStart: {
43
+ value: 'd',
44
+ label: 'Word Alphabet'
45
+ }
46
+ };
47
+ var testCurrencies = [gbCurrency, usCurrency];
9
48
  describe('getAutocompleteSource', function () {
10
49
  it('should handle a null config', function () {
11
50
  var SOURCE = (0, _getAutocompleteSource.default)(null);
@@ -19,26 +58,14 @@ describe('utils', function () {
19
58
  it('should get any specified options from the config', function () {
20
59
  var CONFIG = {
21
60
  data: {
22
- options: [{
23
- value: 'a',
24
- label: 'Alpha'
25
- }, {
26
- value: 'b',
27
- label: 'Bravo'
28
- }]
61
+ options: [options.alpha, options.bravo]
29
62
  }
30
63
  };
31
64
  var SOURCE = (0, _getAutocompleteSource.default)(CONFIG);
32
65
  expect(typeof SOURCE === 'function').toBeTruthy();
33
66
  SOURCE('a', function (results) {
34
67
  expect(results.length).toEqual(2);
35
- expect(results).toEqual([{
36
- value: 'a',
37
- label: 'Alpha'
38
- }, {
39
- value: 'b',
40
- label: 'Bravo'
41
- }]);
68
+ expect(results).toEqual([options.alpha, options.bravo]);
42
69
  });
43
70
  SOURCE('al', function (results) {
44
71
  expect(results.length).toEqual(1);
@@ -51,82 +78,43 @@ describe('utils', function () {
51
78
  it('should handle an empty query', function () {
52
79
  var CONFIG = {
53
80
  data: {
54
- options: [{
55
- value: 'a',
56
- label: 'Alpha'
57
- }, {
58
- value: 'b',
59
- label: 'Bravo'
60
- }]
81
+ options: [options.alpha, options.bravo]
61
82
  }
62
83
  };
63
84
  var SOURCE = (0, _getAutocompleteSource.default)(CONFIG);
64
85
  SOURCE('', function (results) {
65
86
  expect(results.length).toEqual(2);
66
- expect(results).toEqual([{
67
- value: 'a',
68
- label: 'Alpha'
69
- }, {
70
- value: 'b',
71
- label: 'Bravo'
72
- }]);
87
+ expect(results).toEqual([options.alpha, options.bravo]);
73
88
  });
74
89
  });
75
90
  it('should handle an undefined query', function () {
76
91
  var CONFIG = {
77
92
  data: {
78
- options: [{
79
- value: 'a',
80
- label: 'Alpha'
81
- }, {
82
- value: 'b',
83
- label: 'Bravo'
84
- }]
93
+ options: [options.alpha, options.bravo]
85
94
  }
86
95
  };
87
96
  var SOURCE = (0, _getAutocompleteSource.default)(CONFIG);
88
97
  SOURCE(undefined, function (results) {
89
98
  expect(results.length).toEqual(2);
90
- expect(results).toEqual([{
91
- value: 'a',
92
- label: 'Alpha'
93
- }, {
94
- value: 'b',
95
- label: 'Bravo'
96
- }]);
99
+ expect(results).toEqual([options.alpha, options.bravo]);
97
100
  });
98
101
  });
99
102
  it('should handle a null query', function () {
100
103
  var CONFIG = {
101
104
  data: {
102
- options: [{
103
- value: 'a',
104
- label: 'Alpha'
105
- }, {
106
- value: 'b',
107
- label: 'Bravo'
108
- }]
105
+ options: [options.alpha, options.bravo]
109
106
  }
110
107
  };
111
108
  var SOURCE = (0, _getAutocompleteSource.default)(CONFIG);
112
109
  SOURCE(null, function (results) {
113
110
  expect(results.length).toEqual(2);
114
- expect(results).toEqual([{
115
- value: 'a',
116
- label: 'Alpha'
117
- }, {
118
- value: 'b',
119
- label: 'Bravo'
120
- }]);
111
+ expect(results).toEqual([options.alpha, options.bravo]);
121
112
  });
122
113
  });
123
114
  it('should handle a missing label on an option', function () {
124
115
  var CONFIG = {
125
116
  data: {
126
- options: [{
127
- value: 'a',
128
- label: 'Alpha'
129
- }, {
117
+ options: [options.alpha, {
130
118
  value: 'b'
131
119
  }]
132
120
  }
@@ -135,20 +123,28 @@ describe('utils', function () {
135
123
  expect(typeof SOURCE === 'function').toBeTruthy();
136
124
  SOURCE('a', function (results) {
137
125
  expect(results.length).toEqual(1);
138
- expect(results).toEqual([{
139
- value: 'a',
140
- label: 'Alpha'
141
- }]);
126
+ expect(results).toEqual([options.alpha]);
127
+ });
128
+ });
129
+ it('should return matches in the right order', function () {
130
+ var CONFIG = {
131
+ data: {
132
+ options: [options.alIncluded, options.alStart, options.bravo, options.alpha]
133
+ }
134
+ };
135
+ var SOURCE = (0, _getAutocompleteSource.default)(CONFIG);
136
+ expect(typeof SOURCE === 'function').toBeTruthy();
137
+ SOURCE('al', function (results) {
138
+ expect(results.length).toEqual(3);
139
+ expect(results).toEqual([options.alpha, options.alStart, options.alIncluded]);
142
140
  });
143
141
  });
144
142
  it('should match options using a defined synonym', function () {
145
143
  var CONFIG = {
146
144
  data: {
147
- options: [{
148
- value: 'a',
149
- label: 'Alpha',
145
+ options: [_objectSpread(_objectSpread({}, options.alpha), {}, {
150
146
  synonyms: ['first']
151
- }, {
147
+ }), {
152
148
  value: 'b'
153
149
  }]
154
150
  }
@@ -157,11 +153,9 @@ describe('utils', function () {
157
153
  expect(typeof SOURCE === 'function').toBeTruthy();
158
154
  SOURCE('first', function (results) {
159
155
  expect(results.length).toEqual(1);
160
- expect(results).toEqual([{
161
- value: 'a',
162
- label: 'Alpha',
156
+ expect(results).toEqual([_objectSpread(_objectSpread({}, options.alpha), {}, {
163
157
  synonyms: ['first']
164
- }]);
158
+ })]);
165
159
  });
166
160
  });
167
161
  });
@@ -175,43 +169,18 @@ describe('utils', function () {
175
169
  format: '${currencyName} (${currencyCode})'
176
170
  },
177
171
  data: {
178
- options: [{
179
- currencyName: 'Great British Pounds',
180
- currencyCode: 'GBP',
181
- value: 'GBP',
182
- label: 'GBP'
183
- }, {
184
- currencyName: 'United States Dollars',
185
- currencyCode: 'USD',
186
- value: 'USD',
187
- label: 'USD'
188
- }]
172
+ options: testCurrencies
189
173
  }
190
174
  };
191
175
  var SOURCE = (0, _getAutocompleteSource.default)(CONFIG);
192
176
  expect(typeof SOURCE === 'function').toBeTruthy();
193
177
  SOURCE('GB', function (results) {
194
178
  expect(results.length).toEqual(1);
195
- expect(results).toEqual([{
196
- currencyName: 'Great British Pounds',
197
- currencyCode: 'GBP',
198
- value: 'GBP',
199
- label: 'GBP'
200
- }]);
179
+ expect(results).toEqual([gbCurrency]);
201
180
  });
202
181
  SOURCE(' (', function (results) {
203
182
  expect(results.length).toEqual(2);
204
- expect(results).toEqual([{
205
- currencyName: 'Great British Pounds',
206
- currencyCode: 'GBP',
207
- value: 'GBP',
208
- label: 'GBP'
209
- }, {
210
- currencyName: 'United States Dollars',
211
- currencyCode: 'USD',
212
- value: 'USD',
213
- label: 'USD'
214
- }]);
183
+ expect(results).toEqual(testCurrencies);
215
184
  });
216
185
  });
217
186
  it('should handle an empty query', function () {
@@ -223,33 +192,13 @@ describe('utils', function () {
223
192
  format: '${currencyName} (${currencyCode})'
224
193
  },
225
194
  data: {
226
- options: [{
227
- currencyName: 'Great British Pounds',
228
- currencyCode: 'GBP',
229
- value: 'GBP',
230
- label: 'GBP'
231
- }, {
232
- currencyName: 'United States Dollars',
233
- currencyCode: 'USD',
234
- value: 'USD',
235
- label: 'USD'
236
- }]
195
+ options: testCurrencies
237
196
  }
238
197
  };
239
198
  var SOURCE = (0, _getAutocompleteSource.default)(CONFIG);
240
199
  SOURCE('', function (results) {
241
200
  expect(results.length).toEqual(2);
242
- expect(results).toEqual([{
243
- currencyName: 'Great British Pounds',
244
- currencyCode: 'GBP',
245
- value: 'GBP',
246
- label: 'GBP'
247
- }, {
248
- currencyName: 'United States Dollars',
249
- currencyCode: 'USD',
250
- value: 'USD',
251
- label: 'USD'
252
- }]);
201
+ expect(results).toEqual(testCurrencies);
253
202
  });
254
203
  });
255
204
  it('should handle an undefined query', function () {
@@ -261,33 +210,13 @@ describe('utils', function () {
261
210
  format: '${currencyName} (${currencyCode})'
262
211
  },
263
212
  data: {
264
- options: [{
265
- currencyName: 'Great British Pounds',
266
- currencyCode: 'GBP',
267
- value: 'GBP',
268
- label: 'GBP'
269
- }, {
270
- currencyName: 'United States Dollars',
271
- currencyCode: 'USD',
272
- value: 'USD',
273
- label: 'USD'
274
- }]
213
+ options: testCurrencies
275
214
  }
276
215
  };
277
216
  var SOURCE = (0, _getAutocompleteSource.default)(CONFIG);
278
217
  SOURCE(undefined, function (results) {
279
218
  expect(results.length).toEqual(2);
280
- expect(results).toEqual([{
281
- currencyName: 'Great British Pounds',
282
- currencyCode: 'GBP',
283
- value: 'GBP',
284
- label: 'GBP'
285
- }, {
286
- currencyName: 'United States Dollars',
287
- currencyCode: 'USD',
288
- value: 'USD',
289
- label: 'USD'
290
- }]);
219
+ expect(results).toEqual(testCurrencies);
291
220
  });
292
221
  });
293
222
  it('should handle a null query', function () {
@@ -299,33 +228,13 @@ describe('utils', function () {
299
228
  format: '${currencyName} (${currencyCode})'
300
229
  },
301
230
  data: {
302
- options: [{
303
- currencyName: 'Great British Pounds',
304
- currencyCode: 'GBP',
305
- value: 'GBP',
306
- label: 'GBP'
307
- }, {
308
- currencyName: 'United States Dollars',
309
- currencyCode: 'USD',
310
- value: 'USD',
311
- label: 'USD'
312
- }]
231
+ options: testCurrencies
313
232
  }
314
233
  };
315
234
  var SOURCE = (0, _getAutocompleteSource.default)(CONFIG);
316
235
  SOURCE(null, function (results) {
317
236
  expect(results.length).toEqual(2);
318
- expect(results).toEqual([{
319
- currencyName: 'Great British Pounds',
320
- currencyCode: 'GBP',
321
- value: 'GBP',
322
- label: 'GBP'
323
- }, {
324
- currencyName: 'United States Dollars',
325
- currencyCode: 'USD',
326
- value: 'USD',
327
- label: 'USD'
328
- }]);
237
+ expect(results).toEqual(testCurrencies);
329
238
  });
330
239
  });
331
240
  it('should handle a missing label on an option', function () {
@@ -337,12 +246,7 @@ describe('utils', function () {
337
246
  format: '${currencyName} (${currencyCode})'
338
247
  },
339
248
  data: {
340
- options: [{
341
- currencyName: 'Great British Pounds',
342
- currencyCode: 'GBP',
343
- value: 'GBP',
344
- label: 'GBP'
345
- }, {
249
+ options: [gbCurrency, {
346
250
  currencyName: 'United States Dollars',
347
251
  currencyCode: 'USD',
348
252
  value: 'USD'
@@ -356,12 +260,7 @@ describe('utils', function () {
356
260
  // format for item labels means the label is constructed upon processing
357
261
  // a query - we're not relying on the 'label' field of the option.
358
262
  expect(results.length).toEqual(2);
359
- expect(results).toEqual([{
360
- currencyName: 'Great British Pounds',
361
- currencyCode: 'GBP',
362
- value: 'GBP',
363
- label: 'GBP'
364
- }, {
263
+ expect(results).toEqual([gbCurrency, {
365
264
  currencyName: 'United States Dollars',
366
265
  currencyCode: 'USD',
367
266
  value: 'USD',
@@ -378,31 +277,16 @@ describe('utils', function () {
378
277
  format: '${currencyName} (${currencyCode})'
379
278
  },
380
279
  data: {
381
- options: [{
382
- currencyName: 'Great British Pounds',
383
- currencyCode: 'GBP',
384
- value: 'GBP',
385
- label: 'GBP'
386
- }, {
387
- currencyName: 'United States Dollars',
388
- currencyCode: 'USD',
389
- value: 'USD',
390
- label: 'USD',
391
- synonyms: ['bucks']
392
- }]
280
+ options: testCurrencies
393
281
  }
394
282
  };
395
283
  var SOURCE = (0, _getAutocompleteSource.default)(CONFIG);
396
284
  expect(typeof SOURCE === 'function').toBeTruthy();
397
- SOURCE('bucks', function (results) {
285
+ SOURCE('greenbacks', function (results) {
398
286
  expect(results.length).toEqual(1);
399
- expect(results).toEqual([{
400
- currencyName: 'United States Dollars',
401
- currencyCode: 'USD',
402
- value: 'USD',
403
- label: 'USD',
404
- synonyms: ['bucks']
405
- }]);
287
+ expect(results).toEqual(testCurrencies.filter(function (c) {
288
+ return c.currencyCode === 'USD';
289
+ }));
406
290
  });
407
291
  });
408
292
  it('should match options using defined extra searchable fields', function () {
@@ -415,32 +299,16 @@ describe('utils', function () {
415
299
  extraFieldsToSearch: ['slangTerm']
416
300
  },
417
301
  data: {
418
- options: [{
419
- currencyName: 'Great British Pounds',
420
- currencyCode: 'GBP',
421
- value: 'GBP',
422
- label: 'GBP',
423
- slangTerm: 'Quid'
424
- }, {
425
- currencyName: 'United States Dollars',
426
- currencyCode: 'USD',
427
- value: 'USD',
428
- label: 'USD',
429
- slangTerm: 'Dollary-doos'
430
- }]
302
+ options: testCurrencies
431
303
  }
432
304
  };
433
305
  var SOURCE = (0, _getAutocompleteSource.default)(CONFIG);
434
306
  expect(typeof SOURCE === 'function').toBeTruthy();
435
- SOURCE('doo', function (results) {
307
+ SOURCE('buc', function (results) {
436
308
  expect(results.length).toEqual(1);
437
- expect(results).toEqual([{
438
- currencyName: 'United States Dollars',
439
- currencyCode: 'USD',
440
- value: 'USD',
441
- label: 'USD',
442
- slangTerm: 'Dollary-doos'
443
- }]);
309
+ expect(results).toEqual(testCurrencies.filter(function (c) {
310
+ return c.currencyCode === 'USD';
311
+ }));
444
312
  });
445
313
  });
446
314
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "5.41.1",
3
+ "version": "5.43.0",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",