Files
llmx/codex-cli/tests/multiline-external-editor-shortcut.test.tsx
Ilan Bigio 59a180ddec Initial commit
Signed-off-by: Ilan Bigio <ilan@openai.com>
2025-04-16 12:56:08 -04:00

65 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { renderTui } from "./ui-test-helpers.js";
import MultilineTextEditor from "../src/components/chat/multiline-editor.js";
import TextBuffer from "../src/lib/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();
});
});