Skip to content

Commit ab74118

Browse files
Scheduler - Migrate popup state and editor tests to isolated environment (#33670)
1 parent 4c36e27 commit ab74118

3 files changed

Lines changed: 223 additions & 314 deletions

File tree

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

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import $ from '@js/core/renderer';
44
// eslint-disable-next-line devextreme-custom/no-deferred
55
import { Deferred } from '@js/core/utils/deferred';
66

7-
import { mockTimeZoneCalculator } from '../../__mock__/timezone_calculator.mock';
87
import { AppointmentForm } from '../../appointment_popup/form';
98
import {
109
APPOINTMENT_POPUP_CLASS,
1110
AppointmentPopup,
1211
} from '../../appointment_popup/popup';
12+
import { createTimeZoneCalculator } from '../../r1/timezone_calculator/utils';
1313
import {
1414
AppointmentDataAccessor,
1515
} from '../../utils/data_accessor/appointment_data_accessor';
@@ -41,6 +41,8 @@ const DEFAULT_EDITING = {
4141
allowDragging: true,
4242
};
4343

44+
const NO_TIMEZONE = '';
45+
4446
const DEFAULT_APPOINTMENT = {
4547
text: 'Test Appointment',
4648
startDate: new Date(2021, 3, 26, 9, 30),
@@ -61,6 +63,7 @@ interface CreateAppointmentPopupOptions {
6163
editing?: Record<string, unknown>;
6264
firstDayOfWeek?: number;
6365
startDayHour?: number;
66+
timeZone?: string;
6467
onAppointmentFormOpening?: (...args: unknown[]) => void;
6568
onSave?: jest.Mock<(appointment: Record<string, unknown>) => PromiseLike<unknown>>;
6669
title?: string;
@@ -104,7 +107,7 @@ export const createAppointmentPopup = async (
104107

105108
const dataAccessors = new AppointmentDataAccessor(DEFAULT_FIELDS, false);
106109
const resourceManager = new ResourceManager([]);
107-
const timeZoneCalculator = mockTimeZoneCalculator;
110+
const timeZoneCalculator = createTimeZoneCalculator(options.timeZone ?? NO_TIMEZONE);
108111
const editing = { ...DEFAULT_EDITING, ...options.editing };
109112

110113
const addAppointment = options.addAppointment
@@ -163,21 +166,24 @@ export const createAppointmentPopup = async (
163166
const title = options.title ?? 'New Appointment';
164167
const readOnly = options.readOnly ?? false;
165168

166-
popup.show(appointmentData, { onSave, title, readOnly });
167-
await new Promise(process.nextTick);
169+
const overlaySelector = `.dx-overlay-wrapper.${APPOINTMENT_POPUP_CLASS}`;
170+
171+
const showAndQuery = async (
172+
data: Record<string, unknown>,
173+
): Promise<PopupModel> => {
174+
popup.show(data, { onSave, title, readOnly });
175+
await new Promise(process.nextTick);
168176

169-
const selector = `.dx-overlay-wrapper.${APPOINTMENT_POPUP_CLASS}`;
170-
const overlayWrapper = document.querySelector(
171-
selector,
172-
) as HTMLDivElement;
177+
const wrapper = document.querySelector(overlaySelector) as HTMLDivElement;
173178

174-
if (!overlayWrapper) {
175-
throw new Error(
176-
'AppointmentPopup overlay wrapper not found in DOM',
177-
);
178-
}
179+
if (!wrapper) {
180+
throw new Error('AppointmentPopup overlay wrapper not found in DOM');
181+
}
182+
183+
return new PopupModel(wrapper);
184+
};
179185

180-
const POM = new PopupModel(overlayWrapper);
186+
const POM = await showAndQuery(appointmentData);
181187

182188
const dispose = (): void => {
183189
popup.dispose();

0 commit comments

Comments
 (0)