devextreme
Version:
JavaScript/TypeScript Component Suite for Responsive Web Development
140 lines (139 loc) • 5.77 kB
JavaScript
/**
* DevExtreme (esm/__internal/scheduler/__tests__/__mock__/model/popup.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 $ from "../../../../../core/renderer";
import {
within
} from "@testing-library/dom";
const queryRequiredElement = (parent, selector) => {
const element = parent.querySelector(selector);
if (!element) {
throw new Error(`Element with selector "${selector}" not found`)
}
return element
};
export class PopupModel {
constructor(element) {
this.getInput = editorName => {
var _$input, _$input2, _$input3;
const editor = this.dxForm.getEditor(editorName);
let $input = null;
if ("startDateTimeZoneEditor" === editorName || "endDateTimeZoneEditor" === editorName) {
$input = null === editor || void 0 === editor ? void 0 : editor.$element().find('input[type="hidden"]')
}
if (!(null !== (_$input = $input) && void 0 !== _$input && _$input.length)) {
$input = null === editor || void 0 === editor ? void 0 : editor.$element().find(".dx-texteditor-input")
}
if (!(null !== (_$input2 = $input) && void 0 !== _$input2 && _$input2.length)) {
$input = null === editor || void 0 === editor ? void 0 : editor.$element().find("input")
}
if (!(null !== (_$input3 = $input) && void 0 !== _$input3 && _$input3.length)) {
throw new Error(`Input element of editor with name "${editorName}" not found`)
}
return $input.get(0)
};
this.getInputValue = editorName => {
const input = this.getInput(editorName);
return input.value
};
this.setInputValue = (editorName, value) => {
var _this$dxForm$getEdito;
null === (_this$dxForm$getEdito = this.dxForm.getEditor(editorName)) || void 0 === _this$dxForm$getEdito || _this$dxForm$getEdito.option("value", value)
};
this.isInputVisible = editorName => {
const editor = this.dxForm.getEditor(editorName);
return !!(null !== editor && void 0 !== editor && editor.$element().get(0).isConnected)
};
this.getWeekDaysSelection = () => {
const buttons = Array.from(this.recurrenceWeekDayButtons.querySelectorAll(".dx-button"));
return buttons.map(button => button.classList.contains("dx-button-mode-contained"))
};
this.selectRepeatValue = value => {
this.getInput("repeatEditor").click();
const items = document.querySelectorAll(".dx-selectbox-popup-wrapper .dx-list .dx-list-item");
const itemToSelect = Array.from(items).find(item => {
var _item$textContent;
return (null === (_item$textContent = item.textContent) || void 0 === _item$textContent ? void 0 : _item$textContent.toLowerCase()) === value.toLowerCase()
});
if (!itemToSelect) {
throw new Error(`Repeat value "${value}" not found`)
}
itemToSelect.click()
};
this.element = element;
this.queries = within(element);
this.component = $(".dx-scheduler-appointment-popup.dx-popup.dx-widget").dxPopup("instance")
}
get dxForm() {
return $(this.element.querySelector(".dx-form")).dxForm("instance")
}
get mainGroup() {
return queryRequiredElement(this.element, ".dx-scheduler-form-main-group")
}
get recurrenceGroup() {
return queryRequiredElement(this.element, ".dx-scheduler-form-recurrence-group")
}
get subjectIcon() {
return queryRequiredElement(this.element, ".dx-scheduler-form-subject-group .dx-scheduler-form-icon .dx-icon")
}
get resourceIcon() {
return queryRequiredElement(this.element, ".dx-scheduler-form-resources-group .dx-icon")
}
get recurrenceWeekDayButtons() {
return queryRequiredElement(this.element, ".dx-scheduler-days-of-week-buttons")
}
get saveButton() {
return this.queries.getByRole("button", {
name: "Save"
})
}
get cancelButton() {
return this.queries.getByRole("button", {
name: "Cancel"
})
}
get closeButton() {
return this.queries.getByRole("button", {
name: "Close"
})
}
get backButton() {
return this.queries.getByRole("button", {
name: "Back"
})
}
get editSeriesButton() {
return this.queries.getByRole("button", {
name: "Edit series"
})
}
get deleteSeriesButton() {
return this.queries.getByRole("button", {
name: "Delete series"
})
}
get editAppointmentButton() {
return this.queries.getByRole("button", {
name: "Edit appointment"
})
}
get deleteAppointmentButton() {
return this.queries.getByRole("button", {
name: "Delete appointment"
})
}
get recurrenceSettingsButton() {
return queryRequiredElement(this.element, ".dx-scheduler-form-recurrence-settings-button")
}
isMainGroupVisible() {
return !this.mainGroup.classList.contains("dx-scheduler-form-main-group-hidden")
}
isRecurrenceGroupVisible() {
return !this.recurrenceGroup.classList.contains("dx-scheduler-form-recurrence-group-hidden")
}
}