mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
test (tui): cover newline preservation in submit and render paths
This commit is contained in:
@@ -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(
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user