test (tui): cover newline preservation in submit and render paths

This commit is contained in:
Vignesh Natarajan
2026-02-14 20:56:32 -08:00
parent fa1aca83ef
commit 2faceadd0d
2 changed files with 42 additions and 0 deletions

View File

@@ -93,4 +93,28 @@ describe("createEditorSubmitHandler", () => {
expect(sendMessage).toHaveBeenCalledWith("hello");
expect(editor.addToHistory).toHaveBeenCalledWith("hello");
});
it("preserves internal newlines for multiline messages", () => {
const editor = {
setText: vi.fn(),
addToHistory: vi.fn(),
};
const handleCommand = vi.fn();
const sendMessage = vi.fn();
const handleBangLine = vi.fn();
const onSubmit = createEditorSubmitHandler({
editor,
handleCommand,
sendMessage,
handleBangLine,
});
onSubmit("Line 1\nLine 2\nLine 3");
expect(sendMessage).toHaveBeenCalledWith("Line 1\nLine 2\nLine 3");
expect(editor.addToHistory).toHaveBeenCalledWith("Line 1\nLine 2\nLine 3");
expect(handleCommand).not.toHaveBeenCalled();
expect(handleBangLine).not.toHaveBeenCalled();
});
});