mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 05:42:43 +00:00
feat(tui): add input history for submitted messages (WIP)
Record submitted inputs in the editor history so up/down arrow can recall previous messages. Adds a small helper to wire submit handling and unit tests for routing/recording behavior. No PR yet (per request).
This commit is contained in:
committed by
Peter Steinberger
parent
416894c642
commit
2700794228
99
src/tui/tui-input-history.test.ts
Normal file
99
src/tui/tui-input-history.test.ts
Normal file
@@ -0,0 +1,99 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { createEditorSubmitHandler } from "./tui.js";
|
||||
|
||||
describe("createEditorSubmitHandler", () => {
|
||||
it("adds submitted messages to editor history", () => {
|
||||
const editor = {
|
||||
setText: vi.fn(),
|
||||
addToHistory: vi.fn(),
|
||||
};
|
||||
|
||||
const handler = createEditorSubmitHandler({
|
||||
editor,
|
||||
handleCommand: vi.fn(),
|
||||
sendMessage: vi.fn(),
|
||||
});
|
||||
|
||||
handler("hello world");
|
||||
|
||||
expect(editor.setText).toHaveBeenCalledWith("");
|
||||
expect(editor.addToHistory).toHaveBeenCalledWith("hello world");
|
||||
});
|
||||
|
||||
it("trims input before adding to history", () => {
|
||||
const editor = {
|
||||
setText: vi.fn(),
|
||||
addToHistory: vi.fn(),
|
||||
};
|
||||
|
||||
const handler = createEditorSubmitHandler({
|
||||
editor,
|
||||
handleCommand: vi.fn(),
|
||||
sendMessage: vi.fn(),
|
||||
});
|
||||
|
||||
handler(" hi ");
|
||||
|
||||
expect(editor.addToHistory).toHaveBeenCalledWith("hi");
|
||||
});
|
||||
|
||||
it("does not add empty submissions to history", () => {
|
||||
const editor = {
|
||||
setText: vi.fn(),
|
||||
addToHistory: vi.fn(),
|
||||
};
|
||||
|
||||
const handler = createEditorSubmitHandler({
|
||||
editor,
|
||||
handleCommand: vi.fn(),
|
||||
sendMessage: vi.fn(),
|
||||
});
|
||||
|
||||
handler(" ");
|
||||
|
||||
expect(editor.addToHistory).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("routes slash commands to handleCommand", () => {
|
||||
const editor = {
|
||||
setText: vi.fn(),
|
||||
addToHistory: vi.fn(),
|
||||
};
|
||||
const handleCommand = vi.fn();
|
||||
const sendMessage = vi.fn();
|
||||
|
||||
const handler = createEditorSubmitHandler({
|
||||
editor,
|
||||
handleCommand,
|
||||
sendMessage,
|
||||
});
|
||||
|
||||
handler("/models");
|
||||
|
||||
expect(editor.addToHistory).toHaveBeenCalledWith("/models");
|
||||
expect(handleCommand).toHaveBeenCalledWith("/models");
|
||||
expect(sendMessage).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("routes normal messages to sendMessage", () => {
|
||||
const editor = {
|
||||
setText: vi.fn(),
|
||||
addToHistory: vi.fn(),
|
||||
};
|
||||
const handleCommand = vi.fn();
|
||||
const sendMessage = vi.fn();
|
||||
|
||||
const handler = createEditorSubmitHandler({
|
||||
editor,
|
||||
handleCommand,
|
||||
sendMessage,
|
||||
});
|
||||
|
||||
handler("hello");
|
||||
|
||||
expect(editor.addToHistory).toHaveBeenCalledWith("hello");
|
||||
expect(sendMessage).toHaveBeenCalledWith("hello");
|
||||
expect(handleCommand).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user