Files
oh-my-pi/packages/coding-agent/test/custom-editor-keybindings.test.ts
T
metaphorics 5a97367ea2 test(keybindings): cover the editor default table for the shift+up dequeue
The registry assertion did not touch DEFAULT_ACTION_KEYS in custom-editor.ts,
which is the table this change calls fragile. A real CustomEditor now takes the
shift+up wire form through handleInput without setActionKeys, so only the
shipped default seeds the match set. Mutation-checked: removing shift+up from
DEFAULT_ACTION_KEYS fails this test while the registry test stays green.
2026-07-31 18:50:21 +09:00

71 lines
2.5 KiB
TypeScript

import { beforeAll, describe, expect, it, vi } from "bun:test";
import { KeybindingsManager } from "@oh-my-pi/pi-coding-agent/config/keybindings";
import { CustomEditor } from "@oh-my-pi/pi-coding-agent/modes/components/custom-editor";
import { getEditorTheme, initTheme } from "@oh-my-pi/pi-coding-agent/modes/theme/theme";
describe("CustomEditor keybindings", () => {
beforeAll(async () => {
await initTheme();
});
it("routes the configured retry chord through handleInput", () => {
const editor = new CustomEditor(getEditorTheme());
const onRetry = vi.fn();
editor.setActionKeys("app.retry", ["alt+shift+r"]);
editor.onRetry = onRetry;
editor.handleInput("\x1bR");
expect(onRetry).toHaveBeenCalledTimes(1);
});
it("lets custom handlers keep precedence over the default retry chord", () => {
const editor = new CustomEditor(getEditorTheme());
const onRetry = vi.fn();
const customHandler = vi.fn();
editor.onRetry = onRetry;
editor.setCustomKeyHandler("alt+r", customHandler);
editor.handleInput("\x1br");
expect(customHandler).toHaveBeenCalledTimes(1);
expect(onRetry).not.toHaveBeenCalled();
});
it("lets copy-prompt remaps keep precedence over the default retry chord", () => {
const editor = new CustomEditor(getEditorTheme());
const onRetry = vi.fn();
const onCopyPrompt = vi.fn();
editor.onRetry = onRetry;
editor.onCopyPrompt = onCopyPrompt;
editor.setActionKeys("app.clipboard.copyPrompt", ["alt+r"]);
editor.handleInput("\x1br");
expect(onCopyPrompt).toHaveBeenCalledTimes(1);
expect(onRetry).not.toHaveBeenCalled();
});
});
describe("shipped dequeue defaults", () => {
it("binds both alt+up and shift+up to the steering dequeue", () => {
const keybindings = KeybindingsManager.inMemory();
const keys = keybindings.getKeys("app.message.dequeue");
expect(keys).toContain("alt+up");
expect(keys).toContain("shift+up");
});
it("routes the shipped shift+up default through DEFAULT_ACTION_KEYS to the dequeue handler", () => {
// F12: the registry test above does not cover DEFAULT_ACTION_KEYS, the second
// defaults table that custom-editor.ts seeds its match set from. Drive a real
// editor without calling setActionKeys, so the shipped entry is the only thing
// that can make the shift+up wire form (CSI 1;2A) reach onDequeue.
const editor = new CustomEditor(getEditorTheme());
const onDequeue = vi.fn();
editor.onDequeue = onDequeue;
editor.handleInput("\x1b[1;2A");
expect(onDequeue).toHaveBeenCalledTimes(1);
});
});