nexus/ui/src/components/ChatMarkdownMessage.test.tsx

39 lines
1.3 KiB
TypeScript

// @vitest-environment node
import { describe, expect, it } from "vitest";
import { renderToStaticMarkup } from "react-dom/server";
import { ChatMarkdownMessage } from "./ChatMarkdownMessage";
describe("ChatMarkdownMessage", () => {
it("renders plain text as a paragraph", () => {
const html = renderToStaticMarkup(
<ChatMarkdownMessage content="Hello world" />,
);
expect(html).toContain("<p>");
expect(html).toContain("Hello world");
});
it("renders fenced code blocks with hljs classes applied by rehype-highlight", () => {
const content = "```typescript\nconst x: number = 42;\n```";
const html = renderToStaticMarkup(
<ChatMarkdownMessage content={content} />,
);
expect(html).toContain("hljs");
});
it("renders a copy button with aria-label='Copy code'", () => {
const content = "```typescript\nconst x = 1;\n```";
const html = renderToStaticMarkup(
<ChatMarkdownMessage content={content} />,
);
expect(html).toContain('aria-label="Copy code"');
});
it("renders a language label extracted from the code fence", () => {
const content = "```typescript\nconst x = 1;\n```";
const html = renderToStaticMarkup(
<ChatMarkdownMessage content={content} />,
);
expect(html).toContain("typescript");
});
});