* early UI refresher of workflows using v3 designs. needs tons of testing, might have broken * Delete .claude/settings.local.json * fix: bunch of design fixes, merge conflict fixes * fix: e2e and type-check * fix: await button click * review fixes * code rabbit fixes * fix styles in variables dropdown * fix text truncate * fix: unit tests * fix: unit tests * chore: add missing i18n * review fixes * review fixes * fix testing info message * move timeSectionText up * fix which team does this apply to info message * disable set up agent button with read only * fix: cal.ai breaking on mobile screen --------- Co-authored-by: Amit Sharma <74371312+Amit91848@users.noreply.github.com> Co-authored-by: Udit Takkar <udit222001@gmail.com> Co-authored-by: CarinaWolli <wollencarina@gmail.com>
77 lines
2.7 KiB
TypeScript
77 lines
2.7 KiB
TypeScript
import { render, screen } from "@testing-library/react";
|
|
import userEvent from "@testing-library/user-event";
|
|
import { describe, it, expect, vi } from "vitest";
|
|
|
|
import { Editor } from "./Editor";
|
|
import type { TextEditorProps } from "./types";
|
|
|
|
vi.mock("@calcom/lib/hooks/useMediaQuery", () => ({
|
|
default: (_query: string) => false,
|
|
}));
|
|
|
|
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(<Editor {...defaultProps} />);
|
|
expect(screen.getByRole("textbox")).toBeInTheDocument();
|
|
expect(screen.getByText("Start typing...")).toBeInTheDocument();
|
|
});
|
|
|
|
it("renders toolbar", () => {
|
|
render(<Editor {...defaultProps} />);
|
|
expect(screen.getByText("Normal")).toBeInTheDocument();
|
|
expect(screen.getByText("add_variable")).toBeInTheDocument();
|
|
});
|
|
|
|
it("excludes toolbar items", () => {
|
|
render(<Editor {...defaultProps} excludedToolbarItems={["bold", "italic"]} />);
|
|
expect(screen.queryByTitle("Bold")).not.toBeInTheDocument();
|
|
expect(screen.queryByTitle("Italic")).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("renders variables plugin when variables are provided", () => {
|
|
render(<Editor {...defaultProps} />);
|
|
expect(screen.getByText("add_variable")).toBeInTheDocument();
|
|
});
|
|
|
|
it("does not render variables plugin when variables are not provided", () => {
|
|
render(<Editor {...defaultProps} variables={undefined} />);
|
|
expect(screen.queryByText("add_variable")).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("disables lists when disableLists is true", () => {
|
|
render(<Editor {...defaultProps} disableLists={true} />);
|
|
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(<Editor {...defaultProps} />);
|
|
const editor = screen.getByRole("textbox");
|
|
await user.type(editor, "Hello, world!");
|
|
expect(defaultProps.getText).toHaveBeenCalled();
|
|
});
|
|
|
|
it("applies custom height", () => {
|
|
render(<Editor {...defaultProps} height="300px" />);
|
|
const editorInner = screen.getByRole("textbox").parentElement;
|
|
expect(editorInner).toHaveStyle({ height: "300px" });
|
|
});
|
|
|
|
it("handles first render and update template", () => {
|
|
const setFirstRender = vi.fn();
|
|
render(
|
|
<Editor {...defaultProps} updateTemplate={true} firstRender={true} setFirstRender={setFirstRender} />
|
|
);
|
|
expect(setFirstRender).toHaveBeenCalled();
|
|
});
|
|
});
|