|
| 1 | +import type { PartialBlock } from "@blocknote/core"; |
| 2 | +import { describe, expect } from "vite-plus/test"; |
| 3 | +import { page, userEvent } from "vite-plus/test/browser"; |
| 4 | +import type { BrowserContext } from "../../../../../tests/src/fixtures/editor.js"; |
| 5 | + |
| 6 | +const imageDocument: PartialBlock[] = [{ type: "paragraph" }]; |
| 7 | + |
| 8 | +async function openImagePanel({ |
| 9 | + pressKey, |
| 10 | + focusUntil, |
| 11 | +}: Pick<BrowserContext, "pressKey" | "focusUntil">) { |
| 12 | + await focusUntil(page.getByRole("textbox")); |
| 13 | + await expect.element(page.getByRole("textbox")).toHaveFocus(); |
| 14 | + await userEvent.keyboard("/image"); |
| 15 | + await expect |
| 16 | + .element(page.getByRole("option", { name: /Image/ })) |
| 17 | + .toBeVisible(); |
| 18 | + await pressKey("Enter"); |
| 19 | + const panel = page.getByRole("tabpanel"); |
| 20 | + await expect.element(panel).toBeVisible(); |
| 21 | + return panel; |
| 22 | +} |
| 23 | + |
| 24 | +describe("keyboard", () => { |
| 25 | + it("file panel: Embed URL input receives focus on opening", async ({ |
| 26 | + setupEditor, |
| 27 | + pressKey, |
| 28 | + focusUntil, |
| 29 | + }) => { |
| 30 | + await setupEditor({ initialContent: imageDocument }); |
| 31 | + const panel = await openImagePanel({ pressKey, focusUntil }); |
| 32 | + await expect.element(panel.getByPlaceholder("Enter URL")).toHaveFocus(); |
| 33 | + }); |
| 34 | + |
| 35 | + it("file panel: Upload button receives focus on opening", async ({ |
| 36 | + setupEditor, |
| 37 | + pressKey, |
| 38 | + focusUntil, |
| 39 | + }) => { |
| 40 | + await setupEditor({ |
| 41 | + initialContent: imageDocument, |
| 42 | + uploadFile: async () => "/image.svg", |
| 43 | + }); |
| 44 | + const panel = await openImagePanel({ pressKey, focusUntil }); |
| 45 | + await expect |
| 46 | + .element(panel.getByRole("button", { name: "Upload image", exact: true })) |
| 47 | + .toHaveFocus(); |
| 48 | + }); |
| 49 | +}); |
0 commit comments