@@ -16,6 +16,8 @@ import {
16
16
validateConsumerGroupId ,
17
17
validateNumber ,
18
18
validateTimeoutNumber ,
19
+ checkTimestamp ,
20
+ checkConvertToDate ,
19
21
} from 'uiSrc/utils'
20
22
21
23
const text1 = '123 123 123'
@@ -32,6 +34,39 @@ const text11 = '3.3.1'
32
34
const text12 = '-3-2'
33
35
const text13 = '5'
34
36
37
+ const checkTimestampTests = [
38
+ { input : '1234567891' , expected : true } ,
39
+ { input : '1234567891234' , expected : true } ,
40
+ { input : '1234567891234567' , expected : true } ,
41
+ { input : '1234567891234567891' , expected : true } ,
42
+ { input : '1234567891.2' , expected : true } ,
43
+ // it should be valid timestamp (for date < 1970)
44
+ { input : '-123456789' , expected : true } ,
45
+ { input : '' , expected : false } ,
46
+ { input : '-' , expected : false } ,
47
+ { input : '0' , expected : false } ,
48
+ { input : '1' , expected : false } ,
49
+ { input : '123' , expected : false } ,
50
+ { input : '12345678911' , expected : false } ,
51
+ { input : '12345678912345' , expected : false } ,
52
+ { input : '12345678912345678' , expected : false } ,
53
+ { input : '1234567891.2.2' , expected : false } ,
54
+ { input : '1234567891asd' , expected : false } ,
55
+ { input : 'inf' , expected : false } ,
56
+ { input : '-inf' , expected : false } ,
57
+ { input : '1234567891:12' , expected : false } ,
58
+ { input : '1234567891a12' , expected : false } ,
59
+ ]
60
+
61
+ const checkConvertToDateTests = [
62
+ ...checkTimestampTests ,
63
+ { input : '2024-08-02T00:00:00.000Z' , expected : true } ,
64
+ { input : '10-10-2020' , expected : true } ,
65
+ { input : '10/10/2020' , expected : true } ,
66
+ { input : '10/10/2020invalid' , expected : false } ,
67
+ { input : 'invalid' , expected : false } ,
68
+ ]
69
+
35
70
describe ( 'Validations utils' , ( ) => {
36
71
describe ( 'validateField' , ( ) => {
37
72
it ( 'validateField should return text without empty spaces' , ( ) => {
@@ -275,4 +310,16 @@ describe('Validations utils', () => {
275
310
expect ( result ) . toBe ( expected )
276
311
} )
277
312
} )
313
+
314
+ describe ( 'checkTimestamp' , ( ) => {
315
+ test . each ( checkTimestampTests ) ( '%j' , ( { input, expected } ) => {
316
+ expect ( checkTimestamp ( input ) ) . toEqual ( expected )
317
+ } )
318
+ } )
319
+
320
+ describe ( 'checkConvertToDate' , ( ) => {
321
+ test . each ( checkConvertToDateTests ) ( '%j' , ( { input, expected } ) => {
322
+ expect ( checkConvertToDate ( input ) ) . toEqual ( expected )
323
+ } )
324
+ } )
278
325
} )
0 commit comments