1- import { toMilliseconds } from '../src/utils.js' ;
1+ import { toMilliseconds , sharedPropsValidation } from '../src/utils.js' ;
22
33describe ( 'utils' , ( ) => {
44 describe ( 'toMilliseconds' , ( ) => {
@@ -17,4 +17,64 @@ describe('utils', () => {
1717 expect ( options ) . toHaveProperty ( 'maximumDate' , 2556057600000 ) ;
1818 } ) ;
1919 } ) ;
20+
21+ describe ( 'sharedPropsValidation' , ( ) => {
22+ describe ( 'minimumDate and maximumDate validation' , ( ) => {
23+ it ( 'should not throw when dates are in correct order' , ( ) => {
24+ const value = new Date ( '2023-06-15' ) ;
25+ const minimumDate = new Date ( '2023-01-01' ) ;
26+ const maximumDate = new Date ( '2023-12-31' ) ;
27+
28+ expect ( ( ) => {
29+ sharedPropsValidation ( { value, minimumDate, maximumDate} ) ;
30+ } ) . not . toThrow ( ) ;
31+ } ) ;
32+
33+ it ( 'should not throw when dates are equal' , ( ) => {
34+ const value = new Date ( '2023-06-15' ) ;
35+ const minimumDate = new Date ( '2023-06-15' ) ;
36+ const maximumDate = new Date ( '2023-06-15' ) ;
37+
38+ expect ( ( ) => {
39+ sharedPropsValidation ( { value, minimumDate, maximumDate} ) ;
40+ } ) . not . toThrow ( ) ;
41+ } ) ;
42+
43+ it ( 'should not throw when only minimumDate is provided' , ( ) => {
44+ const value = new Date ( '2023-06-15' ) ;
45+ const minimumDate = new Date ( '2023-01-01' ) ;
46+
47+ expect ( ( ) => {
48+ sharedPropsValidation ( { value, minimumDate} ) ;
49+ } ) . not . toThrow ( ) ;
50+ } ) ;
51+
52+ it ( 'should not throw when only maximumDate is provided' , ( ) => {
53+ const value = new Date ( '2023-06-15' ) ;
54+ const maximumDate = new Date ( '2023-12-31' ) ;
55+
56+ expect ( ( ) => {
57+ sharedPropsValidation ( { value, maximumDate} ) ;
58+ } ) . not . toThrow ( ) ;
59+ } ) ;
60+
61+ it ( 'should not throw when neither minimumDate nor maximumDate is provided' , ( ) => {
62+ const value = new Date ( '2023-06-15' ) ;
63+
64+ expect ( ( ) => {
65+ sharedPropsValidation ( { value} ) ;
66+ } ) . not . toThrow ( ) ;
67+ } ) ;
68+
69+ it ( 'should throw when minimumDate is after maximumDate' , ( ) => {
70+ const value = new Date ( '2023-06-15' ) ;
71+ const minimumDate = new Date ( '2023-12-31' ) ;
72+ const maximumDate = new Date ( '2023-01-01' ) ;
73+
74+ expect ( ( ) => {
75+ sharedPropsValidation ( { value, minimumDate, maximumDate} ) ;
76+ } ) . toThrow ( 'DateTimePicker: minimumDate (2023-12-31T00:00:00.000Z) is after maximumDate (2023-01-01T00:00:00.000Z). Ensure minimumDate < maximumDate.' ) ;
77+ } ) ;
78+ } ) ;
79+ } ) ;
2080} ) ;
0 commit comments