@ukhomeoffice/cop-react-form-renderer 5.7.0 → 5.8.1

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.
@@ -75,11 +75,11 @@ var ValidationContextProvider = function ValidationContextProvider(_ref) {
75
75
  return allErrors;
76
76
  },
77
77
  pages: function pages(_pages) {
78
- var pagesErrors = _pages.flatMap(function (page) {
78
+ var allPagesErrors = _pages.map(function (page) {
79
79
  return _utils.default.Validate.page(page);
80
80
  });
81
- var allErrors = _pages.flatMap(function (page) {
82
- return hooks.onValidate(page, pagesErrors);
81
+ var allErrors = _pages.flatMap(function (page, index) {
82
+ return hooks.onValidate(page, allPagesErrors[index]);
83
83
  });
84
84
  setErrors(allErrors);
85
85
  return allErrors;
@@ -21,7 +21,12 @@ var getAutocompleteSource = function getAutocompleteSource(config) {
21
21
  var lcQuery = query ? query.toLowerCase() : '';
22
22
  populateResults(options.filter(function (opt) {
23
23
  var label = labelMaker ? labelMaker(opt) : opt.label || '';
24
- return label.toLowerCase().includes(lcQuery);
24
+ if (label.toLowerCase().includes(lcQuery)) {
25
+ return true;
26
+ }
27
+ return opt.synonyms ? opt.synonyms.some(function (synonym) {
28
+ return synonym.toLowerCase().includes(lcQuery);
29
+ }) : false;
25
30
  }));
26
31
  };
27
32
  };
@@ -141,6 +141,29 @@ describe('utils', function () {
141
141
  }]);
142
142
  });
143
143
  });
144
+ it('should match options using a defined synonym', function () {
145
+ var CONFIG = {
146
+ data: {
147
+ options: [{
148
+ value: 'a',
149
+ label: 'Alpha',
150
+ synonyms: ['first']
151
+ }, {
152
+ value: 'b'
153
+ }]
154
+ }
155
+ };
156
+ var SOURCE = (0, _getAutocompleteSource.default)(CONFIG);
157
+ expect(typeof SOURCE === 'function').toBeTruthy();
158
+ SOURCE('first', function (results) {
159
+ expect(results.length).toEqual(1);
160
+ expect(results).toEqual([{
161
+ value: 'a',
162
+ label: 'Alpha',
163
+ synonyms: ['first']
164
+ }]);
165
+ });
166
+ });
144
167
  });
145
168
  describe('with custom item labels', function () {
146
169
  it('should get any specified options from the config', function () {
@@ -346,6 +369,42 @@ describe('utils', function () {
346
369
  }]);
347
370
  });
348
371
  });
372
+ it('should match options using a defined synonym', function () {
373
+ var CONFIG = {
374
+ item: {
375
+ value: 'currencyCode',
376
+ label: 'currencyCode',
377
+ // eslint-disable-next-line no-template-curly-in-string
378
+ format: '${currencyName} (${currencyCode})'
379
+ },
380
+ 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
+ }]
393
+ }
394
+ };
395
+ var SOURCE = (0, _getAutocompleteSource.default)(CONFIG);
396
+ expect(typeof SOURCE === 'function').toBeTruthy();
397
+ SOURCE('bucks', function (results) {
398
+ 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
+ }]);
406
+ });
407
+ });
349
408
  });
350
409
  });
351
410
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "5.7.0",
3
+ "version": "5.8.1",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",