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

DiffCommentAnnotation.test.tsx

92 lines3.1 KB

1import { renderToStaticMarkup } from "react-dom/server";
2import { describe, expect, it, vi } from "vite-plus/test";
3​
4import { DiffCommentAnnotation } from "./DiffCommentAnnotation";
5​
6const callbacks = {
7 onTextChange: vi.fn(),
8 onCancel: vi.fn(),
9 onComment: vi.fn(),
10 onDelete: vi.fn(),
11};
12​
13describe("DiffCommentAnnotation", () => {
14 it("renders the shared draft composer directly in the selected diff", () => {
15 const markup = renderToStaticMarkup(
16 <DiffCommentAnnotation 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("lets a pull-request diff configure actions without replacing the composer", () => {
35 const markup = renderToStaticMarkup(
36 <DiffCommentAnnotation
37 kind="draft"
38 rangeLabel="src/app.ts:4"
39 text=""
40 {...callbacks}
41 submitLabel="Add to review"
42 secondaryAction={{
43 label: "Ask",
44 icon: <span data-test-icon />,
45 allowEmpty: true,
46 onAction: vi.fn(),
47 }}
48 />,
49 );
50​
51 expect(markup).toContain("Add a comment…");
52 expect(markup).toContain(">Ask</button>");
53 expect(markup).toContain(">Add to review</button>");
54 expect(markup.match(/<button[^>]*disabled[^>]*>Add to review<\/button>/)).not.toBeNull();
55 const askButton = markup.match(/<button[^>]*>.*?Ask<\/button>/)?.[0];
56 expect(askButton).toBeDefined();
57 expect(askButton).not.toContain(' disabled=""');
58 });
59​
60 it("renders a saved comment without a nested card or redundant range label", () => {
61 const markup = renderToStaticMarkup(
62 <DiffCommentAnnotation
63 kind="comment"
64 rangeLabel="+78"
65 text="Please keep this branch explicit."
66 {...callbacks}
67 />,
68 );
69​
70 expect(markup).toContain("font-sans");
71 expect(markup).not.toContain("chat-composer-glass");
72 expect(markup).not.toContain("on +78");
73 expect(markup).toContain("Please keep this branch explicit.");
74 expect(markup).toContain('aria-label="Delete comment"');
75 expect(markup).toContain("border-s-2");
76 expect(markup).toContain("bg-primary/[0.045]");
77 expect(markup).toContain("lucide-message-circle");
78 });
79​
80 it("renders draft text owned by the annotation wrapper", () => {
81 const markup = renderToStaticMarkup(
82 <DiffCommentAnnotation
83 kind="draft"
84 rangeLabel="+78"
85 text="Keep this unsaved draft"
86 {...callbacks}
87 />,
88 );
89​
90 expect(markup).toContain("Keep this unsaved draft");
91 });
92});