|
| 1 | +// Components |
| 2 | +import { VTooltip } from '../VTooltip' |
| 3 | +import { VBtn } from '@/components/VBtn' |
| 4 | +import { VList, VListItem } from '@/components/VList' |
| 5 | +import { VMenu } from '@/components/VMenu' |
| 6 | + |
| 7 | +// Utilities |
| 8 | +import { render, screen, userEvent, wait } from '@test' |
| 9 | + |
| 10 | +describe('VTooltip', () => { |
| 11 | + it('should not focus the activator after closing on mouseleave', async () => { |
| 12 | + render(() => ( |
| 13 | + <VList> |
| 14 | + <VListItem data-testid="item" link title="Item"> |
| 15 | + <VTooltip activator="parent" openDelay={ 0 } closeDelay={ 0 }>Tooltip</VTooltip> |
| 16 | + </VListItem> |
| 17 | + <VListItem link title="Other" data-testid="other" /> |
| 18 | + </VList> |
| 19 | + )) |
| 20 | + |
| 21 | + const item = screen.getByTestId('item') |
| 22 | + await userEvent.hover(item) |
| 23 | + await expect.poll(() => screen.queryByCSS('.v-tooltip .v-overlay__content')).toBeVisible() |
| 24 | + |
| 25 | + await userEvent.unhover(item) |
| 26 | + await wait(100) |
| 27 | + |
| 28 | + expect(screen.queryByCSS('.v-tooltip .v-overlay__content')).not.toBeVisible() |
| 29 | + expect(document.activeElement).not.toBe(item) |
| 30 | + }) |
| 31 | + |
| 32 | + it('should not focus the activator after closing on mouseleave while another menu is open', async () => { |
| 33 | + render(() => ( |
| 34 | + <div> |
| 35 | + <VBtn data-testid="tooltip-btn"> |
| 36 | + Hover me |
| 37 | + <VTooltip activator="parent" openDelay={ 0 } closeDelay={ 0 }>Tooltip</VTooltip> |
| 38 | + </VBtn> |
| 39 | + <VBtn data-testid="menu-btn"> |
| 40 | + Open menu |
| 41 | + <VMenu activator="parent"> |
| 42 | + <VList> |
| 43 | + <VListItem link title="Item" /> |
| 44 | + </VList> |
| 45 | + </VMenu> |
| 46 | + </VBtn> |
| 47 | + </div> |
| 48 | + )) |
| 49 | + |
| 50 | + await userEvent.click(screen.getByTestId('menu-btn')) |
| 51 | + await expect.poll(() => screen.queryByCSS('.v-menu .v-overlay__content')).toBeVisible() |
| 52 | + |
| 53 | + const tooltipBtn = screen.getByTestId('tooltip-btn') |
| 54 | + await userEvent.hover(tooltipBtn) |
| 55 | + await expect.poll(() => screen.queryByCSS('.v-tooltip .v-overlay__content')).toBeVisible() |
| 56 | + |
| 57 | + await userEvent.unhover(tooltipBtn) |
| 58 | + await wait(100) |
| 59 | + |
| 60 | + expect(screen.queryByCSS('.v-tooltip .v-overlay__content')).not.toBeVisible() |
| 61 | + expect(document.activeElement).not.toBe(tooltipBtn) |
| 62 | + // the menu should remain open |
| 63 | + expect(screen.queryByCSS('.v-menu .v-overlay__content')).toBeVisible() |
| 64 | + }) |
| 65 | +}) |
0 commit comments