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

ComposerPreviewAnnotationCards.test.tsx

91 lines2.8 KB

1import { EnvironmentId, type PreviewAnnotationPayload } from "@t3tools/contracts";
2import { renderToStaticMarkup } from "react-dom/server";
3import { describe, expect, it, vi } from "vite-plus/test";
4​
5import { ComposerPreviewAnnotationCards } from "./ComposerPreviewAnnotationCards";
6​
7const annotation: PreviewAnnotationPayload = {
8 id: "annotation_1",
9 pageUrl: "http://localhost:3000/welcome",
10 pageTitle: "Welcome",
11 comment: "Make this headline feel intentional.",
12 elements: [],
13 regions: [{ id: "region_1", rect: { x: 1, y: 2, width: 30, height: 20 } }],
14 strokes: [],
15 styleChanges: [
16 {
17 targetId: "element_1",
18 selector: "h1",
19 property: "font-size",
20 previousValue: "32px",
21 value: "40px",
22 },
23 ],
24 screenshot: null,
25 createdAt: "2026-06-13T00:00:00.000Z",
26};
27​
28describe("ComposerPreviewAnnotationCards", () => {
29 it("presents the annotation as one contextual attachment", () => {
30 const markup = renderToStaticMarkup(
31 <ComposerPreviewAnnotationCards
32 annotations={[annotation]}
33 images={[]}
34 onRemove={vi.fn()}
35 onExpandImage={vi.fn()}
36 />,
37 );
38​
39 expect(markup).toContain("Make this headline feel intentional.");
40 expect(markup.match(/data-slot="tooltip-trigger"/g)).toHaveLength(2);
41 expect(markup).not.toContain('title="1 region"');
42 expect(markup).not.toContain('title="1 style change"');
43 expect(markup).not.toContain("Welcome");
44 expect(markup).not.toContain("localhost:3000");
45 expect(markup).not.toContain("Preview annotation");
46 });
47​
48 it("uses the shared button contract for removal", () => {
49 const markup = renderToStaticMarkup(
50 <ComposerPreviewAnnotationCards
51 annotations={[annotation]}
52 images={[]}
53 onRemove={vi.fn()}
54 onExpandImage={vi.fn()}
55 />,
56 );
57​
58 expect(markup).toContain('aria-label="Remove preview annotation"');
59 expect(markup).toContain('data-slot="button"');
60 });
61​
62 it("shows a retry action for a failed screenshot upload", () => {
63 const image = {
64 type: "image" as const,
65 id: annotation.id,
66 name: "annotation.png",
67 mimeType: "image/png",
68 sizeBytes: 3,
69 previewUrl: "blob:annotation",
70 file: new File([new Uint8Array([1, 2, 3])], "annotation.png", { type: "image/png" }),
71 };
72 const markup = renderToStaticMarkup(
73 <ComposerPreviewAnnotationCards
74 annotations={[annotation]}
75 images={[image]}
76 uploadsByImageId={{
77 [image.id]: {
78 status: "failed",
79 environmentId: EnvironmentId.make("environment-1"),
80 reason: "Upload rejected",
81 },
82 }}
83 onRetryUpload={vi.fn()}
84 onRemove={vi.fn()}
85 onExpandImage={vi.fn()}
86 />,
87 );
88​
89 expect(markup).toContain('aria-label="Retry upload for annotation.png"');
90 });
91});