Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import $ from '@js/core/renderer';
// eslint-disable-next-line devextreme-custom/no-deferred
import { Deferred } from '@js/core/utils/deferred';

import { mockTimeZoneCalculator } from '../../__mock__/timezone_calculator.mock';
import { AppointmentForm } from '../../appointment_popup/form';
import {
APPOINTMENT_POPUP_CLASS,
AppointmentPopup,
} from '../../appointment_popup/popup';
import { createTimeZoneCalculator } from '../../r1/timezone_calculator/utils';
import {
AppointmentDataAccessor,
} from '../../utils/data_accessor/appointment_data_accessor';
Expand Down Expand Up @@ -41,6 +41,8 @@ const DEFAULT_EDITING = {
allowDragging: true,
};

const NO_TIMEZONE = '';

const DEFAULT_APPOINTMENT = {
text: 'Test Appointment',
startDate: new Date(2021, 3, 26, 9, 30),
Expand All @@ -61,6 +63,7 @@ interface CreateAppointmentPopupOptions {
editing?: Record<string, unknown>;
firstDayOfWeek?: number;
startDayHour?: number;
timeZone?: string;
onAppointmentFormOpening?: (...args: unknown[]) => void;
onSave?: jest.Mock<(appointment: Record<string, unknown>) => PromiseLike<unknown>>;
title?: string;
Expand Down Expand Up @@ -104,7 +107,7 @@ export const createAppointmentPopup = async (

const dataAccessors = new AppointmentDataAccessor(DEFAULT_FIELDS, false);
const resourceManager = new ResourceManager([]);
const timeZoneCalculator = mockTimeZoneCalculator;
const timeZoneCalculator = createTimeZoneCalculator(options.timeZone ?? NO_TIMEZONE);
const editing = { ...DEFAULT_EDITING, ...options.editing };

const addAppointment = options.addAppointment
Expand Down Expand Up @@ -163,21 +166,24 @@ export const createAppointmentPopup = async (
const title = options.title ?? 'New Appointment';
const readOnly = options.readOnly ?? false;

popup.show(appointmentData, { onSave, title, readOnly });
await new Promise(process.nextTick);
const overlaySelector = `.dx-overlay-wrapper.${APPOINTMENT_POPUP_CLASS}`;

const showAndQuery = async (
data: Record<string, unknown>,
): Promise<PopupModel> => {
popup.show(data, { onSave, title, readOnly });
await new Promise(process.nextTick);

const selector = `.dx-overlay-wrapper.${APPOINTMENT_POPUP_CLASS}`;
const overlayWrapper = document.querySelector(
selector,
) as HTMLDivElement;
const wrapper = document.querySelector(overlaySelector) as HTMLDivElement;

if (!overlayWrapper) {
throw new Error(
'AppointmentPopup overlay wrapper not found in DOM',
);
}
if (!wrapper) {
throw new Error('AppointmentPopup overlay wrapper not found in DOM');
}

return new PopupModel(wrapper);
};

const POM = new PopupModel(overlayWrapper);
const POM = await showAndQuery(appointmentData);

const dispose = (): void => {
popup.dispose();
Expand Down
Loading
Loading