Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
26 lines
1.3 KiB
TypeScript
26 lines
1.3 KiB
TypeScript
import { render, screen } from "@testing-library/react";
|
|
import userEvent from "@testing-library/user-event";
|
|
import { describe, it, expect, vi } from "vitest";
|
|
import { RichTextEditor } from "./RichTextEditor";
|
|
|
|
// add-page-visual-editor: links follow the page link rule, and a refused one says why instead of vanishing.
|
|
describe("RichTextEditor", () => {
|
|
it("refuses an unsafe link with a message, and adds nothing", async () => {
|
|
const user = userEvent.setup();
|
|
const onChange = vi.fn();
|
|
vi.spyOn(window, "prompt").mockReturnValue("javascript:alert(1)");
|
|
render(<RichTextEditor label="Content" value="<p>Hello</p>" onChange={onChange} />);
|
|
await screen.findByRole("textbox", { name: "Content" });
|
|
await user.click(screen.getByRole("button", { name: "Link" }));
|
|
expect(screen.getByRole("alert")).toHaveTextContent("That link is not allowed");
|
|
expect(onChange).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("in bare mode drops the box and keeps the toolbar for when the text is being edited", async () => {
|
|
render(<RichTextEditor bare label="Content" value="<p>Hello</p>" onChange={() => {}} />);
|
|
const box = await screen.findByRole("textbox", { name: "Content" });
|
|
expect(box.closest(".border")).toBeNull();
|
|
expect(screen.getByRole("toolbar", { name: "Formatting" })).toBeInTheDocument();
|
|
});
|
|
});
|