@@ -80,7 +80,7 @@ describe('Workspace', () => {
8080 } ) ;
8181 } ) ;
8282
83- describe ( 'scrollTo (T1310544) ' , ( ) => {
83+ describe ( 'scrollTo' , ( ) => {
8484 beforeEach ( ( ) => {
8585 fx . off = true ;
8686 setupSchedulerTestEnvironment ( { height : 600 } ) ;
@@ -125,5 +125,109 @@ describe('Workspace', () => {
125125
126126 scrollBySpy . mockRestore ( ) ;
127127 } ) ;
128+
129+ describe ( 'hour normalization' , ( ) => {
130+ it ( 'should normalize hours to visible range without viewOffset' , async ( ) => {
131+ const { scheduler } = await createScheduler ( {
132+ views : [ 'timelineDay' ] ,
133+ currentView : 'timelineDay' ,
134+ currentDate : new Date ( 2021 , 1 , 2 ) ,
135+ startDayHour : 6 ,
136+ endDayHour : 18 ,
137+ offset : 0 ,
138+ } ) ;
139+
140+ const workspace = scheduler . getWorkSpace ( ) ;
141+ const scrollable = workspace . getScrollable ( ) ;
142+ const scrollBySpy = jest . spyOn ( scrollable , 'scrollBy' ) ;
143+
144+ // Below startDayHour (6), should normalize to 6
145+ const dateBelowRange = new Date ( 2021 , 1 , 2 , 4 , 0 ) ;
146+ scheduler . scrollTo ( dateBelowRange , undefined , false ) ;
147+ expect ( scrollBySpy ) . toHaveBeenCalled ( ) ;
148+
149+ scrollBySpy . mockClear ( ) ;
150+ // Above endDayHour (18), should normalize to 17
151+ const dateAboveRange = new Date ( 2021 , 1 , 2 , 20 , 0 ) ;
152+ scheduler . scrollTo ( dateAboveRange , undefined , false ) ;
153+ expect ( scrollBySpy ) . toHaveBeenCalled ( ) ;
154+
155+ scrollBySpy . mockClear ( ) ;
156+ // Within range [6, 18), should scroll normally
157+ const dateInRange = new Date ( 2021 , 1 , 2 , 12 , 0 ) ;
158+ scheduler . scrollTo ( dateInRange , undefined , false ) ;
159+ expect ( scrollBySpy ) . toHaveBeenCalled ( ) ;
160+
161+ scrollBySpy . mockRestore ( ) ;
162+ } ) ;
163+
164+ it ( 'should normalize hours to visible range with viewOffset (no midnight crossing)' , async ( ) => {
165+ const { scheduler } = await createScheduler ( {
166+ views : [ 'timelineDay' ] ,
167+ currentView : 'timelineDay' ,
168+ currentDate : new Date ( 2021 , 1 , 2 ) ,
169+ startDayHour : 6 ,
170+ endDayHour : 18 ,
171+ offset : 360 ,
172+ } ) ;
173+
174+ const workspace = scheduler . getWorkSpace ( ) ;
175+ const scrollable = workspace . getScrollable ( ) ;
176+ const scrollBySpy = jest . spyOn ( scrollable , 'scrollBy' ) ;
177+
178+ // Below adjustedStartDayHour (12), should normalize to 12
179+ const dateBelowAdjustedRange = new Date ( 2021 , 1 , 2 , 10 , 0 ) ;
180+ scheduler . scrollTo ( dateBelowAdjustedRange , undefined , false ) ;
181+ expect ( scrollBySpy ) . toHaveBeenCalled ( ) ;
182+
183+ scrollBySpy . mockClear ( ) ;
184+ // Within adjusted range [12, 24), should scroll normally
185+ const dateInAdjustedRange = new Date ( 2021 , 1 , 2 , 15 , 0 ) ;
186+ scheduler . scrollTo ( dateInAdjustedRange , undefined , false ) ;
187+ expect ( scrollBySpy ) . toHaveBeenCalled ( ) ;
188+
189+ scrollBySpy . mockRestore ( ) ;
190+ } ) ;
191+
192+ it ( 'should normalize hours to visible range with viewOffset (midnight crossing)' , async ( ) => {
193+ const { scheduler } = await createScheduler ( {
194+ views : [ 'timelineDay' ] ,
195+ currentView : 'timelineDay' ,
196+ currentDate : new Date ( 2021 , 1 , 2 ) ,
197+ startDayHour : 6 ,
198+ endDayHour : 18 ,
199+ offset : 720 ,
200+ } ) ;
201+
202+ const workspace = scheduler . getWorkSpace ( ) ;
203+ const scrollable = workspace . getScrollable ( ) ;
204+ const scrollBySpy = jest . spyOn ( scrollable , 'scrollBy' ) ;
205+
206+ // In gap [6, 18), should normalize to 18:00 Feb 2
207+ const dateInGap = new Date ( 2021 , 1 , 2 , 10 , 0 ) ;
208+ scheduler . scrollTo ( dateInGap , undefined , false ) ;
209+ expect ( scrollBySpy ) . toHaveBeenCalled ( ) ;
210+
211+ scrollBySpy . mockClear ( ) ;
212+ // In range [18, 24) on Feb 2, should scroll normally
213+ const dateInFirstRange = new Date ( 2021 , 1 , 2 , 22 , 0 ) ;
214+ scheduler . scrollTo ( dateInFirstRange , undefined , false ) ;
215+ expect ( scrollBySpy ) . toHaveBeenCalled ( ) ;
216+
217+ scrollBySpy . mockClear ( ) ;
218+ // In range [0, 6) but on wrong day (Feb 2), should normalize to 18:00 Feb 2
219+ const dateInSecondRangeWrongDay = new Date ( 2021 , 1 , 2 , 3 , 0 ) ;
220+ scheduler . scrollTo ( dateInSecondRangeWrongDay , undefined , false ) ;
221+ expect ( scrollBySpy ) . toHaveBeenCalled ( ) ;
222+
223+ scrollBySpy . mockClear ( ) ;
224+ // In range [0, 6) on correct day (Feb 3), should scroll normally
225+ const dateInSecondRangeCorrectDay = new Date ( 2021 , 1 , 3 , 3 , 0 ) ;
226+ scheduler . scrollTo ( dateInSecondRangeCorrectDay , undefined , false ) ;
227+ expect ( scrollBySpy ) . toHaveBeenCalled ( ) ;
228+
229+ scrollBySpy . mockRestore ( ) ;
230+ } ) ;
231+ } ) ;
128232 } ) ;
129233} ) ;
0 commit comments