Files
llmx/codex-cli/tests/multiline-external-editor-shortcut.test.tsx

65 lines
1.7 KiB
TypeScript
Raw Normal View History

import { renderTui } from "./ui-test-helpers.js";
import MultilineTextEditor from "../src/components/chat/multiline-editor.js";
import TextBuffer from "../src/text-buffer.js";
import * as React from "react";
import { describe, it, expect, vi } from "vitest";
async function type(
stdin: NodeJS.WritableStream,
text: string,
flush: () => Promise<void>,
) {
stdin.write(text);
await flush();
}
describe("MultilineTextEditor external editor shortcut", () => {
it("fires openInExternalEditor on CtrlE (single key)", async () => {
const spy = vi
.spyOn(TextBuffer.prototype as any, "openInExternalEditor")
.mockResolvedValue(undefined);
const { stdin, flush, cleanup } = renderTui(
React.createElement(MultilineTextEditor, {
initialText: "hello",
width: 20,
height: 3,
}),
);
// Ensure initial render.
await flush();
// Send CtrlE → should fire immediately
await type(stdin, "\x05", flush); // CtrlE (ENQ / 0x05)
expect(spy).toHaveBeenCalledTimes(1);
spy.mockRestore();
cleanup();
});
it("fires openInExternalEditor on CtrlX (single key)", async () => {
const spy = vi
.spyOn(TextBuffer.prototype as any, "openInExternalEditor")
.mockResolvedValue(undefined);
const { stdin, flush, cleanup } = renderTui(
React.createElement(MultilineTextEditor, {
initialText: "hello",
width: 20,
height: 3,
}),
);
// Ensure initial render.
await flush();
// Send CtrlX → should fire immediately
await type(stdin, "\x18", flush); // CtrlX (SUB / 0x18)
expect(spy).toHaveBeenCalledTimes(1);
spy.mockRestore();
cleanup();
});
});