Skip to content

Commit 6e3087c

Browse files
committed
implement tests
1 parent 67c8004 commit 6e3087c

3 files changed

Lines changed: 430 additions & 160 deletions

File tree

packages/devextreme/js/__internal/scheduler/__tests__/__mock__/m_mock_scheduler.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,8 @@ export const setupSchedulerTestEnvironment = ({
7070

7171
return defaultRect;
7272
});
73+
74+
Element.prototype.getClientRects = jest.fn(function (): DOMRectList {
75+
return [Element.prototype.getBoundingClientRect.call(this)] as unknown as DOMRectList;
76+
});
7377
};

packages/devextreme/js/__internal/scheduler/__tests__/__mock__/model/tooltip.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,49 @@
1+
import type { dxElementWrapper } from '@js/core/renderer';
2+
import $ from '@js/core/renderer';
3+
import type dxTooltip from '@js/ui/tooltip';
14
import { within } from '@testing-library/dom';
25

36
const TOOLTIP_WRAPPER_SELECTOR = '.dx-overlay-wrapper.dx-scheduler-appointment-tooltip-wrapper';
47

58
export class TooltipModel {
6-
private get element(): HTMLElement | null {
9+
get element(): HTMLElement | null {
710
return document.querySelector<HTMLElement>(TOOLTIP_WRAPPER_SELECTOR);
811
}
912

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+
1023
isVisible(): boolean {
1124
return this.element !== null;
1225
}
1326

27+
getOverlayContent(): HTMLElement | null {
28+
return this.element?.querySelector('.dx-scheduler-appointment-tooltip-wrapper .dx-overlay-content') ?? null;
29+
}
30+
1431
getScrollableContent(): Element | null {
1532
return this.element?.querySelector('.dx-scrollable .dx-scrollview-content') ?? null;
1633
}
1734

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+
)
2240
: [];
41+
}
42+
43+
getDeleteButton(index = 0): HTMLElement {
44+
const buttons = this.getDeleteButtons();
2345

24-
if (buttons.length === 0) {
46+
if (buttons.length <= index) {
2547
throw new Error('Tooltip delete button not found');
2648
}
2749

0 commit comments

Comments
 (0)