11import {
2- describe , expect , it , jest ,
2+ beforeAll , beforeEach , describe , expect , it , jest ,
33} from '@jest/globals' ;
4+ import { logger } from '@ts/core/utils/m_console' ;
45
56import { getResourceManagerMock } from '../__mock__/resource_manager.mock' ;
67import SchedulerTimelineDay from '../workspaces/m_timeline_day' ;
@@ -12,13 +13,38 @@ import SchedulerWorkSpaceDay from '../workspaces/m_work_space_day';
1213import SchedulerWorkSpaceMonth from '../workspaces/m_work_space_month' ;
1314import SchedulerWorkSpaceWeek from '../workspaces/m_work_space_week' ;
1415import SchedulerWorkSpaceWorkWeek from '../workspaces/m_work_space_work_week' ;
16+ import { setupSchedulerTestEnvironment } from './__mock__/m_mock_scheduler' ;
17+
18+ jest . mock ( '@ts/core/m_devices' , ( ) => {
19+ const originalModule : any = jest . requireActual ( '@ts/core/m_devices' ) ;
20+ const real = jest . fn ( ) . mockReturnValue ( {
21+ platform : 'mac' ,
22+ mac : true ,
23+ deviceType : 'desktop' ,
24+ } ) ;
25+ const current = jest . fn ( ) . mockReturnValue ( {
26+ platform : 'mac' ,
27+ mac : true ,
28+ deviceType : 'desktop' ,
29+ } ) ;
30+
31+ return {
32+ __esModule : true ,
33+ default : {
34+ ...originalModule . default ,
35+ isSimulator : originalModule . default . isSimulator ,
36+ real,
37+ current,
38+ } ,
39+ } ;
40+ } ) ;
1541
1642type WorkspaceConstructor < T > = new ( container : Element , options ?: any ) => T ;
1743
1844const createWorkspace = < T extends SchedulerWorkSpace > (
1945 WorkSpace : WorkspaceConstructor < T > ,
2046 currentView : string ,
21- ) : T => {
47+ ) : { workspace : T ; container : Element } => {
2248 const container = document . createElement ( 'div' ) ;
2349 const workspace = new WorkSpace ( container , {
2450 views : [ currentView ] ,
@@ -30,8 +56,9 @@ const createWorkspace = <T extends SchedulerWorkSpace>(
3056 ( workspace as any ) . _isVisible = ( ) => true ;
3157 expect ( container . classList ) . toContain ( 'dx-scheduler-work-space' ) ;
3258
33- return workspace ;
59+ return { workspace, container } ;
3460} ;
61+
3562const workSpaces : {
3663 currentView : string ;
3764 WorkSpace : WorkspaceConstructor < SchedulerWorkSpace > ;
@@ -46,10 +73,14 @@ const workSpaces: {
4673 { currentView : 'timelineMonth' , WorkSpace : SchedulerTimelineMonth } ,
4774] ;
4875
76+ beforeAll ( ( ) => {
77+ setupSchedulerTestEnvironment ( ) ;
78+ } ) ;
79+
4980describe ( 'scheduler workspace' , ( ) => {
5081 workSpaces . forEach ( ( { currentView, WorkSpace } ) => {
5182 it ( `should clear cache on dimension change, view: ${ currentView } ` , ( ) => {
52- const workspace = createWorkspace ( WorkSpace , currentView ) ;
83+ const { workspace } = createWorkspace ( WorkSpace , currentView ) ;
5384 jest . spyOn ( workspace . cache , 'clear' ) ;
5485
5586 workspace . cache . memo ( 'test' , ( ) => 'value' ) ;
@@ -59,7 +90,7 @@ describe('scheduler workspace', () => {
5990 } ) ;
6091
6192 it ( `should clear cache on _cleanView call, view: ${ currentView } ` , ( ) => {
62- const workspace = createWorkspace ( WorkSpace , currentView ) ;
93+ const { workspace } = createWorkspace ( WorkSpace , currentView ) ;
6394 jest . spyOn ( workspace . cache , 'clear' ) ;
6495
6596 workspace . cache . memo ( 'test' , ( ) => 'value' ) ;
@@ -70,3 +101,95 @@ describe('scheduler workspace', () => {
70101 } ) ;
71102 } ) ;
72103} ) ;
104+
105+ describe ( 'scheduler workspace scrollTo' , ( ) => {
106+ beforeEach ( ( ) => {
107+ setupSchedulerTestEnvironment ( ) ;
108+ } ) ;
109+
110+ it ( 'should change scroll position with center alignment' , ( ) => {
111+ const { workspace, container } = createWorkspace ( SchedulerTimelineDay , 'timelineDay' ) ;
112+
113+ const scrollableElement = container . querySelector ( '.dx-scheduler-date-table-scrollable' ) as HTMLElement ;
114+ const scrollableContainer = scrollableElement . querySelector ( '.dx-scrollable-container' ) as HTMLElement ;
115+
116+ workspace . scrollTo ( new Date ( 2017 , 4 , 25 , 22 , 0 ) ) ;
117+
118+ expect ( scrollableContainer . scrollLeft ) . toBeCloseTo ( 11125 ) ;
119+ } ) ;
120+
121+ it ( 'should not change scroll position when date is outside view range' , ( ) => {
122+ const { workspace, container } = createWorkspace ( SchedulerTimelineDay , 'timelineDay' ) ;
123+
124+ const scrollableElement = container . querySelector ( '.dx-scheduler-date-table-scrollable' ) as HTMLElement ;
125+ const scrollableContainer = scrollableElement . querySelector ( '.dx-scrollable-container' ) as HTMLElement ;
126+
127+ workspace . scrollTo ( new Date ( 2030 , 0 , 1 ) ) ;
128+
129+ expect ( scrollableContainer . scrollLeft ) . toBeCloseTo ( 0 ) ;
130+ expect ( scrollableContainer . scrollTop ) . toBeCloseTo ( 0 ) ;
131+ } ) ;
132+
133+ it ( 'should scroll with start alignment' , ( ) => {
134+ const { workspace, container } = createWorkspace ( SchedulerTimelineDay , 'timelineDay' ) ;
135+
136+ const scrollableElement = container . querySelector ( '.dx-scheduler-date-table-scrollable' ) as HTMLElement ;
137+ const scrollableContainer = scrollableElement . querySelector ( '.dx-scrollable-container' ) as HTMLElement ;
138+
139+ workspace . scrollTo ( new Date ( 2017 , 4 , 25 , 22 , 0 ) , undefined , false , true , 'start' ) ;
140+
141+ expect ( scrollableContainer . scrollLeft ) . toBeCloseTo ( 11000 ) ;
142+ expect ( scrollableContainer . scrollTop ) . toBeCloseTo ( 0 ) ;
143+ } ) ;
144+
145+ it ( 'should scroll with center alignment' , ( ) => {
146+ const { workspace, container } = createWorkspace ( SchedulerTimelineDay , 'timelineDay' ) ;
147+
148+ const scrollableElement = container . querySelector ( '.dx-scheduler-date-table-scrollable' ) as HTMLElement ;
149+ const scrollableContainer = scrollableElement . querySelector ( '.dx-scrollable-container' ) as HTMLElement ;
150+
151+ workspace . scrollTo ( new Date ( 2017 , 4 , 25 , 22 , 0 ) , undefined , false , true , 'center' ) ;
152+
153+ expect ( scrollableContainer . scrollLeft ) . toBeCloseTo ( 11125 ) ;
154+ } ) ;
155+
156+ it ( 'should scroll to all day panel when allDay is true' , ( ) => {
157+ const { workspace, container } = createWorkspace ( SchedulerTimelineDay , 'timelineDay' ) ;
158+
159+ const scrollableElement = container . querySelector ( '.dx-scheduler-date-table-scrollable' ) as HTMLElement ;
160+ const scrollableContainer = scrollableElement . querySelector ( '.dx-scrollable-container' ) as HTMLElement ;
161+
162+ workspace . scrollTo ( new Date ( 2017 , 4 , 25 , 22 , 0 ) , undefined , true ) ;
163+
164+ expect ( scrollableContainer . scrollLeft ) . toBeCloseTo ( 11125 ) ;
165+ } ) ;
166+
167+ it ( 'should handle throwWarning parameter correctly' , ( ) => {
168+ const loggerWarnSpy = jest . spyOn ( logger , 'warn' ) ;
169+ loggerWarnSpy . mockReset ( ) ;
170+
171+ const { workspace, container } = createWorkspace ( SchedulerTimelineDay , 'timelineDay' ) ;
172+
173+ const scrollableElement = container . querySelector ( '.dx-scheduler-date-table-scrollable' ) as HTMLElement ;
174+ const scrollableContainer = scrollableElement . querySelector ( '.dx-scrollable-container' ) as HTMLElement ;
175+
176+ workspace . scrollTo ( new Date ( 2030 , 0 , 1 ) , undefined , false , true ) ;
177+
178+ expect ( scrollableContainer . scrollLeft ) . toBe ( 0 ) ;
179+ expect ( scrollableContainer . scrollTop ) . toBe ( 0 ) ;
180+ expect ( loggerWarnSpy ) . toHaveBeenCalledTimes ( 1 ) ;
181+ expect ( loggerWarnSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( 'W1008' ) ) ;
182+ } ) ;
183+
184+ it ( 'should apply RTL offset when rtlEnabled is true' , ( ) => {
185+ const { workspace, container } = createWorkspace ( SchedulerTimelineDay , 'timelineDay' ) ;
186+ workspace . option ( 'rtlEnabled' , true ) ;
187+
188+ const scrollableElement = container . querySelector ( '.dx-scheduler-date-table-scrollable' ) as HTMLElement ;
189+ const scrollableContainer = scrollableElement . querySelector ( '.dx-scrollable-container' ) as HTMLElement ;
190+
191+ workspace . scrollTo ( new Date ( 2017 , 4 , 25 , 22 , 0 ) ) ;
192+
193+ expect ( scrollableContainer . scrollLeft ) . toBeCloseTo ( - 11125 ) ;
194+ } ) ;
195+ } ) ;
0 commit comments