-
- {image.kind === "image" && image.previewUrl ? (
-

- ) : (
-
- {image.kind === "image" ? (
-
- ) : image.kind === "video" ? (
-
- ) : (
-
- )}
-
- )}
- {image.status === "encoding" ? (
-
-
-
- ) : null}
-
- {!isThumbnail ? (
-
-
- {image.file.name}
+
+
+
+
-
- {image.status === "error" && image.error
- ? formatError(image.error)
- : sizeLabel}
-
-
- ) : null}
-
+ }>
+ {isThumbnail && image.previewUrl ?
: }
+ {image.status === "encoding" ?
+
+ : null}
+
+ {error ? {error} : null}
);
}
diff --git a/webui/src/lib/image-gallery-layout.ts b/webui/src/lib/image-gallery-layout.ts
new file mode 100644
index 000000000..fbbaff602
--- /dev/null
+++ b/webui/src/lib/image-gallery-layout.ts
@@ -0,0 +1,53 @@
+export interface ImageDimensions {
+ width: number;
+ height: number;
+}
+
+export interface ImageRow {
+ start: number;
+ widths: number[];
+ height: number;
+}
+
+export const IMAGE_GAP = 8;
+
+// Extreme screenshots keep their full content inside a bounded portrait/landscape frame.
+export function imageFrameRatio(image: ImageDimensions | null): number {
+ return image ? Math.max(0.5, Math.min(3, image.width / image.height)) : 1.5;
+}
+
+/** Choose ordered, equal-height rows for the gallery's at most four previews. */
+export function layoutImageRows(
+ images: (ImageDimensions | null)[],
+ width: number,
+ targetHeight: number,
+ maxHeight: number,
+): ImageRow[] {
+ let best: ImageRow[] = [];
+ let bestScore = Infinity;
+ const ratios = images.map(imageFrameRatio);
+
+ function visit(start: number, rows: ImageRow[], score: number) {
+ if (start === images.length) {
+ if (score < bestScore) { best = rows; bestScore = score; }
+ return;
+ }
+ if (rows.length === 2) return;
+ for (let end = start + 1; end <= images.length; end += 1) {
+ const count = end - start;
+ const rowRatios = ratios.slice(start, end);
+ const ratioSum = rowRatios.reduce((sum, ratio) => sum + ratio, 0);
+ const naturalHeight = Math.min(...images.slice(start, end).map((image, i) =>
+ image ? Math.min(image.height, image.width / rowRatios[i]) : maxHeight));
+ const height = Math.min((width - IMAGE_GAP * (count - 1)) / ratioSum, maxHeight, naturalHeight);
+ const widths = rowRatios.map((ratio) => ratio * height);
+ const unusedWidth = (width - ratioSum * height - IMAGE_GAP * (count - 1)) / width;
+ const rowScore = count * (Math.log(height / targetHeight) ** 2 + unusedWidth ** 2) + 0.55;
+ const lonelyLast = end === images.length && count === 1 && images.length > 2 ? 0.25 : 0;
+ visit(end, [...rows, { start, widths, height }], score + rowScore + lonelyLast);
+ }
+ }
+
+ visit(0, [], 0);
+ return best;
+}
diff --git a/webui/src/tests/attachment-tile.test.tsx b/webui/src/tests/attachment-tile.test.tsx
index 5c06a4b02..75be4b7b8 100644
--- a/webui/src/tests/attachment-tile.test.tsx
+++ b/webui/src/tests/attachment-tile.test.tsx
@@ -1,7 +1,12 @@
-import { render, screen } from "@testing-library/react";
-import { describe, expect, it } from "vitest";
+import { render, screen, within } from "@testing-library/react";
+import userEvent from "@testing-library/user-event";
+import { beforeAll, describe, expect, it } from "vitest";
import { AttachmentTile } from "@/components/AttachmentTile";
+import { MessageBubble } from "@/components/MessageBubble";
+import { preloadMarkdownText } from "@/components/MarkdownText";
+
+beforeAll(preloadMarkdownText);
describe("attachment download cards", () => {
it("keeps named download actions distinct and shows the file extension", () => {
@@ -14,9 +19,9 @@ describe("attachment download cards", () => {
expect(archive).toHaveAttribute("download", "猫咪图鉴完整包.zip");
expect(archive).toHaveAttribute("href", "/api/media/signed/archive");
expect(archive).toHaveAttribute("title", "猫咪图鉴完整包.zip");
- expect(archive).toHaveTextContent("ZIP");
+ expect(archive.closest("[data-file-attachment]")).toHaveTextContent("ZIP");
expect(archive.querySelector(".lucide-download")).toHaveAttribute("aria-hidden", "true");
- expect(screen.getByRole("link", { name: "Download source.tar.gz" })).toHaveTextContent("TAR.GZ");
+ expect(screen.getByRole("link", { name: "Download source.tar.gz" }).closest("[data-file-attachment]")).toHaveTextContent("TAR.GZ");
});
it("changes a pending file to a download only after its URL arrives", () => {
@@ -26,7 +31,8 @@ describe("attachment download cards", () => {
expect(screen.queryByRole("link")).not.toBeInTheDocument();
rerender(
);
- expect(screen.getByRole("link", { name: "Download report.pdf" })).toHaveTextContent("PDF");
+ expect(screen.getByRole("link", { name: "Download report.pdf" })).toHaveAttribute("href", "/api/media/signed/report");
+ expect(screen.getByText("PDF")).toBeVisible();
rerender(
);
expect(screen.getByText("Attachment unavailable")).toBeVisible();
@@ -40,8 +46,40 @@ describe("attachment download cards", () => {
>);
const unnamed = screen.getByRole("link", { name: "Download File attachment" });
expect(unnamed).toHaveAttribute("download", "File attachment");
- expect(unnamed).toHaveTextContent("File attachment");
- expect(unnamed.querySelector(".lucide-file-archive")).toBeInTheDocument();
- expect(screen.getByRole("link", { name: "Download LICENSE" })).toHaveTextContent("File attachment");
+ expect(unnamed.closest("[data-file-attachment]")).toHaveTextContent("ZIP");
+ expect(screen.getByRole("link", { name: "Download LICENSE" }).closest("[data-file-attachment]")).toHaveTextContent("File attachment");
+ });
+});
+
+describe("delivered file type cards", () => {
+ it.each(["user", "assistant"] as const)("keeps %s file information and named downloads separate", async (role) => {
+ const user = userEvent.setup();
+ const { container } = render(
);
+ const cards = container.querySelectorAll("[data-file-attachment]");
+ expect(Array.from(cards).map((card) => card.textContent)).toEqual(["JSON", "JSON"]);
+ const first = within(cards[0] as HTMLElement);
+ const download = first.getByRole("link", { name: "Download render-config.json" });
+ expect(download).toHaveAttribute("href", "/api/media/signed/first");
+ expect(download).toHaveAttribute("download", "render-config.json");
+ await user.click(first.getByRole("button", { name: "render-config.json" }));
+ expect(await screen.findByRole("dialog", { name: "render-config.json" })).toHaveTextContent("render-config.json");
+ await user.keyboard("{Escape}");
+ expect(first.getByRole("button", { name: "render-config.json" })).toHaveFocus();
+ expect(within(cards[1] as HTMLElement).getByRole("link", { name: "Download another-config.json" })).toHaveAttribute("href", "/api/media/signed/second");
+ });
+
+ it("keeps a file link inside its paragraph instead of extracting it into an attachment card", async () => {
+ const { container } = render(
);
+ const link = await screen.findByRole("link", { name: "notes.txt" });
+ expect(link.closest("p")).toHaveTextContent("Before notes.txt after.");
+ expect(link).toHaveAttribute("href", "https://example.com/notes.txt");
+ expect(container.querySelectorAll("[data-file-attachment]")).toHaveLength(1);
+ expect(screen.getByRole("link", { name: "Download report.pdf" })).toHaveAttribute("download", "report.pdf");
});
});
diff --git a/webui/src/tests/file-reference-icon.test.tsx b/webui/src/tests/file-reference-icon.test.tsx
index de7dff209..4f0dcb252 100644
--- a/webui/src/tests/file-reference-icon.test.tsx
+++ b/webui/src/tests/file-reference-icon.test.tsx
@@ -1,4 +1,4 @@
-import { fireEvent, render, screen } from "@testing-library/react";
+import { fireEvent, render, screen, within } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { AttachmentTile } from "@/components/AttachmentTile";
@@ -48,30 +48,45 @@ describe("shared file icons", () => {
expect(svg.querySelector("text, [fill], [stroke]")).toBeNull();
});
- it.each(["chart.png", "index.html", "data.json", "script.py", "notes.md", "archive.zip", "report.pdf", "budget.xlsx", "slides.pptx", "song.mp3"])(
- "reuses the same glyph for %s in replies, tabs and attachments without changing actions", (path) => {
+ it.each([
+ ["chart.png", "PNG"],
+ ["index.html", "HTML"],
+ ["data.json", "JSON"],
+ ["script.py", "PY"],
+ ["notes.md", "MD"],
+ ["archive.zip", "ZIP"],
+ ["report.pdf", "PDF"],
+ ["budget.xlsx", "XLSX"],
+ ["slides.pptx", "PPTX"],
+ ["song.mp3", "MP3"],
+ ])(
+ "shares reply and tab glyphs for %s while keeping attachment type cards and actions distinct", (path, type) => {
const open = vi.fn();
- render(<>
+ const references = render(<>
{}} onCloseTab={() => {}}
onClose={() => {}} onResizeStart={() => {}}>Preview
-
>);
- const reference = screen.getByRole("button", { name: path });
- const tab = screen.getByRole("tab", { name: path });
- const attachment = screen.getByRole("link", { name: `Download ${path}` });
+ const attachments = render(
);
+ const reference = within(references.container).getByRole("button", { name: path });
+ const tab = within(references.container).getByRole("tab", { name: path });
+ const information = within(attachments.container).getByRole("button", { name: path });
+ const download = within(attachments.container).getByRole("link", { name: `Download ${path}` });
const glyph = reference.querySelector("svg")!.innerHTML;
expect(tab.querySelector("svg")!.innerHTML).toBe(glyph);
- expect(attachment.querySelector("svg")!.innerHTML).toBe(glyph);
expect(tab.querySelector("svg")).toHaveClass("size-3.5");
- expect(attachment.querySelector("svg")).toHaveClass("size-5");
expect(tab.querySelector("svg")).not.toHaveClass("translate-y-[0.12em]");
- expect(attachment.querySelector("svg")).not.toHaveClass("translate-y-[0.12em]");
- expect(attachment).toHaveAttribute("href", `/download/${path}`);
- expect(attachment).toHaveAttribute("download", path);
+ expect(within(information).getByText(type)).toBeVisible();
+ expect(information.querySelector("svg")).toHaveClass("lucide-file-text");
+ expect(download.querySelector("svg")).toHaveClass("lucide-download", "size-4");
+ expect(download).toHaveAttribute("href", `/download/${path}`);
+ expect(download).toHaveAttribute("download", path);
fireEvent.click(reference);
expect(open).toHaveBeenCalledWith(path);
+ fireEvent.click(information);
+ expect(screen.getByRole("dialog", { name: path })).toHaveTextContent(path);
+ expect(open).toHaveBeenCalledTimes(1);
},
);
@@ -88,10 +103,15 @@ describe("shared file icons", () => {
expect(open).toHaveBeenCalledWith("/repo/src/app.tsx");
});
- it.each(["image", "video"] as const)("retains %s identity when its attachment is unavailable", (kind) => {
- const { container } = render(
);
- expect(container.querySelector("svg")).toHaveClass(kind === "image" ? "lucide-file-image" : "lucide-file-video2");
+ it.each([
+ ["image", "Image attachment"],
+ ["video", "Video attachment"],
+ ] as const)("retains %s identity when its attachment is unavailable", (kind, label) => {
+ render(
);
+ const information = screen.getByRole("button", { name: "Unavailable" });
+ expect(within(information).getByText(label)).toBeVisible();
+ expect(information).toHaveAccessibleDescription("Attachment unavailable");
expect(screen.queryByRole("link")).not.toBeInTheDocument();
- expect(screen.getByText("Attachment unavailable")).toBeInTheDocument();
+ expect(screen.getByText("Attachment unavailable")).toBeVisible();
});
});
diff --git a/webui/src/tests/image-gallery-layout.test.ts b/webui/src/tests/image-gallery-layout.test.ts
new file mode 100644
index 000000000..31d8f7f8e
--- /dev/null
+++ b/webui/src/tests/image-gallery-layout.test.ts
@@ -0,0 +1,57 @@
+import { describe, expect, it } from "vitest";
+
+import { IMAGE_GAP, layoutImageRows } from "@/lib/image-gallery-layout";
+
+const square = { width: 800, height: 800 };
+
+describe("ordered image layout", () => {
+ it("chooses two balanced rows for four square images, rather than a tiny single strip", () => {
+ const rows = layoutImageRows([square, square, square, square], 360, 144, 224);
+ expect(rows.map((row) => row.widths.length)).toEqual([2, 2]);
+ for (const row of rows) {
+ expect(row.height).toBe(176);
+ expect(row.widths).toEqual([176, 176]);
+ }
+ });
+
+ it.each([360, 240])("preserves the order and native proportions of mixed images at %ipx", (width) => {
+ const images = [
+ { width: 1200, height: 800 },
+ { width: 600, height: 900 },
+ square,
+ { width: 1600, height: 900 },
+ ];
+ const rows = layoutImageRows(images, width, 144, 224);
+ let position = 0;
+ for (const row of rows) {
+ expect(row.start).toBe(position);
+ expect(row.height).toBeGreaterThan(0);
+ expect(row.height).toBeLessThanOrEqual(224);
+ expect(row.widths.reduce((sum, item) => sum + item, IMAGE_GAP * (row.widths.length - 1))).toBeLessThanOrEqual(width + 0.001);
+ for (const tileWidth of row.widths) {
+ expect(tileWidth / row.height).toBeCloseTo(images[position].width / images[position].height);
+ position += 1;
+ }
+ }
+ expect(position).toBe(images.length);
+ expect(rows.length).toBeLessThanOrEqual(2);
+ });
+
+ it("fits a single portrait without stretching it into a square or exceeding the height limit", () => {
+ const [row] = layoutImageRows([{ width: 600, height: 900 }], 360, 144, 320);
+ expect(row.height).toBe(320);
+ expect(row.widths[0]).toBeCloseTo(320 * 2 / 3);
+ });
+
+ it("does not enlarge a small image beyond its original resolution", () => {
+ const [row] = layoutImageRows([{ width: 48, height: 32 }], 360, 144, 320);
+ expect(row).toEqual({ start: 0, widths: [48], height: 32 });
+ });
+
+ it("gives extreme screenshots a bounded frame instead of a nearly invisible sliver", () => {
+ const [long] = layoutImageRows([{ width: 600, height: 4800 }], 360, 144, 320);
+ const [wide] = layoutImageRows([{ width: 4800, height: 600 }], 360, 144, 320);
+ expect(long).toEqual({ start: 0, widths: [160], height: 320 });
+ expect(wide).toEqual({ start: 0, widths: [360], height: 120 });
+ });
+});
diff --git a/webui/src/tests/image-gallery.test.tsx b/webui/src/tests/image-gallery.test.tsx
index 151f6058b..c77733359 100644
--- a/webui/src/tests/image-gallery.test.tsx
+++ b/webui/src/tests/image-gallery.test.tsx
@@ -70,13 +70,60 @@ describe("image presentation", () => {
expect(within(screen.getByRole("dialog")).getByRole("img", { name: "0.png" })).toBeVisible();
});
- it("replaces a broken thumbnail with a quiet named placeholder", () => {
+ it("shows an explicit failure without painting a filename across the thumbnail", () => {
render(
);
fireEvent.error(screen.getByRole("img"));
- expect(screen.queryByRole("img")).not.toBeInTheDocument();
- expect(screen.getByText("0.png")).toBeVisible();
+ expect(screen.getByText("Attachment unavailable")).toBeVisible();
+ expect(screen.getByLabelText("Attachment unavailable: 0.png")).toHaveAttribute("title", "0.png");
+ expect(screen.queryByText("0.png")).not.toBeInTheDocument();
expect(screen.queryByRole("button")).not.toBeInTheDocument();
});
+
+ it("uses the loaded picture's shape for a sent user image and retains its accessible viewer action", async () => {
+ const user = userEvent.setup();
+ render(
);
+ const image = screen.getByRole("img", { name: "portrait.png" });
+ Object.defineProperties(image, { naturalWidth: { value: 600 }, naturalHeight: { value: 900 } });
+ fireEvent.load(image);
+ const open = screen.getByRole("button", { name: "View image: portrait.png" });
+ expect(Number.parseFloat(open.style.width)).toBeCloseTo(320 * 2 / 3);
+ expect(open.style.height).toBe("320px");
+ expect(screen.queryByText("portrait.png")).not.toBeInTheDocument();
+ await user.click(open);
+ expect(within(screen.getByRole("dialog")).getByRole("img", { name: "portrait.png" })).toBeVisible();
+ });
+
+ it("settles a mixed gallery together after loading and preserves click order through regrouping", async () => {
+ const user = userEvent.setup();
+ const { container } = render(
);
+ for (const image of screen.getAllByRole("img")) {
+ Object.defineProperties(image, { naturalWidth: { value: 800 }, naturalHeight: { value: 800 } });
+ fireEvent.load(image);
+ }
+ const tiles = Array.from(container.querySelectorAll
("[data-image-gallery] > button"));
+ expect(tiles.map((tile) => Number.parseFloat(tile.style.top))).toEqual([0, 0, 184, 184]);
+ expect(screen.getAllByRole("button").map((button) => button.getAttribute("aria-label"))).toEqual(
+ [0, 1, 2, 3].map((index) => `View image: ${index}.png`));
+ await user.click(screen.getByRole("button", { name: "View image: 2.png" }));
+ expect(screen.getByText("3 / 4")).toBeVisible();
+ expect(within(screen.getByRole("dialog")).getByRole("img", { name: "2.png" })).toBeVisible();
+ });
+
+ it("returns focus to the same thumbnail when late image loads change the row grouping", async () => {
+ const user = userEvent.setup();
+ const { container } = render();
+ const thumbnails = container.querySelectorAll("[data-image-gallery] img");
+ const opener = screen.getByRole("button", { name: "View image: 2.png" });
+ await user.click(opener);
+ for (const image of thumbnails) {
+ Object.defineProperties(image, { naturalWidth: { value: 600 }, naturalHeight: { value: 900 } });
+ fireEvent.load(image);
+ }
+ await user.keyboard("{Escape}");
+ expect(screen.getByRole("button", { name: "View image: 2.png" })).toBe(opener);
+ expect(opener).toHaveFocus();
+ });
});
describe("file quick look", () => {
diff --git a/webui/src/tests/markdown-text-renderer.test.tsx b/webui/src/tests/markdown-text-renderer.test.tsx
index 529f69e20..89dad6bfe 100644
--- a/webui/src/tests/markdown-text-renderer.test.tsx
+++ b/webui/src/tests/markdown-text-renderer.test.tsx
@@ -294,7 +294,8 @@ describe("MarkdownTextRenderer", () => {
it("renders markdown links with file-looking names as file attachments", () => {
render();
- expect(screen.getByRole("link", { name: "Download index.html" })).toHaveTextContent("index.html");
+ expect(screen.getByRole("link", { name: "Download index.html" })).toHaveAttribute("download", "index.html");
+ expect(screen.getByRole("button", { name: "index.html" })).toBeVisible();
expect(screen.queryByRole("img", { name: "index.html" })).not.toBeInTheDocument();
});
diff --git a/webui/src/tests/message-bubble.test.tsx b/webui/src/tests/message-bubble.test.tsx
index 1521d4bd6..3b4a26398 100644
--- a/webui/src/tests/message-bubble.test.tsx
+++ b/webui/src/tests/message-bubble.test.tsx
@@ -1238,18 +1238,15 @@ describe("MessageBubble", () => {
const { container } = render();
+ const image = container.querySelector("img")!;
+ Object.defineProperties(image, { naturalWidth: { value: 1600 }, naturalHeight: { value: 900 } });
+ fireEvent.load(image);
const imageButton = screen.getByRole("button", { name: /view image/i });
- expect(imageButton).toHaveClass("w-[min(100%,28rem)]", "rounded-control");
- expect(imageButton).toHaveClass(
- "border",
- "border-border/60",
- "focus-visible:ring-2",
- );
- expect(imageButton).not.toHaveClass("hover:scale-[1.01]");
- expect(imageButton).not.toHaveClass("hover:ring-2");
- expect(imageButton).not.toHaveClass("hover:ring-primary/25");
+ expect(imageButton).toHaveClass("rounded-control", "focus-visible:ring-2");
+ expect(imageButton.style.width).toBe("448px");
+ expect(imageButton.style.height).toBe("252px");
expect(imageButton).not.toHaveAttribute("title");
- expect(container.querySelector("img")).toHaveClass("h-auto", "w-full", "object-contain");
+ expect(image).toHaveClass("object-contain");
});
it("renders mislabeled html assistant media as a file attachment", () => {
@@ -1269,7 +1266,8 @@ describe("MessageBubble", () => {
const { container } = render();
- expect(screen.getByRole("link", { name: "Download index.html" })).toHaveTextContent("index.html");
+ expect(screen.getByRole("link", { name: "Download index.html" })).toHaveAttribute("download", "index.html");
+ expect(screen.getByRole("button", { name: "index.html" })).toBeVisible();
expect(container.querySelector("img")).not.toBeInTheDocument();
});
diff --git a/webui/src/tests/thread-composer-attach.test.tsx b/webui/src/tests/thread-composer-attach.test.tsx
index 3d57f9529..5127ef263 100644
--- a/webui/src/tests/thread-composer-attach.test.tsx
+++ b/webui/src/tests/thread-composer-attach.test.tsx
@@ -4,7 +4,9 @@ import {
render,
screen,
waitFor,
+ within,
} from "@testing-library/react";
+import userEvent from "@testing-library/user-event";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { ThreadComposer } from "@/components/thread/ThreadComposer";
@@ -87,6 +89,7 @@ beforeEach(() => {
describe("ThreadComposer — attachments", () => {
it("previews a picked image with size details on hover and includes its data url on send", async () => {
+ const user = userEvent.setup();
const file = pngFile("a.png", 100);
encodeImage.mockResolvedValueOnce({ ...resolveReady(file), normalized: true, bytes: 50 });
const onSend = vi.fn();
@@ -103,7 +106,10 @@ describe("ThreadComposer — attachments", () => {
});
expect(screen.getByRole("img", { name: "a.png" })).toHaveAttribute("src", expect.stringContaining("blob:"));
- expect(screen.getByTestId("composer-chip")).toHaveAttribute("title", "a.png\n100 B → 50 B (auto)");
+ await user.hover(screen.getByRole("button", { name: "a.png" }));
+ const details = await screen.findByRole("tooltip");
+ expect(details).toHaveTextContent("a.png");
+ expect(details).toHaveTextContent("100 B → 50 B (auto)");
expect(screen.getByRole("button", { name: "Remove attachment" })).toHaveAccessibleDescription("a.png");
const textarea = screen.getByLabelText(/message input/i);
@@ -118,6 +124,32 @@ describe("ThreadComposer — attachments", () => {
expect(images[0].media.name).toBe("a.png");
});
+ it("identifies same-type files through focus/tap details and removes only the chosen attachment", async () => {
+ const user = userEvent.setup();
+ const first = new File(['{"theme":"light"}'], "render-config.json", { type: "application/json" });
+ const second = new File(['{"theme":"dark"}'], "another-config.json", { type: "application/json" });
+ const onSend = vi.fn();
+ render();
+ const textarea = screen.getByLabelText(/message input/i);
+ const input = textarea.closest("form")!.querySelector('input[type="file"]')!;
+ await act(async () => fireEvent.change(input, { target: { files: [first, second] } }));
+ const cards = screen.getAllByTestId("composer-chip");
+ expect(cards.map((card) => card.textContent)).toEqual(["JSON", "JSON"]);
+ const firstInfo = within(cards[0]).getByRole("button", { name: first.name });
+ act(() => firstInfo.focus());
+ expect(await screen.findByRole("tooltip")).toHaveTextContent(first.name);
+ expect(screen.getByRole("tooltip")).toHaveTextContent(`${first.size} B`);
+ await user.keyboard("{Escape}");
+ await user.click(within(cards[1]).getByRole("button", { name: second.name }));
+ expect(await screen.findByRole("dialog", { name: second.name })).toHaveTextContent(second.name);
+ await user.keyboard("{Escape}");
+ await user.click(within(cards[1]).getByRole("button", { name: "Remove attachment" }));
+ expect(screen.getAllByTestId("composer-chip")).toHaveLength(1);
+ expect(screen.getByRole("button", { name: first.name })).toBeVisible();
+ fireEvent.keyDown(textarea, { key: "Enter" });
+ expect(onSend.mock.calls[0][1].map((attachment: { media: { name: string } }) => attachment.media.name)).toEqual([first.name]);
+ });
+
it("attaches a picked PDF and includes its data url on send", async () => {
const file = pdfFile();
const onSend = vi.fn();
@@ -134,7 +166,7 @@ describe("ThreadComposer — attachments", () => {
});
await waitFor(() =>
- expect(screen.getByTestId("composer-chip")).toHaveTextContent("report.pdf"),
+ expect(screen.getByTestId("composer-chip")).toHaveTextContent("PDF"),
);
const textarea = screen.getByLabelText(/message input/i);
@@ -168,7 +200,7 @@ describe("ThreadComposer — attachments", () => {
});
await waitFor(() =>
- expect(screen.getByTestId("composer-chip")).toHaveTextContent("report.csv"),
+ expect(screen.getByRole("button", { name: "report.csv" })).toHaveAccessibleDescription(expect.stringContaining("B")),
);
const textarea = screen.getByLabelText(/message input/i);
@@ -242,8 +274,8 @@ describe("ThreadComposer — attachments", () => {
expect(screen.queryByRole("alert")).not.toBeInTheDocument();
expect(screen.getAllByTestId("composer-chip")).toHaveLength(2);
- expect(screen.getByText("first.pdf")).toBeInTheDocument();
- expect(screen.getByText("second.pdf")).toBeInTheDocument();
+ expect(screen.getByRole("button", { name: "first.pdf" })).toBeInTheDocument();
+ expect(screen.getByRole("button", { name: "second.pdf" })).toBeInTheDocument();
});
it("enforces the decoded attachment-total policy independently", async () => {
@@ -317,7 +349,7 @@ describe("ThreadComposer — attachments", () => {
});
await waitFor(() =>
- expect(screen.getByText("pasted.pdf")).toBeInTheDocument(),
+ expect(screen.getByRole("button", { name: "pasted.pdf" })).toBeInTheDocument(),
);
await act(async () => {
@@ -332,7 +364,7 @@ describe("ThreadComposer — attachments", () => {
});
await waitFor(() =>
- expect(screen.getByText("dropped.pdf")).toBeInTheDocument(),
+ expect(screen.getByRole("button", { name: "dropped.pdf" })).toBeInTheDocument(),
);
expect(screen.getAllByTestId("composer-chip")).toHaveLength(2);
expect(encodeImage).not.toHaveBeenCalled();
@@ -421,7 +453,7 @@ describe("local attachment paths and video ingress", () => {
fireEvent.change(input, { target: { value: "keep this " } });
(input as HTMLTextAreaElement).setSelectionRange(10, 10);
fireEvent.paste(input, { clipboardData: { items: [], getData: () => '"C:\\project\\my clip.mp4"' } });
- await waitFor(() => expect(screen.getByTestId("composer-chip")).toHaveTextContent("my clip.mp4"));
+ await waitFor(() => expect(screen.getByRole("button", { name: "my clip.mp4" })).toBeInTheDocument());
expect(input).toHaveValue("keep this ");
expect(inspect).toHaveBeenCalledWith(local.path);
fireEvent.keyDown(input, { key: "Enter" });
@@ -568,7 +600,7 @@ describe("local attachment paths and video ingress", () => {
render();
const input = screen.getByLabelText(/message input/i);
fireEvent.paste(input, { clipboardData: { items: [], getData: () => document.path } });
- await screen.findByText(document.name);
+ await screen.findByRole("button", { name: document.name });
const picker = input.closest("form")!.querySelector('input[type="file"]')!;
fireEvent.change(picker, { target: { files: [pdfFile("upload.pdf", 8)] } });
await waitFor(() => expect(screen.getByRole("button", { name: /send message/i })).toBeEnabled());
diff --git a/webui/src/tests/thread-messages.test.tsx b/webui/src/tests/thread-messages.test.tsx
index 18c817dda..dc5990228 100644
--- a/webui/src/tests/thread-messages.test.tsx
+++ b/webui/src/tests/thread-messages.test.tsx
@@ -2022,9 +2022,14 @@ describe("ThreadMessages", () => {
});
render();
- expect(screen.getByText("result.csv")).toBeInTheDocument();
- const ownerRow = screen.getByText("result.csv")
- .closest("[data-thread-display-unit]")!;
+ const information = screen.getByRole("button", { name: "result.csv" });
+ const download = screen.getByRole("link", { name: "Download result.csv" });
+ expect(information).toBeVisible();
+ expect(download).toHaveAttribute("href", "/api/media/result.csv");
+ expect(download).toHaveAttribute("download", "result.csv");
+ expect(download.closest("[data-testid='activity-model-message'], [data-testid='agent-activity-content']")).toBeNull();
+ const ownerRow = information.closest("[data-thread-display-unit]")!;
+ expect(ownerRow).toContainElement(download);
openAssistantBlockMenu(ownerRow);
expect(screen.getByRole("button", { name: "Worked" })).toBeInTheDocument();
});
diff --git a/webui/src/tests/thread-shell.test.tsx b/webui/src/tests/thread-shell.test.tsx
index b8c7997ad..947b6725e 100644
--- a/webui/src/tests/thread-shell.test.tsx
+++ b/webui/src/tests/thread-shell.test.tsx
@@ -593,9 +593,12 @@ describe("ThreadShell", () => {
await waitFor(() => expect(onCreateChat).toHaveBeenCalledTimes(1));
view.rerender(shell("created"));
await waitFor(() => expect(screen.getByRole("textbox")).toHaveValue("keep the first draft"));
- expect(await screen.findByTestId("composer-chip")).toHaveTextContent("video.mp4");
+ expect(within(await screen.findByTestId("composer-chip")).getByRole("button", { name: "video.mp4" })).toBeVisible();
expect(screen.getByRole("alert")).toHaveTextContent("file not found");
- expect(store.get("websocket:created")?.attachments).toHaveLength(1);
+ expect(store.get("websocket:created")).toMatchObject({
+ text: "keep the first draft",
+ attachments: [{ path: "/project/video.mp4", name: "video.mp4", kind: "video" }],
+ });
expect(store.has("new:chat")).toBe(false);
client.sendAttachments.mockResolvedValue(undefined);
fireEvent.click(screen.getByRole("button", { name: "Send message" }));