Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

LocalCommentAnnotation.test.tsx

66 lines2.2 KB

1import { renderToStaticMarkup } from "react-dom/server";
2import { describe, expect, it, vi } from "vite-plus/test";
3​
4import { LocalCommentAnnotation } from "./LocalCommentAnnotation";
5​
6const callbacks = {
7 onTextChange: vi.fn(),
8 onCancel: vi.fn(),
9 onComment: vi.fn(),
10 onDelete: vi.fn(),
11};
12​
13describe("LocalCommentAnnotation", () => {
14 it("renders the draft composer directly in the selected diff", () => {
15 const markup = renderToStaticMarkup(
16 <LocalCommentAnnotation kind="draft" rangeLabel="+78" text="" {...callbacks} />,
17 );
18​
19 expect(markup).toContain("font-sans");
20 expect(markup).not.toContain("chat-composer-glass");
21 expect(markup).not.toContain("font-mono");
22 expect(markup).not.toContain("Local comment");
23 expect(markup).not.toContain("on +78");
24 expect(markup).toContain("⌘/Ctrl Enter to send");
25 expect(markup).toContain("Add a comment…");
26 expect(markup).toContain(">Comment</button>");
27 expect(markup).toContain("autofocus");
28 const textareaControl = markup.match(/<span[^>]*data-slot="textarea-control"[^>]*>/)?.[0];
29 expect(textareaControl).toBeDefined();
30 expect(textareaControl).not.toContain("ring-ring");
31 expect(markup).toContain("cursor-text");
32 });
33​
34 it("renders a saved comment without a nested card or redundant range label", () => {
35 const markup = renderToStaticMarkup(
36 <LocalCommentAnnotation
37 kind="comment"
38 rangeLabel="+78"
39 text="Please keep this branch explicit."
40 {...callbacks}
41 />,
42 );
43​
44 expect(markup).toContain("font-sans");
45 expect(markup).not.toContain("chat-composer-glass");
46 expect(markup).not.toContain("on +78");
47 expect(markup).toContain("Please keep this branch explicit.");
48 expect(markup).toContain('aria-label="Delete comment"');
49 expect(markup).toContain("border-s-2");
50 expect(markup).toContain("bg-primary/[0.045]");
51 expect(markup).toContain("lucide-message-circle");
52 });
53​
54 it("renders draft text owned by the annotation wrapper", () => {
55 const markup = renderToStaticMarkup(
56 <LocalCommentAnnotation
57 kind="draft"
58 rangeLabel="+78"
59 text="Keep this unsaved draft"
60 {...callbacks}
61 />,
62 );
63​
64 expect(markup).toContain("Keep this unsaved draft");
65 });
66});