Files
t3code/apps/web/src/components/diffs/DiffCommentAnnotation.test.tsx
T
cad2c93616 feat: multi-provider pull requests page with in-app reviews (#4849)
Co-authored-by: Julius Marminge <[email protected]>
Co-authored-by: Claude Fable 5 <[email protected]>
Co-authored-by: maria <[email protected]>
Co-authored-by: maria-rcks <[email protected]>
Co-authored-by: codex <[email protected]>
2026-08-10 17:47:02 +02:00

93 lines
3.1 KiB
TypeScript

import { renderToStaticMarkup } from "react-dom/server";
import { describe, expect, it, vi } from "vite-plus/test";
import { DiffCommentAnnotation } from "./DiffCommentAnnotation";
const callbacks = {
onTextChange: vi.fn(),
onCancel: vi.fn(),
onComment: vi.fn(),
onDelete: vi.fn(),
};
describe("DiffCommentAnnotation", () => {
it("renders the shared draft composer directly in the selected diff", () => {
const markup = renderToStaticMarkup(
<DiffCommentAnnotation kind="draft" rangeLabel="+78" text="" {...callbacks} />,
);
expect(markup).toContain("font-sans");
expect(markup).not.toContain("chat-composer-glass");
expect(markup).not.toContain("font-mono");
expect(markup).not.toContain("Local comment");
expect(markup).not.toContain("on +78");
expect(markup).toContain("⌘/Ctrl Enter to send");
expect(markup).toContain("Add a comment…");
expect(markup).toContain(">Comment</button>");
expect(markup).toContain("autofocus");
const textareaControl = markup.match(/<span[^>]*data-slot="textarea-control"[^>]*>/)?.[0];
expect(textareaControl).toBeDefined();
expect(textareaControl).not.toContain("ring-ring");
expect(markup).toContain("cursor-text");
});
it("lets a pull-request diff configure actions without replacing the composer", () => {
const markup = renderToStaticMarkup(
<DiffCommentAnnotation
kind="draft"
rangeLabel="src/app.ts:4"
text=""
{...callbacks}
submitLabel="Add to review"
secondaryAction={{
label: "Ask",
icon: <span data-test-icon />,
allowEmpty: true,
onAction: vi.fn(),
}}
/>,
);
expect(markup).toContain("Add a comment…");
expect(markup).toContain(">Ask</button>");
expect(markup).toContain(">Add to review</button>");
expect(markup.match(/<button[^>]*disabled[^>]*>Add to review<\/button>/)).not.toBeNull();
const askButton = markup.match(/<button[^>]*>.*?Ask<\/button>/)?.[0];
expect(askButton).toBeDefined();
expect(askButton).not.toContain(' disabled=""');
});
it("renders a saved comment without a nested card or redundant range label", () => {
const markup = renderToStaticMarkup(
<DiffCommentAnnotation
kind="comment"
rangeLabel="+78"
text="Please keep this branch explicit."
{...callbacks}
/>,
);
expect(markup).toContain("font-sans");
expect(markup).not.toContain("chat-composer-glass");
expect(markup).not.toContain("on +78");
expect(markup).toContain("Please keep this branch explicit.");
expect(markup).toContain('aria-label="Delete comment"');
expect(markup).toContain("border-s-2");
expect(markup).toContain("bg-primary/[0.045]");
expect(markup).toContain("lucide-message-circle");
});
it("renders draft text owned by the annotation wrapper", () => {
const markup = renderToStaticMarkup(
<DiffCommentAnnotation
kind="draft"
rangeLabel="+78"
text="Keep this unsaved draft"
{...callbacks}
/>,
);
expect(markup).toContain("Keep this unsaved draft");
});
});