test(webui): assert code block language fallback

This commit is contained in:
Xubin Ren 2026-05-31 15:15:40 +08:00
parent bdb3a2ded7
commit 15c6abc991
2 changed files with 5 additions and 0 deletions

View File

@ -12,13 +12,16 @@ const mockedStyles = vi.hoisted(() => ({
vi.mock("react-syntax-highlighter/dist/esm/prism-async-light", () => ({
default: ({
children,
language,
style,
}: {
children: string;
language?: string;
style: Record<string, unknown>;
}) => (
<pre
data-testid="highlighted-code"
data-language={language}
data-theme={style === mockedStyles.dark ? "dark" : "light"}
>
<code>{children}</code>
@ -61,6 +64,7 @@ describe("CodeBlock", () => {
});
expect(screen.getByTestId("highlighted-code")).toBeInTheDocument();
expect(screen.getByTestId("highlighted-code")).toHaveAttribute("data-language", "text");
expect(screen.getByText("const value = 1;")).toBeInTheDocument();
});

View File

@ -24,6 +24,7 @@ describe("MarkdownTextRenderer", () => {
);
expect(screen.getByText("code without language")).toBeInTheDocument();
expect(screen.getByText("text")).toBeInTheDocument();
expect(container.querySelectorAll("pre")).toHaveLength(1);
});