|
| 1 | +import { BlockNoteSchema } from "@blocknote/core"; |
| 2 | +import { describe, expect } from "vite-plus/test"; |
| 3 | + |
| 4 | +import { ReactFileBlock } from "./block.js"; |
| 5 | + |
| 6 | +describe("File block", () => { |
| 7 | + it.for(["core", "React"] as const)( |
| 8 | + "lays out the attachment icon next to its filename (%s)", |
| 9 | + async (variant, { setupEditor }) => { |
| 10 | + const defaultSchema = BlockNoteSchema.create(); |
| 11 | + const schema = |
| 12 | + variant === "React" |
| 13 | + ? defaultSchema.extend({ blockSpecs: { file: ReactFileBlock() } }) |
| 14 | + : defaultSchema; |
| 15 | + const { rootNode } = await setupEditor({ |
| 16 | + schema, |
| 17 | + initialContent: [ |
| 18 | + { |
| 19 | + type: "file", |
| 20 | + props: { |
| 21 | + name: "Report.pdf", |
| 22 | + url: "https://example.com/report.pdf", |
| 23 | + }, |
| 24 | + }, |
| 25 | + ], |
| 26 | + }); |
| 27 | + |
| 28 | + const icon = rootNode.querySelector(".bn-file-icon")!; |
| 29 | + const filename = rootNode.querySelector(".bn-file-name")!; |
| 30 | + const iconBounds = icon.getBoundingClientRect(); |
| 31 | + const filenameBounds = filename.getBoundingClientRect(); |
| 32 | + |
| 33 | + expect(filename).toHaveTextContent("Report.pdf"); |
| 34 | + expect(filenameBounds.left).toBeGreaterThanOrEqual(iconBounds.right); |
| 35 | + expect(filenameBounds.top).toBeLessThan(iconBounds.bottom); |
| 36 | + expect(filename.closest('[data-content-type="file"]')).toHaveAttribute( |
| 37 | + "data-file-block", |
| 38 | + ); |
| 39 | + }, |
| 40 | + ); |
| 41 | + |
| 42 | + it("styles the React add-file control and opens the file panel", async ({ |
| 43 | + setupEditor, |
| 44 | + page, |
| 45 | + }) => { |
| 46 | + const { editor } = await setupEditor({ |
| 47 | + schema: BlockNoteSchema.create().extend({ |
| 48 | + blockSpecs: { file: ReactFileBlock() }, |
| 49 | + }), |
| 50 | + initialContent: [{ type: "file" }], |
| 51 | + }); |
| 52 | + |
| 53 | + const addFile = page.getByRole("button", { |
| 54 | + name: editor.dictionary.file_blocks.add_button_text.file, |
| 55 | + }); |
| 56 | + await expect.element(addFile).toHaveStyle({ display: "flex" }); |
| 57 | + await addFile.click(); |
| 58 | + await expect |
| 59 | + .element( |
| 60 | + page.getByRole("tab", { |
| 61 | + name: editor.dictionary.file_panel.embed.title, |
| 62 | + }), |
| 63 | + ) |
| 64 | + .toBeVisible(); |
| 65 | + }); |
| 66 | +}); |
0 commit comments