story-kit: merge 215_bug_cancel_button_still_discards_queued_messages_197_regression
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { act, fireEvent, render, screen } from "@testing-library/react";
|
||||
import * as React from "react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { ChatInputHandle } from "./ChatInput";
|
||||
import { ChatInput } from "./ChatInput";
|
||||
|
||||
describe("ChatInput component (Story 178 AC1)", () => {
|
||||
@@ -200,3 +202,78 @@ describe("ChatInput component (Story 178 AC1)", () => {
|
||||
expect(onRemove).toHaveBeenCalledWith("q1");
|
||||
});
|
||||
});
|
||||
|
||||
describe("ChatInput appendToInput (Bug 215 regression)", () => {
|
||||
it("appendToInput sets text into an empty input", async () => {
|
||||
const ref = React.createRef<ChatInputHandle>();
|
||||
|
||||
render(
|
||||
<ChatInput
|
||||
ref={ref}
|
||||
loading={false}
|
||||
queuedMessages={[]}
|
||||
onSubmit={vi.fn()}
|
||||
onCancel={vi.fn()}
|
||||
onRemoveQueuedMessage={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
|
||||
await act(async () => {
|
||||
ref.current?.appendToInput("queued message");
|
||||
});
|
||||
|
||||
const textarea = screen.getByPlaceholderText("Send a message...");
|
||||
expect((textarea as HTMLTextAreaElement).value).toBe("queued message");
|
||||
});
|
||||
|
||||
it("appendToInput appends to existing input content with a newline separator", async () => {
|
||||
const ref = React.createRef<ChatInputHandle>();
|
||||
|
||||
render(
|
||||
<ChatInput
|
||||
ref={ref}
|
||||
loading={false}
|
||||
queuedMessages={[]}
|
||||
onSubmit={vi.fn()}
|
||||
onCancel={vi.fn()}
|
||||
onRemoveQueuedMessage={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
|
||||
const textarea = screen.getByPlaceholderText("Send a message...");
|
||||
|
||||
await act(async () => {
|
||||
fireEvent.change(textarea, { target: { value: "existing text" } });
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
ref.current?.appendToInput("appended text");
|
||||
});
|
||||
|
||||
expect((textarea as HTMLTextAreaElement).value).toBe(
|
||||
"existing text\nappended text",
|
||||
);
|
||||
});
|
||||
|
||||
it("multiple queued messages joined with newlines are appended on cancel", async () => {
|
||||
const ref = React.createRef<ChatInputHandle>();
|
||||
|
||||
render(
|
||||
<ChatInput
|
||||
ref={ref}
|
||||
loading={false}
|
||||
queuedMessages={[]}
|
||||
onSubmit={vi.fn()}
|
||||
onCancel={vi.fn()}
|
||||
onRemoveQueuedMessage={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
|
||||
await act(async () => {
|
||||
ref.current?.appendToInput("msg one\nmsg two");
|
||||
});
|
||||
|
||||
const textarea = screen.getByPlaceholderText("Send a message...");
|
||||
expect((textarea as HTMLTextAreaElement).value).toBe("msg one\nmsg two");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user