import { render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { describe, it, expect, vi } from "vitest"; import type { TextEditorProps } from "./Editor"; import { Editor } from "./Editor"; describe("Editor", () => { const defaultProps: TextEditorProps = { getText: vi.fn(), setText: vi.fn(), variables: ["name", "email"], height: "200px", placeholder: "Start typing...", }; it("renders editor with default props", () => { render(); expect(screen.getByRole("textbox")).toBeInTheDocument(); expect(screen.getByText("Start typing...")).toBeInTheDocument(); }); it("renders toolbar", () => { render(); expect(screen.getByText("Normal")).toBeInTheDocument(); expect(screen.getByText("add_variable")).toBeInTheDocument(); }); it("excludes toolbar items", () => { render(); expect(screen.queryByTitle("Bold")).not.toBeInTheDocument(); expect(screen.queryByTitle("Italic")).not.toBeInTheDocument(); }); it("renders variables plugin when variables are provided", () => { render(); expect(screen.getByText("add_variable")).toBeInTheDocument(); }); it("does not render variables plugin when variables are not provided", () => { render(); expect(screen.queryByText("add_variable")).not.toBeInTheDocument(); }); it("disables lists when disableLists is true", () => { render(); expect(screen.queryByTitle("Bullet List")).not.toBeInTheDocument(); expect(screen.queryByTitle("Numbered List")).not.toBeInTheDocument(); }); it("calls getText when text is entered", async () => { const user = userEvent.setup(); render(); const editor = screen.getByRole("textbox"); await user.type(editor, "Hello, world!"); expect(defaultProps.getText).toHaveBeenCalled(); }); it("applies custom height", () => { render(); const editorInner = screen.getByRole("textbox").parentElement; expect(editorInner).toHaveStyle({ height: "300px" }); }); it("handles first render and update template", () => { const setFirstRender = vi.fn(); render( ); expect(setFirstRender).toHaveBeenCalled(); }); });