details} content={thumbnail} />)
- const anchor = screen.getByRole('button', { name: 'details' })
- const matches = vi.spyOn(anchor, 'matches').mockReturnValue(true)
- fireEvent.focus(anchor)
- expect(screen.getByText('thumbnail')).toBeTruthy()
- const activeElement = vi.spyOn(document, 'activeElement', 'get').mockReturnValue(anchor)
- fireEvent.pointerLeave(anchor.parentElement as HTMLElement)
- act(() => { vi.advanceTimersByTime(POINTER_GRACE_MS) })
- expect(screen.getByText('thumbnail')).toBeTruthy()
- activeElement.mockRestore()
- fireEvent.blur(anchor, { relatedTarget: document.body })
- expect(screen.queryByText('thumbnail')).toBeNull()
- matches.mockRestore()
-})
-
it('dismisses an inline hover without anchor focus and lets the next Escape reach the owner', () => {
const ownerKey = vi.fn()
render(
@@ -895,46 +706,3 @@ it('flips inline media above a bottom link and constrains it without covering th
expect(card.style.top).toBe('42px')
expect(Number.parseFloat(card.style.maxHeight)).toBe(window.innerHeight - 50)
})
-
-it('closes a compact copyable card after its mouse-focused card loses the pointer', () => {
- const { wrapper } = mount({ copyText: 'value' })
- fireEvent.pointerEnter(wrapper)
- act(() => { vi.advanceTimersByTime(500) })
- const card = screen.getByRole('button', { name: 'Copy: value' })
- act(() => { card.focus() })
- expect(document.activeElement).toBe(card)
- fireEvent.pointerLeave(card)
- act(() => { vi.advanceTimersByTime(POINTER_GRACE_MS) })
- expect(screen.queryByText('card body')).toBeNull()
-})
-
-it('closes a callout hover after click toggling leaves mouse focus on the anchor', () => {
- render(details} content="body" />)
- const anchor = screen.getByRole('button', { name: 'details' })
- act(() => { anchor.focus() })
- fireEvent.click(anchor)
- fireEvent.click(anchor)
- fireEvent.pointerEnter(anchor.parentElement as HTMLElement)
- act(() => { vi.advanceTimersByTime(500) })
- expect(screen.getByText('body')).toBeTruthy()
- fireEvent.pointerLeave(anchor.parentElement as HTMLElement)
- act(() => { vi.advanceTimersByTime(POINTER_GRACE_MS) })
- expect(screen.queryByText('body')).toBeNull()
-})
-
-it('scrolls an open callout with the focused anchor keyboard controls', () => {
- render(details} content="body" />)
- const anchor = screen.getByRole('button', { name: 'details' })
- fireEvent.click(anchor)
- const scroll = document.querySelector('[data-hover-card-scroll]') as HTMLElement
- Object.defineProperty(scroll, 'clientHeight', { configurable: true, value: 160 })
- Object.defineProperty(scroll, 'scrollHeight', { configurable: true, value: 640 })
- expect(fireEvent.keyDown(scroll, { key: 'PageDown' })).toBe(true)
- expect(scroll.scrollTop).toBe(0)
- for (const [key, top] of [['ArrowDown', 20], ['ArrowUp', 0], ['PageDown', 160], ['PageUp', 0], ['End', 640], ['Home', 0]] as const) {
- expect(fireEvent.keyDown(anchor, { key })).toBe(false)
- expect(scroll.scrollTop).toBe(top)
- }
- fireEvent.keyDown(anchor, { key: 'Tab' })
- expect(screen.queryByText('body')).toBeNull()
-})