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 expect(markup).toMatch(/<span[^>]*data-size="sm"[^>]*data-slot="textarea-control"/);
29 });
30
31 it("lets a pull-request diff configure actions without replacing the composer", () => {
32 const markup = renderToStaticMarkup(
33 <DiffCommentAnnotation
34 kind="draft"
35 rangeLabel="src/app.ts:4"
36 text=""
37 {...callbacks}
38 submitLabel="Add to review"
39 secondaryAction={{
40 label: "Add to agent",
41 onAction: vi.fn(),
42 }}
43 />,
44 );
45
46 expect(markup).toContain("Add a comment…");
47 expect(markup).toContain(">Add to review</button>");
48 expect(markup.match(/<button[^>]*disabled[^>]*>Add to review<\/button>/)).not.toBeNull();
49 expect(markup.match(/<button[^>]*disabled[^>]*>Add to agent<\/button>/)).not.toBeNull();
50 });
51
52 it("renders a saved comment without a nested card or redundant range label", () => {
53 const markup = renderToStaticMarkup(
54 <DiffCommentAnnotation
55 kind="comment"
56 rangeLabel="+78"
57 text="Please keep this branch explicit."
58 {...callbacks}
59 />,
60 );
61
62 expect(markup).toContain("font-sans");
63 expect(markup).not.toContain("chat-composer-glass");
64 expect(markup).not.toContain("on +78");
65 expect(markup).toContain("Please keep this branch explicit.");
66 expect(markup).toContain('aria-label="Delete comment"');
67 expect(markup).toContain("border-s-2");
68 expect(markup).toContain("bg-primary/[0.045]");
69 expect(markup).toContain("lucide-message-circle");
70 });
71
72 it("renders draft text owned by the annotation wrapper", () => {
73 const markup = renderToStaticMarkup(
74 <DiffCommentAnnotation
75 kind="draft"
76 rangeLabel="+78"
77 text="Keep this unsaved draft"
78 {...callbacks}
79 />,
80 );
81
82 expect(markup).toContain("Keep this unsaved draft");
83 });
84});