Skip to content

Commit 65b80bf

Browse files
aleksei-semikozovAleksei Semikozov
andauthored
Scheduler: fix all-day appointment rendered in the next resource (DevExpress#30771)
Co-authored-by: Aleksei Semikozov <[email protected]>
1 parent 549551a commit 65b80bf

File tree

4 files changed

+58
-15
lines changed

4 files changed

+58
-15
lines changed

packages/devextreme/js/__internal/scheduler/__tests__/__mock__/m_mock_scheduler.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,36 @@ import DOMComponent from '@ts/core/widget/dom_component';
33

44
import SchedulerWorkSpace from '../../workspaces/m_work_space';
55

6-
export const setupSchedulerTestEnvironment = (
7-
isTimelineView = false,
8-
): void => {
9-
const cellWidth = 250;
10-
const cellHeight = isTimelineView ? 450 : 80;
6+
interface SetupSchedulerTestEnvironmentOptions {
7+
width?: number;
8+
height?: number;
9+
}
1110

12-
(DOMComponent.prototype as any)._isVisible = jest.fn().mockReturnValue(true);
13-
SchedulerWorkSpace.prototype._createCrossScrollingConfig = () => ({
11+
export const DEFAULT_CELL_WIDTH = 250;
12+
export const DEFAULT_CELL_HEIGHT = 80;
13+
export const DEFAULT_TIMELINE_CELL_HEIGHT = 450;
14+
15+
export const setupSchedulerTestEnvironment = ({
16+
width = DEFAULT_CELL_WIDTH,
17+
height = DEFAULT_CELL_HEIGHT,
18+
}: SetupSchedulerTestEnvironmentOptions = {}): void => {
19+
DOMComponent.prototype._isVisible = jest.fn((): boolean => true);
20+
SchedulerWorkSpace.prototype._createCrossScrollingConfig = (): {
21+
direction: string;
22+
onScroll: jest.Mock;
23+
onEnd: jest.Mock;
24+
} => ({
1425
direction: 'both',
1526
onScroll: jest.fn(),
1627
onEnd: jest.fn(),
1728
});
18-
Element.prototype.getBoundingClientRect = jest.fn(() => ({
19-
width: cellWidth,
20-
height: cellHeight,
29+
Element.prototype.getBoundingClientRect = jest.fn((): DOMRect => ({
30+
width,
31+
height,
2132
top: 0,
2233
left: 0,
23-
bottom: cellHeight,
24-
right: cellWidth,
34+
bottom: height,
35+
right: width,
2536
x: 0,
2637
y: 0,
2738
toJSON: (): void => {},

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from '@jest/globals';
88

99
import { createScheduler } from './__mock__/create_scheduler';
10-
import { setupSchedulerTestEnvironment } from './__mock__/m_mock_scheduler';
10+
import { DEFAULT_TIMELINE_CELL_HEIGHT, setupSchedulerTestEnvironment } from './__mock__/m_mock_scheduler';
1111

1212
const dataSource = [
1313
{
@@ -98,7 +98,7 @@ const views = [
9898

9999
describe('scheduler', () => {
100100
it.each(views)('should render correct workspace in Santiago DST for view: $view.name', async ({ view, result }) => {
101-
setupSchedulerTestEnvironment(true);
101+
setupSchedulerTestEnvironment({ height: DEFAULT_TIMELINE_CELL_HEIGHT });
102102

103103
const { POM } = await createScheduler({
104104
views: [view],

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,36 @@ describe('views', () => {
3737
const appointment = POM.getAppointment();
3838
expect(appointment !== null).toBe(true);
3939
});
40+
41+
it('should render all-day appointment correctly with fractional cell values', async () => {
42+
const FRACTIONAL_CELL_WIDTH = 250.4;
43+
setupSchedulerTestEnvironment({ width: FRACTIONAL_CELL_WIDTH });
44+
const { container } = await createScheduler({
45+
dataSource: [{
46+
text: 'Appointment 2',
47+
startDate: new Date('2021-02-02T15:15:00.000Z'),
48+
endDate: new Date('2021-02-02T17:45:00.000Z'),
49+
allDay: true,
50+
resourceId: 1,
51+
}],
52+
currentDate: new Date(2021, 1, 2),
53+
startDayHour: 8,
54+
endDayHour: 20,
55+
allDayPanelMode: 'hidden',
56+
groups: ['resourceId'],
57+
resources: [{
58+
label: 'User',
59+
dataSource: [
60+
{ title: 'Mark', id: 1 },
61+
{ title: 'Luke', id: 2 },
62+
],
63+
displayExpr: 'title',
64+
fieldExpr: 'resourceId',
65+
valueExpr: 'id',
66+
}],
67+
});
68+
69+
const appointments = container.querySelectorAll('.dx-item.dx-scheduler-appointment');
70+
expect(appointments.length).toBe(1);
71+
});
4072
});

packages/devextreme/js/__internal/scheduler/view_model/generate_view_model/rendering_strategies/m_strategy_vertical.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ class VerticalRenderingStrategy extends BaseAppointmentsStrategy {
216216
let tailHeight = this._getTailHeight(appointmentGeometry, appointmentSettings);
217217
let { columnIndex } = appointmentSettings;
218218

219-
while (tailHeight > 0 && left < hMax) {
219+
while (tailHeight > 0 && left < Math.round(hMax)) {
220220
tailHeight = Math.max(minHeight, tailHeight);
221221
columnIndex += cellsDiff;
222222
const height = Math.min(tailHeight, maxHeight);

0 commit comments

Comments
 (0)