feat(webui): refine attachment galleries and file cards (#6457)

* feat(webui): refine attachment galleries and file cards

* fix(webui): align attachment tests and Escape handling
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-25 22:39:44 +08:00
1 parent 44a7ef53ce
commit eed7b47753
19 files changed
+660 -255

No files matched your search

+46 -8
View File
@@ -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(<AttachmentTile attachment={{ ...attachment, url: "/api/media/signed/report" }} />);
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(<AttachmentTile attachment={attachment} />);
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(<MessageBubble message={{ id: `files-${role}`, role, content: "Files ready", createdAt: 1,
media: [
{ kind: "file", name: "render-config.json", url: "/api/media/signed/first" },
{ kind: "file", name: "another-config.json", url: "/api/media/signed/second" },
] }} />);
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(<MessageBubble message={{ id: "inline-file", role: "assistant", createdAt: 1,
content: "Before [notes.txt](https://example.com/notes.txt) after.",
media: [{ kind: "file", name: "report.pdf", url: "/api/media/signed/report" }] }} />);
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");
});
});
+37 -17
View File
@@ -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(<>
<FileReferenceChip path={path} onOpen={open} />
<PreviewPane tabs={[{ id: path, value: path }]} activeId={path}
width={544} isClosing={false} onSelect={() => {}} onCloseTab={() => {}}
onClose={() => {}} onResizeStart={() => {}}><p>Preview</p></PreviewPane>
<AttachmentTile attachment={{ kind: "file", name: path, url: `/download/${path}` }} />
</>);
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(<AttachmentTile attachment={{ kind: "file", name: path, url: `/download/${path}` }} />);
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(<AttachmentTile attachment={{ kind, name: "Unavailable" }} />);
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(<AttachmentTile attachment={{ kind, name: "Unavailable" }} />);
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();
});
});
@@ -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 });
});
});
+50 -3
View File
@@ -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(<ImageGallery images={[images[0]]} />);
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(<MessageBubble message={{ id: "portrait", role: "user", content: "", createdAt: 1,
images: [{ url: "/portrait.png", name: "portrait.png" }] }} />);
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(<ImageGallery images={images.slice(0, 4)} size="compact" />);
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<HTMLElement>("[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(<ImageGallery images={images.slice(0, 4)} size="compact" />);
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", () => {
@@ -294,7 +294,8 @@ describe("MarkdownTextRenderer", () => {
it("renders markdown links with file-looking names as file attachments", () => {
render(<MarkdownTextRenderer>![index.html](/api/media/sig/html)</MarkdownTextRenderer>);
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();
});
+9 -11
View File
@@ -1238,18 +1238,15 @@ describe("MessageBubble", () => {
const { container } = render(<MessageBubble message={message} />);
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(<MessageBubble message={message} />);
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();
});
@@ -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(<ThreadComposer onSend={onSend} />);
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(<ThreadComposer onSend={onSend} onInspectAttachment={vi.fn().mockResolvedValue(document)} ingressLimits={ingressLimits({ maxFileBytes: 8, maxTotalBytes: 8 })} />);
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());
+8 -3
View File
@@ -2022,9 +2022,14 @@ describe("ThreadMessages", () => {
});
render(<ThreadMessages messages={messages} isStreaming={false} />);
expect(screen.getByText("result.csv")).toBeInTheDocument();
const ownerRow = screen.getByText("result.csv")
.closest<HTMLElement>("[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<HTMLElement>("[data-thread-display-unit]")!;
expect(ownerRow).toContainElement(download);
openAssistantBlockMenu(ownerRow);
expect(screen.getByRole("button", { name: "Worked" })).toBeInTheDocument();
});
+5 -2
View File
@@ -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" }));