@@ -35,8 +35,16 @@ function setup(propsOverrides = {}) {
3535}
3636
3737describe ( 'DateTimeControl' , ( ) => {
38+ const mockDate = '2025-01-01T12:00:00.000Z' ;
39+
3840 beforeEach ( ( ) => {
3941 jest . clearAllMocks ( ) ;
42+ jest . useFakeTimers ( ) ;
43+ jest . setSystemTime ( new Date ( mockDate ) ) ;
44+ } ) ;
45+
46+ afterEach ( ( ) => {
47+ jest . useRealTimers ( ) ;
4048 } ) ;
4149
4250 test ( 'renders the component with input, now button, and clear button' , ( ) => {
@@ -57,4 +65,26 @@ describe('DateTimeControl', () => {
5765 fireEvent . click ( clearButton ) ;
5866 expect ( props . onChange ) . toHaveBeenCalledWith ( '' ) ;
5967 } ) ;
68+
69+ test ( 'sets value in custom format (local timezone) when input value changes' , ( ) => {
70+ const { input, props } = setup ( { field : new Map ( ) } )
71+
72+ const testDate = '2024-03-15T10:30:00' ;
73+
74+ fireEvent . change ( input , { target : { value : testDate } } ) ;
75+
76+ const expectedValue = dayjs ( testDate ) . format ( 'YYYY-MM-DDTHH:mm:ss.SSSZ' ) ;
77+ expect ( props . onChange ) . toHaveBeenCalledWith ( expectedValue ) ;
78+ } ) ;
79+
80+ test ( 'sets value in custom format (UTC) when input value changes' , ( ) => {
81+ const { input, props } = setup ( { field : new Map ( [ [ 'picker_utc' , true ] ] ) } ) ;
82+
83+ const testDate = '2024-03-15T10:30:00' ;
84+
85+ fireEvent . change ( input , { target : { value : testDate } } ) ;
86+
87+ const expectedValue = dayjs ( testDate ) . format ( 'YYYY-MM-DDTHH:mm:ss.SSS[Z]' ) ;
88+ expect ( props . onChange ) . toHaveBeenCalledWith ( expectedValue ) ;
89+ } ) ;
6090} ) ;
0 commit comments