@@ -126,177 +126,93 @@ describe('Workspace', () => {
126126 scrollBySpy . mockRestore ( ) ;
127127 } ) ;
128128
129- it ( 'should scroll to date with offset after midnight: 720 (12 hours)' , async ( ) => {
130- const { scheduler } = await createScheduler ( {
131- views : [ 'timelineDay' ] ,
132- currentView : 'timelineDay' ,
133- currentDate : new Date ( 2021 , 1 , 2 ) ,
134- firstDayOfWeek : 0 ,
135- startDayHour : 6 ,
136- endDayHour : 18 ,
137- offset : 720 ,
138- cellDuration : 60 ,
139- height : 580 ,
140- } ) ;
141-
142- const workspace = scheduler . getWorkSpace ( ) ;
143- const scrollable = workspace . getScrollable ( ) ;
144- const $scrollable = scrollable . $element ( ) ;
145- const scrollBySpy = jest . spyOn ( scrollable , 'scrollBy' ) ;
146-
147- // With offset: 720 (12 hours), cells start at 18:00 (6:00 + 12h)
148- // For date 3 feb 04:00, this should be cell index 10 (18:00=0, 19:00=1, ... 04:00=10)
149- const leftCellCount = 10 ;
150- const cellWidth = workspace . getCellWidth ( ) ;
151- const scrollableWidth = getWidth ( $scrollable ) ;
152- const expectedLeft = leftCellCount * cellWidth - ( scrollableWidth - cellWidth ) / 2 ;
153-
154- const targetDate = new Date ( 2021 , 1 , 3 , 4 , 0 ) ;
155- scheduler . scrollTo ( targetDate , undefined , false ) ;
156-
157- expect ( scrollBySpy ) . toHaveBeenCalledTimes ( 1 ) ;
158- const scrollParams = scrollBySpy . mock . calls [ 0 ] [ 0 ] as { left : number ; top : number } ;
159- expect ( scrollParams . left ) . toBeCloseTo ( expectedLeft , 1 ) ;
160-
161- scrollBySpy . mockRestore ( ) ;
162- } ) ;
163-
164- it ( 'should scroll to end of day' , async ( ) => {
165- const { scheduler } = await createScheduler ( {
166- views : [ 'timelineWeek' ] ,
167- currentView : 'timelineWeek' ,
168- currentDate : new Date ( 2021 , 1 , 2 ) ,
169- firstDayOfWeek : 0 ,
170- startDayHour : 6 ,
171- endDayHour : 18 ,
172- offset : 120 ,
173- cellDuration : 60 ,
174- height : 580 ,
175- } ) ;
176-
177- const workspace = scheduler . getWorkSpace ( ) ;
178- const scrollable = workspace . getScrollable ( ) ;
179- const $scrollable = scrollable . $element ( ) ;
180- const scrollBySpy = jest . spyOn ( scrollable , 'scrollBy' ) ;
181-
182- // With offset: 720 (12 hours), cells start at 18:00 (6:00 + 12h)
183- // For date 3 feb 04:00, this should be cell index 3 (18:00=0, ... 22:00=35)
184- const leftCellCount = 35 ;
185- const cellWidth = workspace . getCellWidth ( ) ;
186- const scrollableWidth = getWidth ( $scrollable ) ;
187- const expectedLeft = leftCellCount * cellWidth - ( scrollableWidth - cellWidth ) / 2 ;
188-
189- const targetDate = new Date ( 2021 , 1 , 2 , 22 , 0 ) ;
190- scheduler . scrollTo ( targetDate , undefined , false ) ;
191-
192- expect ( scrollBySpy ) . toHaveBeenCalledTimes ( 1 ) ;
193- const scrollParams = scrollBySpy . mock . calls [ 0 ] [ 0 ] as { left : number ; top : number } ;
194- expect ( scrollParams . left ) . toBeCloseTo ( expectedLeft , 1 ) ;
195-
196- scrollBySpy . mockRestore ( ) ;
197- } ) ;
198-
199129 describe ( 'hour normalization' , ( ) => {
200- it ( 'should normalize hours to visible range without viewOffset' , async ( ) => {
201- const { scheduler } = await createScheduler ( {
202- views : [ 'timelineDay' ] ,
203- currentView : 'timelineDay' ,
204- currentDate : new Date ( 2021 , 1 , 2 ) ,
130+ [
131+ // Without offset, normal range
132+ {
205133 startDayHour : 6 ,
206134 endDayHour : 18 ,
207135 offset : 0 ,
208- } ) ;
209-
210- const workspace = scheduler . getWorkSpace ( ) ;
211- const scrollable = workspace . getScrollable ( ) ;
212- const scrollBySpy = jest . spyOn ( scrollable , 'scrollBy' ) ;
213-
214- // Below startDayHour (6), should NOT normalize to 6 (?)
215- const dateBelowRange = new Date ( 2021 , 1 , 2 , 4 , 0 ) ;
216- scheduler . scrollTo ( dateBelowRange , undefined , false ) ;
217- expect ( scrollBySpy ) . not . toHaveBeenCalled ( ) ;
218-
219- scrollBySpy . mockClear ( ) ;
220- // Above endDayHour (18), should NOT normalize to 17 (?)
221- const dateAboveRange = new Date ( 2021 , 1 , 2 , 20 , 0 ) ;
222- scheduler . scrollTo ( dateAboveRange , undefined , false ) ;
223- expect ( scrollBySpy ) . not . toHaveBeenCalled ( ) ;
224-
225- scrollBySpy . mockClear ( ) ;
226- // Within range [6, 18), should scroll normally
227- const dateInRange = new Date ( 2021 , 1 , 2 , 12 , 0 ) ;
228- scheduler . scrollTo ( dateInRange , undefined , false ) ;
229- expect ( scrollBySpy ) . toHaveBeenCalled ( ) ;
230-
231- scrollBySpy . mockRestore ( ) ;
232- } ) ;
233-
234- it ( 'should normalize hours to visible range with viewOffset (no midnight crossing)' , async ( ) => {
235- const { scheduler } = await createScheduler ( {
236- views : [ 'timelineDay' ] ,
237- currentView : 'timelineDay' ,
238- currentDate : new Date ( 2021 , 1 , 2 ) ,
136+ hours : [ 4 , 12 , 20 ] ,
137+ } ,
138+ // With positive offset
139+ {
239140 startDayHour : 6 ,
240141 endDayHour : 18 ,
241142 offset : 360 ,
242- } ) ;
243-
244- const workspace = scheduler . getWorkSpace ( ) ;
245- const scrollable = workspace . getScrollable ( ) ;
246- const scrollBySpy = jest . spyOn ( scrollable , 'scrollBy' ) ;
247-
248- // Below adjustedStartDayHour (12), should NOT normalize to 12 (?)
249- const dateBelowAdjustedRange = new Date ( 2021 , 1 , 2 , 10 , 0 ) ;
250- scheduler . scrollTo ( dateBelowAdjustedRange , undefined , false ) ;
251- expect ( scrollBySpy ) . not . toHaveBeenCalled ( ) ;
252-
253- scrollBySpy . mockClear ( ) ;
254- // Within adjusted range [12, 24), should scroll normally
255- const dateInAdjustedRange = new Date ( 2021 , 1 , 2 , 15 , 0 ) ;
256- scheduler . scrollTo ( dateInAdjustedRange , undefined , false ) ;
257- expect ( scrollBySpy ) . toHaveBeenCalled ( ) ;
258-
259- scrollBySpy . mockRestore ( ) ;
260- } ) ;
261-
262- it ( 'should normalize hours to visible range with viewOffset (midnight crossing)' , async ( ) => {
263- const { scheduler } = await createScheduler ( {
264- views : [ 'timelineDay' ] ,
265- currentView : 'timelineDay' ,
266- currentDate : new Date ( 2021 , 1 , 2 ) ,
143+ hours : [ 10 , 15 , 22 ] ,
144+ } ,
145+ // With negative offset
146+ {
147+ startDayHour : 6 ,
148+ endDayHour : 18 ,
149+ offset : - 120 ,
150+ hours : [ 3 , 10 , 20 ] ,
151+ } ,
152+ // With offset creating midnight crossing
153+ {
267154 startDayHour : 6 ,
268155 endDayHour : 18 ,
269156 offset : 720 ,
157+ hours : [ 10 , 22 , 3 ] ,
158+ } ,
159+ // Edge case: startDayHour = 0
160+ {
161+ startDayHour : 0 ,
162+ endDayHour : 12 ,
163+ offset : 0 ,
164+ hours : [ 0 , 6 , 13 ] ,
165+ } ,
166+ // Edge case: endDayHour = 24
167+ {
168+ startDayHour : 12 ,
169+ endDayHour : 24 ,
170+ offset : 0 ,
171+ hours : [ 11 , 18 , 23 ] ,
172+ } ,
173+ ] . forEach ( ( {
174+ startDayHour,
175+ endDayHour,
176+ offset,
177+ hours,
178+ } ) => {
179+ hours . forEach ( ( hour ) => {
180+ const testName = `startDayHour: ${ startDayHour } , `
181+ + `endDayHour: ${ endDayHour } , offset: ${ offset } , `
182+ + `hour: ${ hour } ` ;
183+
184+ it ( testName , async ( ) => {
185+ const { scheduler } = await createScheduler ( {
186+ views : [ 'timelineWeek' ] ,
187+ currentView : 'timelineWeek' ,
188+ currentDate : new Date ( 2021 , 1 , 2 ) ,
189+ startDayHour,
190+ endDayHour,
191+ offset,
192+ } ) ;
193+
194+ const workspace = scheduler . getWorkSpace ( ) ;
195+ const scrollable = workspace . getScrollable ( ) ;
196+ const scrollBySpy = jest . spyOn ( scrollable , 'scrollBy' ) ;
197+ const targetDate = new Date ( 2021 , 1 , 2 , hour , 0 ) ;
198+
199+ scheduler . scrollTo ( targetDate , undefined , false ) ;
200+ const cell = workspace . viewDataProvider . findGlobalCellPosition (
201+ targetDate ,
202+ 0 ,
203+ false ,
204+ true ,
205+ ) ;
206+ const cellStartDate = cell . cellData . startDate ;
207+ const cellEndDate = cell . cellData . endDate ;
208+
209+ expect ( scrollBySpy ) . toHaveBeenCalledTimes ( 1 ) ;
210+ expect ( targetDate . getTime ( ) ) . toBeGreaterThanOrEqual ( cellStartDate . getTime ( ) ) ;
211+ expect ( targetDate . getTime ( ) ) . toBeLessThan ( cellEndDate . getTime ( ) ) ;
212+
213+ scrollBySpy . mockRestore ( ) ;
214+ } ) ;
270215 } ) ;
271-
272- const workspace = scheduler . getWorkSpace ( ) ;
273- const scrollable = workspace . getScrollable ( ) ;
274- const scrollBySpy = jest . spyOn ( scrollable , 'scrollBy' ) ;
275-
276- // In gap [6, 18), should NOT normalize to 18:00 Feb 2 (?)
277- const dateInGap = new Date ( 2021 , 1 , 2 , 10 , 0 ) ;
278- scheduler . scrollTo ( dateInGap , undefined , false ) ;
279- expect ( scrollBySpy ) . not . toHaveBeenCalled ( ) ;
280-
281- scrollBySpy . mockClear ( ) ;
282- // In range [18, 24) on Feb 2, should scroll normally
283- const dateInFirstRange = new Date ( 2021 , 1 , 2 , 22 , 0 ) ;
284- scheduler . scrollTo ( dateInFirstRange , undefined , false ) ;
285- expect ( scrollBySpy ) . toHaveBeenCalled ( ) ;
286-
287- scrollBySpy . mockClear ( ) ;
288- // In range [0, 6) but on wrong day (Feb 2), should NOT normalize to 18:00 Feb 2 (?)
289- const dateInSecondRangeWrongDay = new Date ( 2021 , 1 , 2 , 3 , 0 ) ;
290- scheduler . scrollTo ( dateInSecondRangeWrongDay , undefined , false ) ;
291- expect ( scrollBySpy ) . not . toHaveBeenCalled ( ) ;
292-
293- scrollBySpy . mockClear ( ) ;
294- // In range [0, 6) on correct day (Feb 3), should scroll normally
295- const dateInSecondRangeCorrectDay = new Date ( 2021 , 1 , 3 , 3 , 0 ) ;
296- scheduler . scrollTo ( dateInSecondRangeCorrectDay , undefined , false ) ;
297- expect ( scrollBySpy ) . toHaveBeenCalled ( ) ;
298-
299- scrollBySpy . mockRestore ( ) ;
300216 } ) ;
301217 } ) ;
302218 } ) ;
0 commit comments