story-kit: merge 82_story_shift_enter_inserts_newline_instead_of_sending_in_chat_input

This commit is contained in:
Dave
2026-02-23 15:59:01 +00:00
parent 0a5fcd8db9
commit 76e5c40134
2 changed files with 58 additions and 4 deletions

View File

@@ -1,4 +1,10 @@
import { act, render, screen, waitFor } from "@testing-library/react";
import {
act,
fireEvent,
render,
screen,
waitFor,
} from "@testing-library/react";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { api } from "../api/client";
@@ -261,3 +267,46 @@ describe("Chat two-column layout", () => {
});
});
});
describe("Chat input Shift+Enter behavior", () => {
beforeEach(() => {
capturedWsHandlers = null;
setupMocks();
});
it("renders a textarea element for the chat input (AC3)", async () => {
render(<Chat projectPath="/tmp/project" onCloseProject={vi.fn()} />);
const input = screen.getByPlaceholderText("Send a message...");
expect(input.tagName.toLowerCase()).toBe("textarea");
});
it("sends message on Enter key press without Shift (AC2)", async () => {
render(<Chat projectPath="/tmp/project" onCloseProject={vi.fn()} />);
const input = screen.getByPlaceholderText("Send a message...");
await act(async () => {
fireEvent.change(input, { target: { value: "Hello" } });
});
await act(async () => {
fireEvent.keyDown(input, { key: "Enter", shiftKey: false });
});
await waitFor(() => {
expect((input as HTMLTextAreaElement).value).toBe("");
});
});
it("does not send message on Shift+Enter (AC1)", async () => {
render(<Chat projectPath="/tmp/project" onCloseProject={vi.fn()} />);
const input = screen.getByPlaceholderText("Send a message...");
await act(async () => {
fireEvent.change(input, { target: { value: "Hello" } });
});
await act(async () => {
fireEvent.keyDown(input, { key: "Enter", shiftKey: true });
});
expect((input as HTMLTextAreaElement).value).toBe("Hello");
});
});