devextreme
Version:
JavaScript/TypeScript Component Suite for Responsive Web Development
187 lines (186 loc) • 7.68 kB
JavaScript
/**
* DevExtreme (esm/__internal/scheduler/__tests__/__mock__/model/scheduler.js)
* Version: 25.2.8
* Build date: Mon Jun 08 2026
*
* Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
import {
within
} from "@testing-library/dom";
import {
ToolbarModel
} from "../../../../scheduler/__tests__/__mock__/model/toolbar";
import {
APPOINTMENT_POPUP_CLASS
} from "../../../appointment_popup/popup";
import {
POPUP_DIALOG_CLASS
} from "../../../m_scheduler";
import {
createAppointmentModel
} from "./appointment";
import {
PopupModel
} from "./popup";
import {
TooltipModel
} from "./tooltip";
const getTexts = cells => Array.from(cells).map(cell => {
var _cell$textContent;
return (null === (_cell$textContent = cell.textContent) || void 0 === _cell$textContent ? void 0 : _cell$textContent.trim()) ?? ""
});
export class SchedulerModel {
constructor(container) {
this.getPopups = () => document.querySelectorAll(`.dx-overlay-wrapper.${APPOINTMENT_POPUP_CLASS}, .dx-overlay-wrapper.${POPUP_DIALOG_CLASS}`);
this.getLoadPanel = () => document.querySelector(".dx-loadpanel");
this.getTooltipAppointment = () => document.querySelector(".dx-tooltip-appointment-item");
this.container = container;
this.queries = within(container)
}
get popup() {
return this.getPopup()
}
get tooltip() {
return new TooltipModel
}
get toolbar() {
return new ToolbarModel(this.queries.getByRole("toolbar"))
}
getStatusContent() {
const statusElement = this.container.querySelector(".dx-scheduler-a11y-status-container");
return (null === statusElement || void 0 === statusElement ? void 0 : statusElement.textContent) ?? ""
}
getAppointment(text) {
if (!text) {
const appointments = this.getAppointments();
return appointments.length > 0 ? appointments[0] : createAppointmentModel(null)
}
return this.getAppointments().find(appointment => appointment.getText() === text) ?? createAppointmentModel(null)
}
getAppointments() {
const allButtons = this.queries.queryAllByRole("button");
const appointments = allButtons.filter(btn => btn.classList.contains("dx-scheduler-appointment"));
return appointments.map(element => createAppointmentModel(element))
}
getDraggedAppointment() {
const draggableContainer = this.container.querySelector(".dx-scheduler-draggable-container");
const dragClone = null === draggableContainer || void 0 === draggableContainer ? void 0 : draggableContainer.querySelector(".dx-scheduler-appointment");
return dragClone ? createAppointmentModel(dragClone) : null
}
getCollectorTexts() {
const allButtons = this.queries.queryAllByRole("button");
const collectors = allButtons.filter(btn => btn.classList.contains("dx-scheduler-appointment-collector"));
return getTexts(collectors)
}
getCollectorButton() {
let index = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 0;
const allButtons = this.queries.queryAllByRole("button");
const collectors = allButtons.filter(btn => btn.classList.contains("dx-scheduler-appointment-collector"));
if (0 === collectors.length) {
throw new Error("Collector button not found")
}
return collectors[index]
}
getDateTableContent() {
const cells = this.container.querySelectorAll(".dx-scheduler-date-table-cell");
return getTexts(cells)
}
getDateTableCell() {
let rowIndex = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 0;
let cellIndex = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 0;
const rowSelector = `.dx-scheduler-date-table-row:nth-child(${rowIndex+1})`;
const cellSelector = `.dx-scheduler-date-table-cell:nth-child(${cellIndex+1})`;
const selector = `${rowSelector} ${cellSelector}`;
const result = this.container.querySelector(selector);
if (!result) {
throw new Error(`Date cell in row ${rowIndex} and column ${cellIndex} not found`)
}
return result
}
getAllDayTableCell() {
let cellIndex = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 0;
const cellSelector = `.dx-scheduler-all-day-table-cell:nth-child(${cellIndex+1})`;
const result = this.container.querySelector(cellSelector);
if (!result) {
throw new Error(`All-day cell in column ${cellIndex} not found`)
}
return result
}
getWorkspace() {
const result = this.container.querySelector(".dx-scheduler-work-space");
if (!result) {
throw new Error("Workspace not found")
}
return result
}
getHeaderPanelContent() {
const cells = this.container.querySelectorAll(".dx-scheduler-header-panel-cell");
return getTexts(cells)
}
getTimePanelContent() {
const cells = this.container.querySelectorAll(".dx-scheduler-time-panel-cell");
return getTexts(cells)
}
getGroupTableContent() {
const cells = this.container.querySelectorAll(".dx-scheduler-group-header");
return getTexts(cells)
}
getPopup() {
const elements = this.getPopups();
if (0 === elements.length) {
throw new Error("Popup is not rendered")
}
const popupElement = elements[0];
return new PopupModel(popupElement)
}
isPopupVisible() {
return this.getPopups().length > 0
}
isRecurrenceDialogVisible() {
return !!document.querySelector(`.dx-overlay-wrapper.${POPUP_DIALOG_CLASS}`)
}
openPopupByDblClick(text) {
const appointment = this.getAppointment(text);
if (!(null !== appointment && void 0 !== appointment && appointment.element)) {
throw new Error(`Appointment "${text}" not found`)
}
appointment.element.click();
appointment.element.click();
return appointment
}
dblClickDateTableCell() {
let rowIndex = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 0;
let cellIndex = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 0;
const cellElement = this.getDateTableCell(rowIndex, cellIndex);
cellElement.dispatchEvent(new MouseEvent("mousedown", {
bubbles: true,
cancelable: true
}));
cellElement.click();
cellElement.dispatchEvent(new MouseEvent("mousedown", {
bubbles: true,
cancelable: true
}));
cellElement.click()
}
dblClickAllDayTableCell() {
let cellIndex = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 0;
const cellElement = this.getAllDayTableCell(cellIndex);
cellElement.dispatchEvent(new MouseEvent("mousedown", {
bubbles: true,
cancelable: true
}));
cellElement.click();
cellElement.dispatchEvent(new MouseEvent("mousedown", {
bubbles: true,
cancelable: true
}));
cellElement.click()
}
}
export const createSchedulerModel = container => {
const model = new SchedulerModel(container);
return model
};