@@ -8,18 +8,20 @@ import ChangeDate from './change-date.svelte';
88describe ( 'ChangeDate component' , ( ) => {
99 const initialDate = DateTime . fromISO ( '2024-01-01' ) ;
1010 const initialTimeZone = 'Europe/Berlin' ;
11+ const targetDate = DateTime . fromISO ( '2024-01-01' ) . setZone ( 'UTC+1' , {
12+ keepLocalTime : true ,
13+ } ) ;
1114 const currentInterval = {
1215 start : DateTime . fromISO ( '2000-02-01T14:00:00+01:00' ) ,
1316 end : DateTime . fromISO ( '2001-02-01T14:00:00+01:00' ) ,
1417 } ;
15- const onCancel = vi . fn ( ) ;
16- const onConfirm = vi . fn ( ) ;
18+ const onClose = vi . fn ( ) ;
1719
1820 const getRelativeInputToggle = ( ) => screen . getByTestId ( 'edit-by-offset-switch' ) ;
1921 const getDateInput = ( ) => screen . getByLabelText ( 'date_and_time' ) as HTMLInputElement ;
2022 const getTimeZoneInput = ( ) => screen . getByLabelText ( 'timezone' ) as HTMLInputElement ;
21- const getCancelButton = ( ) => screen . getByText ( 'Cancel ' ) ;
22- const getConfirmButton = ( ) => screen . getByText ( 'Confirm ' ) ;
23+ const getCancelButton = ( ) => screen . getByText ( 'cancel ' ) ;
24+ const getConfirmButton = ( ) => screen . getByText ( 'confirm ' ) ;
2325
2426 beforeEach ( ( ) => {
2527 vi . stubGlobal ( 'IntersectionObserver' , getIntersectionObserverMock ( ) ) ;
@@ -38,54 +40,64 @@ describe('ChangeDate component', () => {
3840 } ) ;
3941
4042 test ( 'should render correct values' , ( ) => {
41- render ( ChangeDate , { initialDate, initialTimeZone, onCancel , onConfirm } ) ;
43+ render ( ChangeDate , { initialDate, initialTimeZone, onClose } ) ;
4244 expect ( getDateInput ( ) . value ) . toBe ( '2024-01-01T00:00' ) ;
4345 expect ( getTimeZoneInput ( ) . value ) . toBe ( 'Europe/Berlin (+01:00)' ) ;
4446 } ) ;
4547
4648 test ( 'calls onConfirm with correct date on confirm' , async ( ) => {
4749 render ( ChangeDate , {
48- props : { initialDate, initialTimeZone, onCancel , onConfirm } ,
50+ props : { initialDate, initialTimeZone, onClose } ,
4951 } ) ;
5052
5153 await fireEvent . click ( getConfirmButton ( ) ) ;
5254
53- expect ( onConfirm ) . toHaveBeenCalledWith ( { mode : 'absolute' , date : '2024-01-01T00:00:00.000+01:00' } ) ;
55+ expect ( onClose ) . toHaveBeenCalledWith ( {
56+ mode : 'absolute' ,
57+ date : '2024-01-01T00:00:00.000+01:00' ,
58+ dateTime : targetDate ,
59+ } ) ;
5460 } ) ;
5561
5662 test ( 'calls onCancel on cancel' , async ( ) => {
5763 render ( ChangeDate , {
58- props : { initialDate, initialTimeZone, onCancel , onConfirm } ,
64+ props : { initialDate, initialTimeZone, onClose } ,
5965 } ) ;
6066
6167 await fireEvent . click ( getCancelButton ( ) ) ;
6268
63- expect ( onCancel ) . toHaveBeenCalled ( ) ;
69+ expect ( onClose ) . toHaveBeenCalled ( ) ;
6470 } ) ;
6571
6672 describe ( 'when date is in daylight saving time' , ( ) => {
6773 const dstDate = DateTime . fromISO ( '2024-07-01' ) ;
68-
74+ const targetDate = DateTime . fromISO ( '2024-07-01' ) . setZone ( 'UTC+2' , {
75+ keepLocalTime : true ,
76+ } ) ;
6977 test ( 'should render correct timezone with offset' , ( ) => {
70- render ( ChangeDate , { initialDate : dstDate , initialTimeZone, onCancel , onConfirm } ) ;
78+ render ( ChangeDate , { initialDate : dstDate , initialTimeZone, onClose } ) ;
7179
7280 expect ( getTimeZoneInput ( ) . value ) . toBe ( 'Europe/Berlin (+02:00)' ) ;
7381 } ) ;
7482
7583 test ( 'calls onConfirm with correct date on confirm' , async ( ) => {
7684 render ( ChangeDate , {
77- props : { initialDate : dstDate , initialTimeZone, onCancel , onConfirm } ,
85+ props : { initialDate : dstDate , initialTimeZone, onClose } ,
7886 } ) ;
7987
8088 await fireEvent . click ( getConfirmButton ( ) ) ;
8189
82- expect ( onConfirm ) . toHaveBeenCalledWith ( { mode : 'absolute' , date : '2024-07-01T00:00:00.000+02:00' } ) ;
90+ expect ( onClose ) . toHaveBeenCalledWith ( {
91+ mode : 'absolute' ,
92+ date : '2024-07-01T00:00:00.000+02:00' ,
93+ dateTime : targetDate ,
94+ } ) ;
8395 } ) ;
8496 } ) ;
8597
8698 test ( 'calls onConfirm with correct offset in relative mode' , async ( ) => {
8799 render ( ChangeDate , {
88- props : { initialDate, initialTimeZone, currentInterval, onCancel , onConfirm } ,
100+ props : { initialDate, initialTimeZone, currentInterval, onClose } ,
89101 } ) ;
90102
91103 await fireEvent . click ( getRelativeInputToggle ( ) ) ;
@@ -104,7 +116,7 @@ describe('ChangeDate component', () => {
104116
105117 await fireEvent . click ( getConfirmButton ( ) ) ;
106118
107- expect ( onConfirm ) . toHaveBeenCalledWith ( {
119+ expect ( onClose ) . toHaveBeenCalledWith ( {
108120 mode : 'relative' ,
109121 duration : days * 60 * 24 + hours * 60 + minutes ,
110122 timeZone : undefined ,
@@ -114,7 +126,7 @@ describe('ChangeDate component', () => {
114126 test ( 'calls onConfirm with correct timeZone in relative mode' , async ( ) => {
115127 const user = userEvent . setup ( ) ;
116128 render ( ChangeDate , {
117- props : { initialDate, initialTimeZone, currentInterval, onCancel , onConfirm } ,
129+ props : { initialDate, initialTimeZone, currentInterval, onClose } ,
118130 } ) ;
119131
120132 await user . click ( getRelativeInputToggle ( ) ) ;
@@ -123,7 +135,7 @@ describe('ChangeDate component', () => {
123135 await user . keyboard ( '{Enter}' ) ;
124136
125137 await user . click ( getConfirmButton ( ) ) ;
126- expect ( onConfirm ) . toHaveBeenCalledWith ( {
138+ expect ( onClose ) . toHaveBeenCalledWith ( {
127139 mode : 'relative' ,
128140 duration : 0 ,
129141 timeZone : initialTimeZone ,
@@ -177,7 +189,7 @@ describe('ChangeDate component', () => {
177189 ] ;
178190
179191 const component = render ( ChangeDate , {
180- props : { initialDate, initialTimeZone, currentInterval, onCancel , onConfirm } ,
192+ props : { initialDate, initialTimeZone, currentInterval, onClose } ,
181193 } ) ;
182194
183195 for ( const testCase of testCases ) {
0 commit comments