fix(webui): open the preset for blocked image input (#6724)

This commit is contained in:
chengyongru authored and GitHub committed 2026-11-19 18:39:00 +08:00
1 parent 607de63fb4
commit ce12bfdd0d
38 files changed
+430 -78

No files matched your search

@@ -88,6 +88,56 @@ beforeEach(() => {
});
describe("ThreadComposer — attachments", () => {
it.each([false, true])("keeps a blocked image draft and opens the preset (active turn: %s)", async (isStreaming) => {
const file = pngFile("screenshot.png");
encodeImage.mockResolvedValueOnce(resolveReady(file));
const onSend = vi.fn();
const onInspectImagePreset = vi.fn();
const renderComposer = (imageInputBlocked: boolean, active = false) => (
<ThreadComposer isStreaming={active} {...{ onSend, imageInputBlocked, onInspectImagePreset }} />
);
const { rerender } = render(renderComposer(true, isStreaming), { wrapper: ToastProvider });
const textarea = screen.getByLabelText(/message input/i);
const input = textarea.closest("form")!.querySelector('input[type="file"]')!;
await act(async () => fireEvent.change(input, { target: { files: [file] } }));
fireEvent.change(textarea, { target: { value: "Please describe this" } });
fireEvent.keyDown(textarea, { key: "Enter" });
expect(screen.getByRole("alert")).toHaveTextContent("Image input is off for this preset");
expect(onSend).not.toHaveBeenCalled();
expect(textarea).toHaveValue("Please describe this");
expect(screen.getByTestId("composer-chip")).toBeVisible();
fireEvent.click(screen.getByRole("button", { name: "View preset" }));
expect(onInspectImagePreset).toHaveBeenCalledOnce();
rerender(renderComposer(false));
fireEvent.keyDown(textarea, { key: "Enter" });
expect(onSend).toHaveBeenCalledWith("Please describe this", [expect.objectContaining({
preview: expect.objectContaining({ name: file.name, kind: "image" }),
})], undefined);
});
it("pauses an already queued image when the next preset cannot process it", async () => {
const file = pngFile("queued.png");
encodeImage.mockResolvedValueOnce(resolveReady(file));
const onSend = vi.fn();
const { rerender } = render(<ThreadComposer isStreaming onSend={onSend} />, { wrapper: ToastProvider });
const textarea = screen.getByLabelText(/message input/i);
const input = textarea.closest("form")!.querySelector('input[type="file"]')!;
await act(async () => fireEvent.change(input, { target: { files: [file] } }));
fireEvent.change(textarea, { target: { value: "Queued with image" } });
fireEvent.keyDown(textarea, { key: "Enter" });
const queue = screen.getByRole("group", { name: "Waiting to send" });
expect(queue).toHaveTextContent("Queued with image");
rerender(<ThreadComposer imageInputBlocked onSend={onSend} />);
expect(await screen.findByRole("alert")).toHaveTextContent("Image input is off for this preset");
expect(onSend).not.toHaveBeenCalled();
fireEvent.click(within(queue).getByRole("button", { name: "Edit message" }));
expect(textarea).toHaveValue("Queued with image");
expect(screen.getByTestId("composer-chip")).toBeVisible();
});
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);
@@ -150,11 +200,11 @@ describe("ThreadComposer — attachments", () => {
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 () => {
it("attaches and sends a PDF even when the preset does not accept images", async () => {
const file = pdfFile();
const onSend = vi.fn();
render(<ThreadComposer onSend={onSend} />);
render(<ThreadComposer onSend={onSend} imageInputBlocked />);
const input = screen
.getByLabelText(/message input/i)