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

ComposerPreviewAnnotationCards.test.tsx

60 lines1.8 KB

1import 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).toContain('title="1 region"');
41 expect(markup).toContain('title="1 style change"');
42 expect(markup).not.toContain("Welcome");
43 expect(markup).not.toContain("localhost:3000");
44 expect(markup).not.toContain("Preview annotation");
45 });
46​
47 it("uses the shared button contract for removal", () => {
48 const markup = renderToStaticMarkup(
49 <ComposerPreviewAnnotationCards
50 annotations={[annotation]}
51 images={[]}
52 onRemove={vi.fn()}
53 onExpandImage={vi.fn()}
54 />,
55 );
56​
57 expect(markup).toContain('aria-label="Remove preview annotation"');
58 expect(markup).toContain('data-slot="button"');
59 });
60});