devextreme
Version:
JavaScript/TypeScript Component Suite for Responsive Web Development
155 lines (153 loc) • 6.53 kB
JavaScript
/**
* DevExtreme (cjs/__internal/scheduler/appointment_popup/appointment_popup.test.js)
* Version: 25.2.7
* Build date: Tue May 05 2026
*
* Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
"use strict";
var _globals = require("@jest/globals");
var _fx = _interopRequireDefault(require("../../../common/core/animation/fx"));
var _create_appointment_popup = require("../__tests__/__mock__/create_appointment_popup");
function _interopRequireDefault(e) {
return e && e.__esModule ? e : {
default: e
}
}(0, _globals.describe)("Isolated AppointmentPopup environment", () => {
(0, _globals.beforeEach)(() => {
_fx.default.off = true
});
(0, _globals.afterEach)(() => {
(0, _create_appointment_popup.disposeAppointmentPopups)();
_fx.default.off = false
});
(0, _globals.it)("should render popup with form fields", async () => {
const {
POM: POM
} = await (0, _create_appointment_popup.createAppointmentPopup)();
(0, _globals.expect)(POM.element).toBeTruthy();
(0, _globals.expect)(POM.dxForm).toBeTruthy()
});
(0, _globals.it)("should display appointment data in form", async () => {
const {
POM: POM
} = await (0, _create_appointment_popup.createAppointmentPopup)({
appointmentData: {
text: "My Meeting",
startDate: new Date(2021, 3, 26, 9, 30),
endDate: new Date(2021, 3, 26, 11, 0)
}
});
(0, _globals.expect)(POM.getInputValue("subjectEditor")).toBe("My Meeting")
});
(0, _globals.it)("should have Save and Cancel buttons", async () => {
const {
POM: POM
} = await (0, _create_appointment_popup.createAppointmentPopup)();
(0, _globals.expect)(POM.saveButton).toBeTruthy();
(0, _globals.expect)(POM.cancelButton).toBeTruthy()
});
(0, _globals.it)("should call onSave callback on Save click", async () => {
const {
POM: POM,
callbacks: callbacks
} = await (0, _create_appointment_popup.createAppointmentPopup)({
appointmentData: {
text: "New Appointment",
startDate: new Date(2021, 3, 26, 9, 30),
endDate: new Date(2021, 3, 26, 11, 0)
}
});
POM.saveButton.click();
(0, _globals.expect)(callbacks.onSave).toHaveBeenCalledTimes(1);
(0, _globals.expect)(callbacks.onSave).toHaveBeenCalledWith(_globals.expect.objectContaining({
text: "New Appointment",
startDate: new Date(2021, 3, 26, 9, 30),
endDate: new Date(2021, 3, 26, 11, 0)
}))
});
(0, _globals.it)("should not call addAppointment or updateAppointment directly", async () => {
const {
POM: POM,
callbacks: callbacks
} = await (0, _create_appointment_popup.createAppointmentPopup)({
appointmentData: {
text: "Test",
startDate: new Date(2021, 3, 26, 9, 30),
endDate: new Date(2021, 3, 26, 11, 0)
}
});
POM.saveButton.click();
(0, _globals.expect)(callbacks.addAppointment).not.toHaveBeenCalled();
(0, _globals.expect)(callbacks.updateAppointment).not.toHaveBeenCalled()
});
(0, _globals.it)("should display title from config", async () => {
const {
POM: POM
} = await (0, _create_appointment_popup.createAppointmentPopup)({
title: "Edit Appointment"
});
const titleElement = POM.element.querySelector(".dx-toolbar-label");
(0, _globals.expect)(null === titleElement || void 0 === titleElement ? void 0 : titleElement.textContent).toBe("Edit Appointment")
});
(0, _globals.it)("should hide Save button when readOnly is true", async () => {
const {
POM: POM
} = await (0, _create_appointment_popup.createAppointmentPopup)({
readOnly: true
});
const saveButtons = POM.element.querySelectorAll(".dx-popup-done");
(0, _globals.expect)(saveButtons.length).toBe(0)
});
(0, _globals.it)("should show Save button when readOnly is false", async () => {
const {
POM: POM
} = await (0, _create_appointment_popup.createAppointmentPopup)({
readOnly: false
});
(0, _globals.expect)(POM.saveButton).toBeTruthy()
});
(0, _globals.it)("should hide popup on Cancel click", async () => {
const {
popup: popup,
POM: POM
} = await (0, _create_appointment_popup.createAppointmentPopup)();
(0, _globals.expect)(popup.visible).toBe(true);
POM.cancelButton.click();
(0, _globals.expect)(popup.visible).toBe(false)
});
(0, _globals.it)("should support composite onSave for exclude-from-series scenario", async () => {
const updateAppointment = _globals.jest.fn();
const addAppointment = _globals.jest.fn(() => Promise.resolve());
const sourceAppointment = {
text: "Series",
recurrenceRule: "FREQ=DAILY"
};
const updatedAppointment = {
text: "Series",
recurrenceException: "20210426"
};
const onSave = _globals.jest.fn(newAppointment => {
updateAppointment(sourceAppointment, updatedAppointment);
return addAppointment(newAppointment)
});
const {
POM: POM
} = await (0, _create_appointment_popup.createAppointmentPopup)({
appointmentData: {
text: "Single occurrence",
startDate: new Date(2021, 3, 26, 9, 30),
endDate: new Date(2021, 3, 26, 11, 0)
},
title: "Edit Appointment",
onSave: onSave
});
POM.saveButton.click();
(0, _globals.expect)(onSave).toHaveBeenCalledTimes(1);
(0, _globals.expect)(updateAppointment).toHaveBeenCalledWith(sourceAppointment, updatedAppointment);
(0, _globals.expect)(addAppointment).toHaveBeenCalledWith(_globals.expect.objectContaining({
text: "Single occurrence"
}))
})
});