style(webui): simplify Markdown code blocks (#5002)

This commit is contained in:
chengyongru
2026-07-20 14:41:23 +08:00
committed by GitHub
parent 949cfad548
commit 76f3eead42
3 changed files with 51 additions and 52 deletions
+19 -4
View File
@@ -48,8 +48,20 @@ describe("CodeBlock", () => {
expect(screen.queryByTestId("highlighted-code")).not.toBeInTheDocument();
expect(screen.getByText("const value = 1;")).toBeInTheDocument();
expect(screen.getByText("ts")).toBeInTheDocument();
expect(screen.queryByText("ts")).not.toBeInTheDocument();
expect(screen.getByTestId("plain-code-fallback")).toHaveClass("text-foreground/90");
expect(screen.getByTestId("plain-code-fallback")).toHaveClass("bg-transparent");
expect(screen.getByTestId("plain-code-fallback")).toHaveClass("py-4", "pl-5", "pr-14");
const container = screen.getByTestId("plain-code-fallback").closest(".not-prose");
expect(container).toHaveClass("relative", "rounded-[18px]", "bg-secondary/70");
expect(container).not.toHaveClass("border");
expect(container).toHaveAttribute("data-language", "ts");
const copyButton = screen.getByRole("button", { name: "Copy code" });
expect(copyButton.parentElement).toBe(container);
expect(copyButton).toHaveClass("absolute", "h-8", "w-8", "rounded-full");
expect(copyButton).toHaveTextContent("");
});
it("can render without chat-style chrome for file previews", () => {
@@ -115,8 +127,11 @@ describe("CodeBlock", () => {
expect(screen.queryByTestId("highlighted-code")).not.toBeInTheDocument();
expect(screen.getByTestId("ansi-code")).toBeInTheDocument();
expect(screen.getByTestId("ansi-code").closest(".not-prose")).toBeTruthy();
expect(screen.getByText("ansi")).toBeInTheDocument();
expect(screen.getByTestId("ansi-code").closest(".not-prose")).toHaveAttribute(
"data-language",
"ansi",
);
expect(screen.queryByText("ansi")).not.toBeInTheDocument();
expect(screen.getByText("PASS")).toHaveStyle({ color: "#0dbc79" });
expect(screen.getByText("<script>alert(1)</script>")).toBeInTheDocument();
expect(document.querySelector("script")).toBeNull();
@@ -183,7 +198,7 @@ describe("CodeBlock", () => {
await user.click(screen.getByRole("button", { name: /copy/i }));
await waitFor(() => expect(execCommand).toHaveBeenCalledWith("copy"));
expect(screen.getByText("Copied")).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Copied" })).toBeInTheDocument();
} finally {
Reflect.deleteProperty(navigator, "clipboard");
Reflect.deleteProperty(document, "execCommand");
@@ -163,7 +163,8 @@ describe("MarkdownTextRenderer", () => {
);
expect(screen.getByText("code without language")).toBeInTheDocument();
expect(screen.getByText("text")).toBeInTheDocument();
expect(screen.queryByText("text")).not.toBeInTheDocument();
expect(container.querySelector(".not-prose")).toHaveAttribute("data-language", "text");
expect(container.querySelectorAll("pre")).toHaveLength(1);
});