|
| 1 | +import type { dxElementWrapper } from '@js/core/renderer'; |
| 2 | +import $ from '@js/core/renderer'; |
| 3 | +import type dxTooltip from '@js/ui/tooltip'; |
1 | 4 | import { within } from '@testing-library/dom'; |
2 | 5 |
|
3 | 6 | const TOOLTIP_WRAPPER_SELECTOR = '.dx-overlay-wrapper.dx-scheduler-appointment-tooltip-wrapper'; |
4 | 7 |
|
5 | 8 | export class TooltipModel { |
6 | | - private get element(): HTMLElement | null { |
| 9 | + get element(): HTMLElement | null { |
7 | 10 | return document.querySelector<HTMLElement>(TOOLTIP_WRAPPER_SELECTOR); |
8 | 11 | } |
9 | 12 |
|
| 13 | + get dxTooltip(): dxTooltip { |
| 14 | + // @ts-expect-error |
| 15 | + return $('.dx-tooltip.dx-widget').dxTooltip('instance') as dxTooltip; |
| 16 | + } |
| 17 | + |
| 18 | + get target(): Element | null { |
| 19 | + const $target = this.dxTooltip.option('target') as unknown as dxElementWrapper; |
| 20 | + return $target?.get(0) ?? null; |
| 21 | + } |
| 22 | + |
10 | 23 | isVisible(): boolean { |
11 | 24 | return this.element !== null; |
12 | 25 | } |
13 | 26 |
|
| 27 | + getOverlayContent(): HTMLElement | null { |
| 28 | + return this.element?.querySelector('.dx-scheduler-appointment-tooltip-wrapper .dx-overlay-content') ?? null; |
| 29 | + } |
| 30 | + |
14 | 31 | getScrollableContent(): Element | null { |
15 | 32 | return this.element?.querySelector('.dx-scrollable .dx-scrollview-content') ?? null; |
16 | 33 | } |
17 | 34 |
|
18 | | - getDeleteButton(index = 0): HTMLElement { |
19 | | - const tooltip = this.element; |
20 | | - const buttons = tooltip |
21 | | - ? within(tooltip).queryAllByRole('button').filter((btn) => btn.classList.contains('dx-tooltip-appointment-item-delete-button')) |
| 35 | + getDeleteButtons(): HTMLElement[] { |
| 36 | + return this.element |
| 37 | + ? within(this.element).queryAllByRole('button').filter( |
| 38 | + (btn) => btn.classList.contains('dx-tooltip-appointment-item-delete-button'), |
| 39 | + ) |
22 | 40 | : []; |
| 41 | + } |
| 42 | + |
| 43 | + getDeleteButton(index = 0): HTMLElement { |
| 44 | + const buttons = this.getDeleteButtons(); |
23 | 45 |
|
24 | | - if (buttons.length === 0) { |
| 46 | + if (buttons.length <= index) { |
25 | 47 | throw new Error('Tooltip delete button not found'); |
26 | 48 | } |
27 | 49 |
|
|
0 commit comments