-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathChatCodePreviewCard.test.tsx
More file actions
58 lines (49 loc) · 1.76 KB
/
ChatCodePreviewCard.test.tsx
File metadata and controls
58 lines (49 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import type { ReactElement } from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { describe, expect, it } from "vitest";
import { buildStreamingCodePreviewMeta } from "~/lib/chatCodePreview";
import { ChatCodePreviewCard } from "./ChatCodePreviewCard";
function renderCard(element: ReactElement) {
return renderToStaticMarkup(element);
}
describe("ChatCodePreviewCard", () => {
it("renders a live status line for streaming previews", () => {
const meta = buildStreamingCodePreviewMeta({
className: "language-typescript",
code: "export const answer = 42;\n",
isStreaming: true,
highlightFailed: false,
});
const markup = renderCard(
<ChatCodePreviewCard code="export const answer = 42;\n" meta={meta} isStreaming>
<pre>
<code>export const answer = 42;</code>
</pre>
</ChatCodePreviewCard>,
);
expect(markup).toContain("Streaming code preview");
expect(markup).toContain("TypeScript");
expect(markup).toContain("1 line");
expect(markup).toContain("Live");
expect(markup).toContain("Copy code");
});
it("renders fallback status when highlighting is unavailable", () => {
const meta = buildStreamingCodePreviewMeta({
className: "language-bash",
code: "bun typecheck",
isStreaming: false,
highlightFailed: true,
});
const markup = renderCard(
<ChatCodePreviewCard code="bun typecheck" meta={meta} isStreaming={false}>
<pre>
<code>bun typecheck</code>
</pre>
</ChatCodePreviewCard>,
);
expect(markup).toContain("Preview unavailable, showing plain code");
expect(markup).toContain("Bash");
expect(markup).toContain("1 line");
expect(markup).toContain("bun typecheck");
});
});