// @vitest-environment jsdom /** * The app's own buttons on the selection strip (`actions`, LEAF-4): pressing * one runs it with the selection in place, and the strip closes. jsdom has no * layout, so the view's focus and coordinates are stood in for. */ import { afterEach, expect, it, vi } from 'vitest' import { act, cleanup, render, screen } from '@testing-library/react' import userEvent from '@testing-library/user-event' import { Editor } from '@tiptap/core' import StarterKit from '@tiptap/starter-kit' import { KeptSelection, SelectionToolbar } from './SelectionToolbar' let editor: Editor | undefined afterEach(() => { cleanup() editor?.destroy() editor = undefined vi.useRealTimers() }) it('runs an action with the selection in place, and closes the strip', async () => { vi.useFakeTimers({ shouldAdvanceTime: true }) editor = new Editor({ extensions: [StarterKit, KeptSelection], content: '
some words to comment on
' }) vi.spyOn(editor.view, 'hasFocus').mockReturnValue(true) vi.spyOn(editor.view, 'coordsAtPos').mockReturnValue({ top: 10, bottom: 20, left: 10, right: 20 }) const seen: { from: number; to: number }[] = [] const run = vi.fn((e: Editor) => seen.push({ from: e.state.selection.from, to: e.state.selection.to })) render(