Open History to see the last commit
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: "Add to agent",
44 onAction: vi.fn(),
45 }}
46 />,
47 );
48
49 expect(markup).toContain("Add a comment…");
50 expect(markup).toContain(">Add to review</button>");
51 expect(markup.match(/<button[^>]*disabled[^>]*>Add to review<\/button>/)).not.toBeNull();
52 expect(markup.match(/<button[^>]*disabled[^>]*>Add to agent<\/button>/)).not.toBeNull();
53 });
54
55 it("renders a saved comment without a nested card or redundant range label", () => {
56 const markup = renderToStaticMarkup(
57 <DiffCommentAnnotation
58 kind="comment"
59 rangeLabel="+78"
60 text="Please keep this branch explicit."
61 {...callbacks}
62 />,
63 );
64
65 expect(markup).toContain("font-sans");
66 expect(markup).not.toContain("chat-composer-glass");
67 expect(markup).not.toContain("on +78");
68 expect(markup).toContain("Please keep this branch explicit.");
69 expect(markup).toContain('aria-label="Delete comment"');
70 expect(markup).toContain("border-s-2");
71 expect(markup).toContain("bg-primary/[0.045]");
72 expect(markup).toContain("lucide-message-circle");
73 });
74
75 it("renders draft text owned by the annotation wrapper", () => {
76 const markup = renderToStaticMarkup(
77 <DiffCommentAnnotation
78 kind="draft"
79 rangeLabel="+78"
80 text="Keep this unsaved draft"
81 {...callbacks}
82 />,
83 );
84
85 expect(markup).toContain("Keep this unsaved draft");
86 });
87});