Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions packages/react/src/blocks/File/block.browser.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { BlockNoteSchema } from "@blocknote/core";
import { describe, expect } from "vite-plus/test";

import { ReactFileBlock } from "./block.js";

describe("File block", () => {
it.for(["core", "React"] as const)(
"lays out the attachment icon next to its filename (%s)",
async (variant, { setupEditor }) => {
const defaultSchema = BlockNoteSchema.create();
const schema =
variant === "React"
? defaultSchema.extend({ blockSpecs: { file: ReactFileBlock() } })
: defaultSchema;
const { rootNode } = await setupEditor({
schema,
initialContent: [
{
type: "file",
props: {
name: "Report.pdf",
url: "https://example.com/report.pdf",
},
},
],
});

const icon = rootNode.querySelector(".bn-file-icon")!;
const filename = rootNode.querySelector(".bn-file-name")!;
const iconBounds = icon.getBoundingClientRect();
const filenameBounds = filename.getBoundingClientRect();

expect(filename).toHaveTextContent("Report.pdf");
expect(filenameBounds.left).toBeGreaterThanOrEqual(iconBounds.right);
expect(filenameBounds.top).toBeLessThan(iconBounds.bottom);
expect(filename.closest('[data-content-type="file"]')).toHaveAttribute(
"data-file-block",
);
},
);

it("styles the React add-file control and opens the file panel", async ({
setupEditor,
page,
}) => {
const { editor } = await setupEditor({
schema: BlockNoteSchema.create().extend({
blockSpecs: { file: ReactFileBlock() },
}),
initialContent: [{ type: "file" }],
});

const addFile = page.getByRole("button", {
name: editor.dictionary.file_blocks.add_button_text.file,
});
await expect.element(addFile).toHaveStyle({ display: "flex" });
await addFile.click();
await expect
.element(
page.getByRole("tab", {
name: editor.dictionary.file_panel.embed.title,
}),
)
.toBeVisible();
});
});
3 changes: 3 additions & 0 deletions packages/react/src/blocks/File/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { FileBlockWrapper } from "./helpers/render/FileBlockWrapper.js";
import { LinkWithCaption } from "./helpers/toExternalHTML/LinkWithCaption.js";

export const ReactFileBlock = createReactBlockSpec(createFileBlockConfig, {
meta: {
fileBlockAccept: ["*/*"],
},
render: (props) => <FileBlockWrapper {...props} />,
parse: fileParse(),
toExternalHTML: (props) => {
Expand Down
1 change: 1 addition & 0 deletions tests/vite.config.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const LOCAL_BROWSER_FILES = [
"../packages/core/src/editor/managers/EventManager.browser.test.ts",
"../packages/core/src/extensions/FormattingToolbar/FormattingToolbar.browser.test.ts",
"../packages/core/src/extensions/SuggestionMenu/SuggestionMenu.browser.test.ts",
"../packages/react/src/blocks/File/block.browser.test.tsx",
"../packages/react/src/components/FormattingToolbar/DefaultButtons/BasicTextStyleButton.browser.test.tsx",
"../packages/react/src/components/FormattingToolbar/DefaultButtons/ColorStyleButton.browser.test.tsx",
"../packages/react/src/components/FormattingToolbar/DefaultButtons/CreateLinkButton.browser.test.tsx",
Expand Down
Loading