@ukhomeoffice/cop-react-form-renderer 5.77.2 → 5.77.3

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.
@@ -39,6 +39,11 @@ var validateTime = function validateTime(time) {
39
39
  var intMinute = parseInt(minute, 10);
40
40
  var badProps = [];
41
41
  var messages = [];
42
+ var numericRegex = /^\d{0,2}:\d{0,2}$/;
43
+ if (!numericRegex.test(time)) {
44
+ badProps.push('invalid');
45
+ messages.push('Enter a valid time');
46
+ }
42
47
  if (hour.length === 0) {
43
48
  badProps.push('hour');
44
49
  messages.push('Time must include a hour');
@@ -61,6 +66,9 @@ var validateTime = function validateTime(time) {
61
66
  if (badProps.includes('minute')) {
62
67
  propsInError.minute = true;
63
68
  }
69
+ if (badProps.includes('invalid')) {
70
+ propsInError.invalid = true;
71
+ }
64
72
  return {
65
73
  message: badProps.length > 1 ? 'Enter a valid time' : messages[0],
66
74
  propsInError: propsInError
@@ -64,6 +64,52 @@ describe('utils', function () {
64
64
  }
65
65
  });
66
66
  });
67
+ test('should return an error if the time string contains non-numeric characters', function () {
68
+ var output = (0, _validateTime.default)('14:3A');
69
+ expect(output).toEqual({
70
+ message: 'Enter a valid time',
71
+ propsInError: {
72
+ invalid: true,
73
+ minute: true
74
+ }
75
+ });
76
+ });
77
+ test('should return an error if the time string contains more than two digits in hour', function () {
78
+ var output = (0, _validateTime.default)('144:30');
79
+ expect(output).toEqual({
80
+ message: 'Enter a valid time',
81
+ propsInError: {
82
+ invalid: true,
83
+ hour: true
84
+ }
85
+ });
86
+ });
87
+ test('should return an error if the time string contains more than two digits in minute', function () {
88
+ var output = (0, _validateTime.default)('14:309');
89
+ expect(output).toEqual({
90
+ message: 'Enter a valid time',
91
+ propsInError: {
92
+ invalid: true,
93
+ minute: true
94
+ }
95
+ });
96
+ });
97
+ test('should return an error if there is an additional colon in the time string', function () {
98
+ var output = (0, _validateTime.default)('14:30:');
99
+ expect(output).toEqual({
100
+ message: 'Enter a valid time',
101
+ propsInError: {
102
+ invalid: true
103
+ }
104
+ });
105
+ });
106
+ test('should return no error if there is a single digit for both hour and minute', function () {
107
+ var output = (0, _validateTime.default)('1:1');
108
+ expect(output).toEqual({
109
+ message: undefined,
110
+ propsInError: undefined
111
+ });
112
+ });
67
113
  });
68
114
  });
69
115
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "5.77.2",
3
+ "version": "5.77.3",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",