mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-03-22 13:47:19 +08:00
Fix issue #5341: [Bug]: When an image is attached in the chat, the chat text is not cleared
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { render, screen, within } from "@testing-library/react";
|
||||
import { render, screen, within, fireEvent } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
|
||||
import { InteractiveChatBox } from "#/components/interactive-chat-box";
|
||||
@@ -98,6 +98,33 @@ describe("InteractiveChatBox", () => {
|
||||
expect(screen.queryAllByTestId("image-preview")).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("should clear text input after submitting with images via paste", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<InteractiveChatBox onSubmit={onSubmitMock} onStop={onStopMock} />);
|
||||
|
||||
const textarea = within(screen.getByTestId("chat-input")).getByRole(
|
||||
"textbox",
|
||||
);
|
||||
await user.type(textarea, "Hello, world!");
|
||||
|
||||
const file = new File(["(⌐□_□)"], "chucknorris.png", { type: "image/png" });
|
||||
|
||||
// Get the UploadImageInput component and simulate file upload
|
||||
const input = screen.getByTestId("upload-image-input");
|
||||
const changeEvent = {
|
||||
target: {
|
||||
files: [file],
|
||||
},
|
||||
};
|
||||
fireEvent.change(input, changeEvent);
|
||||
|
||||
// Submit the message
|
||||
await user.keyboard("{Enter}");
|
||||
|
||||
expect(onSubmitMock).toHaveBeenCalledWith("Hello, world!", [file]);
|
||||
expect(textarea).toHaveValue("");
|
||||
});
|
||||
|
||||
it("should disable the submit button", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(
|
||||
|
||||
@@ -51,6 +51,10 @@ export function ChatInput({
|
||||
if (files.length > 0) {
|
||||
event.preventDefault();
|
||||
onImagePaste(files);
|
||||
// Submit the current message along with the image
|
||||
if (textareaRef.current?.value) {
|
||||
handleSubmitMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
// For text paste, let the default behavior handle it
|
||||
@@ -77,6 +81,10 @@ export function ChatInput({
|
||||
);
|
||||
if (files.length > 0) {
|
||||
onImagePaste(files);
|
||||
// Submit the current message along with the image
|
||||
if (textareaRef.current?.value) {
|
||||
handleSubmitMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user