Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,8 @@ export const setupSchedulerTestEnvironment = ({

return defaultRect;
});

Element.prototype.getClientRects = jest.fn(function (): DOMRectList {
return [Element.prototype.getBoundingClientRect.call(this)] as unknown as DOMRectList;
});
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
import type { dxElementWrapper } from '@js/core/renderer';
import $ from '@js/core/renderer';
import type dxTooltip from '@js/ui/tooltip';
import { within } from '@testing-library/dom';

const TOOLTIP_WRAPPER_SELECTOR = '.dx-overlay-wrapper.dx-scheduler-appointment-tooltip-wrapper';
const TOOLTIP_WRAPPER_SELECTOR = `
.dx-overlay-wrapper.dx-scheduler-overlay-panel,
.dx-overlay-wrapper.dx-scheduler-appointment-tooltip-wrapper
`;

export class TooltipModel {
private get element(): HTMLElement | null {
get element(): HTMLElement | null {
return document.querySelector<HTMLElement>(TOOLTIP_WRAPPER_SELECTOR);
}

get dxTooltip(): dxTooltip {
// @ts-expect-error
return $('.dx-tooltip.dx-widget').dxTooltip('instance') as dxTooltip;
}

get target(): Element | null {
const $target = this.dxTooltip.option('target') as unknown as dxElementWrapper;
return $target?.get(0) ?? null;
}

isVisible(): boolean {
return this.element !== null;
}
Expand All @@ -15,24 +31,35 @@ export class TooltipModel {
return this.element?.querySelector('.dx-scrollable .dx-scrollview-content') ?? null;
}

getDeleteButton(index = 0): HTMLElement {
const tooltip = this.element;
const buttons = tooltip
? within(tooltip).queryAllByRole('button').filter((btn) => btn.classList.contains('dx-tooltip-appointment-item-delete-button'))
getDeleteButtons(): HTMLElement[] {
return this.element
? within(this.element).queryAllByRole('button').filter(
(btn) => btn.classList.contains('dx-tooltip-appointment-item-delete-button'),
)
: [];
}

if (buttons.length === 0) {
getDeleteButton(index = 0): HTMLElement {
const buttons = this.getDeleteButtons();

if (buttons.length <= index) {
throw new Error('Tooltip delete button not found');
}

return buttons[index];
}

getAppointmentItems(): HTMLElement[] {
return this.element ? within(this.element).queryAllByRole('option') : [];
}

getAppointmentItem(index = 0): HTMLElement | null {
const tooltip = this.element;
if (!tooltip) {
return null;
const items = this.getAppointmentItems();

if (items.length <= index) {
throw new Error('Tooltip appointment item not found');
}
return within(tooltip).queryAllByRole('option')[index] ?? null;

return items[index];
Comment thread
Tucchhaa marked this conversation as resolved.
}
}
Loading
Loading