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

@@ -45,6 +45,24 @@ describe("extractTextFromMessage", () => {
expect(text).toBe("first\nsecond");
});
it("preserves internal newlines for string content", () => {
const text = extractTextFromMessage({
role: "assistant",
content: "Line 1\nLine 2\nLine 3",
});
expect(text).toBe("Line 1\nLine 2\nLine 3");
});
it("preserves internal newlines for text blocks", () => {
const text = extractTextFromMessage({
role: "assistant",
content: [{ type: "text", text: "Line 1\nLine 2\nLine 3" }],
});
expect(text).toBe("Line 1\nLine 2\nLine 3");
});
it("places thinking before content when included", () => {
const text = extractTextFromMessage(
{

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();
});
});