Open History to see the last commit
1import { renderToStaticMarkup } from "react-dom/server";
2import { EnvironmentId } from "@t3tools/contracts";
3import { describe, expect, it } from "vite-plus/test";
4
5import { ComposerStashMenu } from "./ComposerStashMenu";
6
7describe("ComposerStashMenu", () => {
8 it("renders saved prompts as an attached composer drawer", () => {
9 const markup = renderToStaticMarkup(
10 <ComposerStashMenu
11 entries={[]}
12 stashShortcutLabel="Ctrl+S"
13 onRestore={() => {}}
14 onDelete={() => {}}
15 onClose={() => {}}
16 />,
17 );
18
19 expect(markup).toContain('data-composer-stash-drawer="true"');
20 expect(markup).toContain("chat-composer-drawer-surface");
21 expect(markup).toContain("chat-composer-drawer-attached");
22 expect(markup).toContain('aria-label="Close stash"');
23 expect(markup).not.toContain("dropdown-glass");
24 expect(markup).not.toContain("Stashed prompts");
25 expect(markup).toContain("Press Ctrl+S with a prompt in the composer to stash it.");
26 });
27
28 it("does not advertise a shortcut when stash is unbound", () => {
29 const markup = renderToStaticMarkup(
30 <ComposerStashMenu
31 entries={[]}
32 stashShortcutLabel={null}
33 onRestore={() => {}}
34 onDelete={() => {}}
35 onClose={() => {}}
36 />,
37 );
38
39 expect(markup).toContain("Nothing stashed yet.");
40 expect(markup).not.toContain("Press");
41 });
42
43 it("shows saved image thumbnails and incomplete image states", () => {
44 const markup = renderToStaticMarkup(
45 <ComposerStashMenu
46 entries={[
47 {
48 id: "with-images",
49 createdAt: new Date(0).toISOString(),
50 prompt: "Compare these screenshots",
51 attachments: [
52 {
53 id: "image-one",
54 name: "before.png",
55 mimeType: "image/png",
56 sizeBytes: 128,
57 dataUrl: "data:image/png;base64,AA==",
58 },
59 ],
60 droppedImageNames: ["after.png"],
61 unreadableImageNames: [],
62 pendingImageCount: 0,
63 },
64 {
65 id: "saving-images",
66 createdAt: new Date(0).toISOString(),
67 prompt: "Save this image",
68 attachments: [],
69 droppedImageNames: [],
70 unreadableImageNames: [],
71 pendingImageCount: 1,
72 },
73 ]}
74 stashShortcutLabel="Ctrl+S"
75 onRestore={() => {}}
76 onDelete={() => {}}
77 onClose={() => {}}
78 />,
79 );
80
81 expect(markup).toContain('src="data:image/png;base64,AA=="');
82 expect(markup).toContain("1 image dropped");
83 expect(markup).toContain("saving 1 image");
84 expect(markup).not.toContain("absolute top-1/2 right-2");
85 expect(markup).toContain("pointer-events-none");
86 expect(markup).toContain("pointer-coarse:pointer-events-auto");
87 expect(markup).toContain("pointer-coarse:opacity-100");
88 expect(markup).not.toContain("bg-popover!");
89 expect(markup).toContain("[--control-icon-color:currentColor]");
90 expect(markup).toContain("size-3.5 stroke-2");
91 expect(markup).not.toContain("bg-background/90");
92 });
93
94 it("labels mixed file and image stashes without treating images as files", () => {
95 const markup = renderToStaticMarkup(
96 <ComposerStashMenu
97 entries={[
98 {
99 id: "mixed-attachments",
100 createdAt: new Date(0).toISOString(),
101 prompt: "",
102 attachments: [
103 {
104 id: "image-one",
105 name: "before.png",
106 mimeType: "image/png",
107 sizeBytes: 128,
108 dataUrl: "data:image/png;base64,AA==",
109 },
110 ],
111 files: [
112 {
113 id: "file-one",
114 name: "report.pdf",
115 mimeType: "application/pdf",
116 sizeBytes: 42,
117 attachmentId: "pending-report-pdf",
118 environmentId: EnvironmentId.make("environment-1"),
119 },
120 ],
121 droppedImageNames: [],
122 },
123 ]}
124 stashShortcutLabel={null}
125 onRestore={() => {}}
126 onDelete={() => {}}
127 onClose={() => {}}
128 />,
129 );
130
131 expect(markup).toContain("(2 attachments)");
132 expect(markup).toContain("size-3.5 text-secondary-label");
133 expect(markup).not.toContain("(2 files)");
134 });
135});