@ukhomeoffice/cop-react-form-renderer 5.2.0 → 5.3.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.
@@ -77,8 +77,8 @@ var meetsCondition = function meetsCondition(condition, value, data) {
77
77
  if (!value || !compare) {
78
78
  return false;
79
79
  }
80
- var _valFloat = parseFloat(value.replace(',', ''));
81
- var _compareFloat = parseFloat(compare.replace(',', ''));
80
+ var _valFloat = parseFloat(value.replace(/,/g, ''));
81
+ var _compareFloat = parseFloat(compare.replace(/,/g, ''));
82
82
  return _valFloat > _compareFloat;
83
83
  }
84
84
  case 'contains':
@@ -502,6 +502,13 @@ describe('utils.Condition.meetsCondition', function () {
502
502
  };
503
503
  expect((0, _meetsCondition.default)(CONDITION, '99')).toBeTruthy();
504
504
  });
505
+ it('less than should handle values with commas in', function () {
506
+ var CONDITION = {
507
+ op: '<',
508
+ value: '10,000'
509
+ };
510
+ expect((0, _meetsCondition.default)(CONDITION, '9,999')).toBeTruthy();
511
+ });
505
512
  it('greater than should reject when value is null', function () {
506
513
  var CONDITION = {
507
514
  op: '>',
@@ -537,6 +544,13 @@ describe('utils.Condition.meetsCondition', function () {
537
544
  };
538
545
  expect((0, _meetsCondition.default)(CONDITION, '101')).toBeTruthy();
539
546
  });
547
+ it('greater than should handle values with commas in', function () {
548
+ var CONDITION = {
549
+ op: '>',
550
+ value: '10,000'
551
+ };
552
+ expect((0, _meetsCondition.default)(CONDITION, '10,000,000')).toBeTruthy();
553
+ });
540
554
  });
541
555
  describe('operator includes', function () {
542
556
  it('should accept a string that exists within the value', function () {
@@ -15,7 +15,9 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
15
15
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
16
16
  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); }
17
17
  var setDefaultDateValue = function setDefaultDateValue(date, data, fullPath) {
18
- var val = date.defaultValue === 'today' ? (0, _dayjs.default)().format('DD-MM-YYYY') : date.defaultValue;
18
+ var dateFormat = /^(\d{1,2})-\d{1,2}-(\d{4})$/;
19
+ var defaultDate = dateFormat.test(date.defaultValue) ? date.defaultValue : (0, _getSourceData.default)(data, date.defaultValue);
20
+ var val = date.defaultValue === 'today' ? (0, _dayjs.default)().format('DD-MM-YYYY') : defaultDate;
19
21
  (0, _setDataItem.default)(data, "".concat(fullPath).concat(date.fieldId), val);
20
22
  };
21
23
 
@@ -405,6 +405,29 @@ describe('utils', function () {
405
405
  }
406
406
  });
407
407
  });
408
+ it('should handle default values given it is a date with a dot-separated field identifier within pages', function () {
409
+ var PAGES = [{
410
+ components: [{
411
+ fieldId: 'pageFieldA',
412
+ type: 'date',
413
+ defaultValue: 'test.a'
414
+ }, {
415
+ fieldId: 'pageFieldB',
416
+ type: 'date',
417
+ defaultValue: 'test.b'
418
+ }]
419
+ }];
420
+ var COMPONENTS = [];
421
+ var DATA = {
422
+ 'test': {
423
+ 'a': '11-04-2023',
424
+ 'b': '12-5-2023'
425
+ }
426
+ };
427
+ var RESULT = (0, _setupFormData.default)(PAGES, COMPONENTS, DATA);
428
+ expect(RESULT.pageFieldA).toEqual('11-04-2023');
429
+ expect(RESULT.pageFieldB).toEqual('12-5-2023');
430
+ });
408
431
  });
409
432
  });
410
433
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "5.2.0",
3
+ "version": "5.3.0",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",