UNPKG

devextreme

Version:

HTML5 JavaScript Component Suite for Responsive Web Development

149 lines (148 loc) • 6.1 kB
/** * DevExtreme (esm/__internal/scheduler/__tests__/__mock__/model/scheduler.js) * Version: 25.2.3 * Build date: Fri Dec 12 2025 * * Copyright (c) 2012 - 2025 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ import { ToolbarModel } from "../../../../scheduler/__tests__/__mock__/model/toolbar"; import { APPOINTMENT_POPUP_CLASS } from "../../../appointment_popup/m_popup"; import { POPUP_DIALOG_CLASS } from "../../../m_scheduler"; import { createAppointmentModel } from "./appointment"; import { PopupModel } from "./popup"; 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 } get popup() { return this.getPopup() } get toolbar() { return new ToolbarModel(this.container.querySelector(".dx-scheduler-header")) } getStatusContent() { var _this$container$query; return (null === (_this$container$query = this.container.querySelector(".dx-scheduler-a11y-status-container")) || void 0 === _this$container$query ? void 0 : _this$container$query.textContent) ?? "" } getAppointment(text) { if (!text) { return createAppointmentModel(this.container.querySelector(".dx-scheduler-appointment")) } return this.getAppointments().find((appointment => appointment.getText() === text)) ?? createAppointmentModel(null) } getAppointments() { return [...this.container.querySelectorAll(".dx-scheduler-appointment")].map((element => createAppointmentModel(element))) } getCollectorTexts() { const collectors = this.container.querySelectorAll(".dx-scheduler-appointment-collector"); return getTexts(collectors) } 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 } 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 } 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 };