UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

182 lines (180 loc) • 8.91 kB
/** * DevExtreme (cjs/__internal/scheduler/appointments_new/appointment/agenda_appointment.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 _renderer = _interopRequireDefault(require("../../../../core/renderer")); var _fx = _interopRequireDefault(require("../../../common/core/animation/fx")); var _base_appointment_view = require("../__mock__/base_appointment_view"); var _const = require("../const"); var _agenda_appointment = require("./agenda_appointment"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e } } const getProperties = (appointmentData, targetedAppointmentData) => { const baseProperties = (0, _base_appointment_view.getBaseAppointmentViewProperties)(appointmentData, targetedAppointmentData); return Object.assign({}, baseProperties, { modifiers: { isLastInGroup: false }, geometry: { height: 50, width: "100%" }, getResourcesValues: () => Promise.resolve([]) }) }; const createAgendaAppointment = async properties => { const $element = (0, _renderer.default)(".root"); const instance = new _agenda_appointment.AgendaAppointmentView($element, properties); await new Promise(process.nextTick); return instance }; const defaultAppointmentData = { text: "Test appointment", startDate: new Date(2024, 0, 1, 9, 0), endDate: new Date(2024, 0, 1, 10, 0) }; (0, _globals.describe)("AgendaAppointment", () => { (0, _globals.beforeEach)(() => { _fx.default.off = true; const $container = (0, _renderer.default)("<div>").addClass("container").appendTo(document.body); (0, _renderer.default)("<div>").addClass("root").appendTo($container) }); (0, _globals.afterEach)(() => { (0, _renderer.default)(".container").remove(); _fx.default.off = false; _globals.jest.useRealTimers() }); (0, _globals.describe)("Classes", () => { _globals.it.each([true, false])("should have correct class for modifiers.lastInGroup = %o", async isLastInGroup => { const instance = await createAgendaAppointment(Object.assign({}, getProperties(defaultAppointmentData), { modifiers: { isLastInGroup: isLastInGroup } })); (0, _globals.expect)(instance.$element().hasClass(_const.AGENDA_APPOINTMENT_CLASSES.LAST_IN_DATE)).toBe(isLastInGroup) }); (0, _globals.it)("should have has-resource class when resource color is applied", async () => { const instance = await createAgendaAppointment(Object.assign({}, getProperties(defaultAppointmentData), { getResourceColor: () => Promise.resolve("red") })); (0, _globals.expect)(instance.$element().hasClass(_const.APPOINTMENT_TYPE_CLASSES.HAS_RESOURCE)).toBe(true) }) }); (0, _globals.describe)("Geometry", () => { (0, _globals.it)("should apply geometry on init", async () => { const instance = await createAgendaAppointment(Object.assign({}, getProperties(defaultAppointmentData), { geometry: { width: "100%", height: 50 } })); const $element = instance.$element(); (0, _globals.expect)($element.css("width")).toBe("100%"); (0, _globals.expect)($element.css("height")).toBe("50px") }) }); (0, _globals.describe)("Title", () => { _globals.it.each([{ text: "Test title", expected: "Test title" }, { text: void 0, expected: "(No subject)" }, { text: "", expected: "(No subject)" }])("should have correct title text for appointment text = %o", async _ref => { let { text: text, expected: expected } = _ref; const instance = await createAgendaAppointment(getProperties(Object.assign({}, defaultAppointmentData, { text: text }))); const $title = instance.$element().find(`.${_const.APPOINTMENT_CLASSES.TITLE}`); (0, _globals.expect)($title.text()).toBe(expected) }) }); (0, _globals.describe)("Date text", () => { (0, _globals.it)("should have correct date text", async () => { const instance = await createAgendaAppointment(getProperties(Object.assign({}, defaultAppointmentData, { startDate: new Date(2024, 0, 1, 9, 0), endDate: new Date(2024, 0, 1, 10, 0) }))); const $date = instance.$element().find(`.${_const.APPOINTMENT_CLASSES.DATE}`); (0, _globals.expect)($date.text()).toBe("9:00 AM - 10:00 AM") }) }); (0, _globals.describe)("Recurrence", () => { _globals.it.each([true, false])("should have correct recurrence icon visibility for isRecurring = %o", async isRecurring => { const appointmentData = isRecurring ? Object.assign({}, defaultAppointmentData, { recurrenceRule: "FREQ=DAILY" }) : defaultAppointmentData; const instance = await createAgendaAppointment(getProperties(appointmentData)); const $icon = instance.$element().find(`.${_const.APPOINTMENT_CLASSES.RECURRENCE_ICON}`); (0, _globals.expect)($icon.length).toBe(isRecurring ? 1 : 0) }) }); (0, _globals.describe)("All Day", () => { _globals.it.each([true, false])("should have correct all day text visibility for allDay = %o", async isAllDay => { const appointmentData = Object.assign({}, defaultAppointmentData, { allDay: isAllDay }); const instance = await createAgendaAppointment(getProperties(appointmentData)); const $allDayText = instance.$element().find(`.${_const.APPOINTMENT_CLASSES.ALL_DAY_TEXT}`); (0, _globals.expect)($allDayText.length).toBe(isAllDay ? 1 : 0) }) }); (0, _globals.describe)("Resources", () => { (0, _globals.it)("should apply resource color", async () => { const instance = await createAgendaAppointment(Object.assign({}, getProperties(defaultAppointmentData), { getResourceColor: () => Promise.resolve("rgb(255, 0, 0)") })); const $marker = instance.$element().find(`.${_const.AGENDA_APPOINTMENT_CLASSES.MARKER}`); (0, _globals.expect)($marker.css("backgroundColor")).toBe("rgb(255, 0, 0)") }); (0, _globals.it)("should render resource list", async () => { const instance = await createAgendaAppointment(Object.assign({}, getProperties(defaultAppointmentData), { getResourcesValues: () => Promise.resolve([{ label: "roomId", values: ["Room 1"] }, { label: "ownerId", values: ["Owner 1"] }]) })); const $resourceItems = instance.$element().find(`.${_const.AGENDA_APPOINTMENT_CLASSES.RESOURCE_ITEM}`); (0, _globals.expect)($resourceItems.length).toBe(2); (0, _globals.expect)($resourceItems.eq(0).text()).toBe("roomId:Room 1"); (0, _globals.expect)($resourceItems.eq(1).text()).toBe("ownerId:Owner 1") }); (0, _globals.it)("should not render resource list if there are no resources", async () => { const instance = await createAgendaAppointment(Object.assign({}, getProperties(defaultAppointmentData), { getResourcesValues: () => Promise.resolve([]) })); const $resourceItems = instance.$element().find(`.${_const.AGENDA_APPOINTMENT_CLASSES.RESOURCE_ITEM}`); (0, _globals.expect)($resourceItems.length).toBe(0) }) }); (0, _globals.describe)("Geometry", () => { (0, _globals.it)("should have correct height and width", async () => { const instance = await createAgendaAppointment(Object.assign({}, getProperties(Object.assign({}, defaultAppointmentData)), { geometry: { height: 60, width: "80%" } })); (0, _globals.expect)(instance.$element().css("height")).toBe("60px"); (0, _globals.expect)(instance.$element().css("width")).toBe("80%") }) }) });