devextreme
Version:
JavaScript/TypeScript Component Suite for Responsive Web Development
180 lines (179 loc) • 7.96 kB
JavaScript
/**
* DevExtreme (cjs/__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/
*/
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createSchedulerModel = exports.SchedulerModel = void 0;
var _dom = require("@testing-library/dom");
var _toolbar = require("../../../../scheduler/__tests__/__mock__/model/toolbar");
var _popup = require("../../../appointment_popup/popup");
var _m_scheduler = require("../../../m_scheduler");
var _appointment = require("./appointment");
var _popup2 = require("./popup");
var _tooltip = require("./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()) ?? ""
});
class SchedulerModel {
constructor(container) {
this.getPopups = () => document.querySelectorAll(`.dx-overlay-wrapper.${_popup.APPOINTMENT_POPUP_CLASS}, .dx-overlay-wrapper.${_m_scheduler.POPUP_DIALOG_CLASS}`);
this.getLoadPanel = () => document.querySelector(".dx-loadpanel");
this.getTooltipAppointment = () => document.querySelector(".dx-tooltip-appointment-item");
this.container = container;
this.queries = (0, _dom.within)(container)
}
get popup() {
return this.getPopup()
}
get tooltip() {
return new _tooltip.TooltipModel
}
get toolbar() {
return new _toolbar.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] : (0, _appointment.createAppointmentModel)(null)
}
return this.getAppointments().find(appointment => appointment.getText() === text) ?? (0, _appointment.createAppointmentModel)(null)
}
getAppointments() {
const allButtons = this.queries.queryAllByRole("button");
const appointments = allButtons.filter(btn => btn.classList.contains("dx-scheduler-appointment"));
return appointments.map(element => (0, _appointment.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 ? (0, _appointment.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 _popup2.PopupModel(popupElement)
}
isPopupVisible() {
return this.getPopups().length > 0
}
isRecurrenceDialogVisible() {
return !!document.querySelector(`.dx-overlay-wrapper.${_m_scheduler.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()
}
}
exports.SchedulerModel = SchedulerModel;
const createSchedulerModel = container => {
const model = new SchedulerModel(container);
return model
};
exports.createSchedulerModel = createSchedulerModel;