Skip to content

Commit f67a376

Browse files
Scheduler — fix scrollTo method ignores single property alignInView (#32886)
1 parent 312da62 commit f67a376

2 files changed

Lines changed: 62 additions & 8 deletions

File tree

packages/devextreme/js/__internal/scheduler/__tests__/scheduler.test.ts

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,47 @@
11
import {
2-
describe, expect, it, jest,
2+
afterEach, beforeEach, describe, expect, it, jest,
33
} from '@jest/globals';
44
import { logger } from '@ts/core/utils/m_console';
55

66
import { createScheduler } from './__mock__/create_scheduler';
77
import { setupSchedulerTestEnvironment } from './__mock__/m_mock_scheduler';
88

9-
describe('Scheduler scrollTo deprecation', () => {
10-
it('should log deprecation warning when using old scrollTo API', async () => {
9+
jest.mock('@ts/core/m_devices', () => {
10+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
11+
const originalModule: any = jest.requireActual('@ts/core/m_devices');
12+
const real = jest.fn().mockReturnValue({
13+
platform: 'mac',
14+
mac: true,
15+
deviceType: 'desktop',
16+
});
17+
const current = jest.fn().mockReturnValue({
18+
platform: 'mac',
19+
mac: true,
20+
deviceType: 'desktop',
21+
});
22+
23+
return {
24+
__esModule: true,
25+
default: {
26+
...originalModule.default,
27+
isSimulator: originalModule.default.isSimulator,
28+
real,
29+
current,
30+
},
31+
};
32+
});
33+
34+
describe('Scheduler scrollTo', () => {
35+
beforeEach(() => {
1136
setupSchedulerTestEnvironment();
37+
jest.spyOn(logger, 'warn').mockImplementation(() => {});
38+
});
39+
40+
afterEach(() => {
41+
document.body.innerHTML = '';
42+
});
43+
44+
it('should log deprecation warning when using scrollTo API with deprecated signature', async () => {
1245
const loggerWarnSpy = jest.spyOn(logger, 'warn');
1346

1447
const { scheduler } = await createScheduler({
@@ -25,9 +58,7 @@ describe('Scheduler scrollTo deprecation', () => {
2558
});
2659
loggerWarnSpy.mockReset();
2760

28-
const testDate = new Date(2025, 0, 16, 14, 0);
29-
30-
scheduler.scrollTo(testDate, undefined, false);
61+
scheduler.scrollTo(new Date(2025, 0, 16, 14, 0), undefined, false);
3162

3263
expect(loggerWarnSpy).toHaveBeenCalledTimes(1);
3364
expect(loggerWarnSpy).toHaveBeenCalledWith(
@@ -59,4 +90,27 @@ describe('Scheduler scrollTo deprecation', () => {
5990

6091
expect(loggerWarnSpy).toHaveBeenCalledTimes(0);
6192
});
93+
94+
it('should pass different left offsets for "start" vs "center" alignInView', async () => {
95+
const { container, scheduler } = await createScheduler({
96+
dataSource: [],
97+
views: ['timelineDay'],
98+
currentView: 'timelineDay',
99+
currentDate: new Date(2017, 4, 25),
100+
});
101+
102+
const scrollableElement = container.querySelector('.dx-scheduler-date-table-scrollable') as HTMLElement;
103+
const scrollableContainer = scrollableElement.querySelector('.dx-scrollable-container') as HTMLElement;
104+
105+
scheduler.scrollTo(new Date(2017, 4, 25, 22, 0), { alignInView: 'start' });
106+
const startScrollLeft = scrollableContainer.scrollLeft;
107+
108+
scrollableContainer.scrollLeft = 0;
109+
110+
scheduler.scrollTo(new Date(2017, 4, 25, 22, 0), { alignInView: 'center' });
111+
const centerScrollLeft = scrollableContainer.scrollLeft;
112+
113+
expect(startScrollLeft).toBeCloseTo(11000);
114+
expect(centerScrollLeft).toBeCloseTo(11125);
115+
});
62116
});

packages/devextreme/js/__internal/scheduler/m_scheduler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,7 +2031,7 @@ class Scheduler extends SchedulerOptionsBaseWidget {
20312031
align = groupValuesOrOptions.alignInView ?? 'center';
20322032
} else {
20332033
if (isDefined(groupValuesOrOptions) || isDefined(allDay)) {
2034-
errors.log('W0002', 'dxScheduler', 'scrollTo', '26.1', 'Use an object with "group", "allDay" and "alignInView" properties instead of separate parameters.');
2034+
errors.log('W0002', 'dxScheduler', 'scrollTo(date, group, allDay)', '26.1', 'Use scrollTo(date, { group, allDay, alignInView }) instead.');
20352035
}
20362036

20372037
groupValues = groupValuesOrOptions;
@@ -2043,7 +2043,7 @@ class Scheduler extends SchedulerOptionsBaseWidget {
20432043

20442044
private _isScrollOptionsObject(options?: ScrollToGroupValuesOrOptions): options is ScrollToOptions {
20452045
return Boolean(options) && typeof options === 'object'
2046-
&& ('align' in options || 'allDay' in options || 'group' in options);
2046+
&& ('alignInView' in options || 'allDay' in options || 'group' in options);
20472047
}
20482048

20492049
private isHorizontalVirtualScrolling() {

0 commit comments

Comments
 (0)