Skip to content

Commit a95e0d5

Browse files
Scheduler New Form — Improve animation offset test: use classRects in setupSchedulerTestEnvironment
1 parent 1d6872f commit a95e0d5

2 files changed

Lines changed: 24 additions & 26 deletions

File tree

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

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ import DOMComponent from '@ts/core/widget/dom_component';
44

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

7+
type ClassRects = Record<string, Partial<DOMRect>>;
8+
79
interface SetupSchedulerTestEnvironmentOptions {
810
width?: number;
911
height?: number;
12+
classRects?: ClassRects;
1013
}
1114

1215
export const DEFAULT_CELL_WIDTH = 250;
@@ -16,6 +19,7 @@ export const DEFAULT_TIMELINE_CELL_HEIGHT = 450;
1619
export const setupSchedulerTestEnvironment = ({
1720
width = DEFAULT_CELL_WIDTH,
1821
height = DEFAULT_CELL_HEIGHT,
22+
classRects = {},
1923
}: SetupSchedulerTestEnvironmentOptions = {}): void => {
2024
jest.spyOn(logger, 'warn').mockImplementation(() => {});
2125
DOMComponent.prototype._isVisible = jest.fn((): boolean => true);
@@ -42,8 +46,18 @@ export const setupSchedulerTestEnvironment = ({
4246
return styles;
4347
});
4448

49+
const defaultRect: DOMRect = {
50+
width: 0, height: 0, top: 0, left: 0, bottom: 0, right: 0, x: 0, y: 0, toJSON: (): void => {},
51+
};
52+
4553
Element.prototype.getBoundingClientRect = jest.fn(function (): DOMRect {
4654
const classList: string[] = Array.from(this.classList);
55+
56+
const matchedClass = classList.find((className) => classRects[className]);
57+
if (matchedClass) {
58+
return { ...defaultRect, ...classRects[matchedClass] };
59+
}
60+
4761
switch (true) {
4862
case classList.includes('dx-scheduler-date-table-cell')
4963
|| classList.includes('dx-scheduler-all-day-table-cell'):
@@ -58,30 +72,8 @@ export const setupSchedulerTestEnvironment = ({
5872
y: 0,
5973
toJSON: (): void => {},
6074
};
61-
case classList.includes('dx-scheduler-form-main-group'):
62-
return {
63-
width: 0,
64-
height: 0,
65-
top: 50,
66-
left: 0,
67-
bottom: 50,
68-
right: 0,
69-
x: 0,
70-
y: 50,
71-
toJSON: (): void => {},
72-
};
7375
default:
74-
return {
75-
width: 0,
76-
height: 0,
77-
top: 0,
78-
left: 0,
79-
bottom: 0,
80-
right: 0,
81-
x: 0,
82-
y: 0,
83-
toJSON: (): void => {},
84-
};
76+
return defaultRect;
8577
}
8678
});
8779
};

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,14 +1596,20 @@ describe('Appointment Form', () => {
15961596
});
15971597

15981598
it('should set animation offset CSS variable when switching to recurrence form', async () => {
1599+
setupSchedulerTestEnvironment({
1600+
height: 600,
1601+
classRects: {
1602+
'dx-form': { top: 10 },
1603+
'dx-scheduler-form-main-group': { top: 60 },
1604+
},
1605+
});
1606+
15991607
const { scheduler, POM } = await createScheduler(getDefaultConfig());
16001608

16011609
scheduler.showAppointmentPopup();
1602-
16031610
POM.popup.selectRepeatValue('weekly');
16041611

1605-
const formElement = POM.popup.dxForm.element();
1606-
const animationTop = formElement.style.getPropertyValue('--dx-scheduler-animation-top');
1612+
const animationTop = POM.popup.dxForm.element().style.getPropertyValue('--dx-scheduler-animation-top');
16071613
expect(animationTop).toBe('50px');
16081614
});
16091615
});

0 commit comments

Comments
 (0)