import test from "node:test"; import assert from "node:assert/strict"; import { keyIntent } from "../mod/ovis-composer/keys.js"; const ev = (key, mods = {}) => ({ key, shift: false, ctrl: false, alt: false, composing: false, ...mods }); const ctx = (o = {}) => ({ hasKeyboard: true, menuOpen: false, panelOpen: false, empty: false, status: null, ...o }); test("no keyboard -> always none", () => { const c = ctx({ hasKeyboard: false }); assert.equal(keyIntent(ev("Enter"), c), "none"); assert.equal(keyIntent(ev("v", { ctrl: true }), c), "none"); assert.equal(keyIntent(ev("Escape"), { ...c, menuOpen: true }), "none"); }); test("composing -> none", () => { assert.equal(keyIntent(ev("Enter", { composing: true }), ctx()), "none"); }); test("enter variants", () => { assert.equal(keyIntent(ev("Enter"), ctx()), "send"); assert.equal(keyIntent(ev("Enter", { shift: true }), ctx()), "newline"); assert.equal(keyIntent(ev("Enter", { ctrl: true }), ctx()), "send_now"); assert.equal(keyIntent(ev("Enter", { alt: true }), ctx()), "hold"); }); test("escape", () => { assert.equal(keyIntent(ev("Escape"), ctx({ menuOpen: true })), "close_menu"); assert.equal(keyIntent(ev("Escape"), ctx({ panelOpen: true })), "close_panel"); assert.equal(keyIntent(ev("Escape"), ctx({ empty: true, status: "working" })), "interrupt"); assert.equal(keyIntent(ev("Escape"), ctx({ empty: false, status: "working" })), "none"); assert.equal(keyIntent(ev("Escape"), ctx({ empty: true, status: "idle" })), "none"); }); test("ctrl+r opens the panel; ctrl+v is not ours", () => { assert.equal(keyIntent(ev("r", { ctrl: true }), ctx()), "open_panel"); assert.equal(keyIntent(ev("v", { ctrl: true }), ctx()), "none"); }); test("menu keys", () => { assert.equal(keyIntent(ev("Tab"), ctx({ menuOpen: true })), "menu_accept"); assert.equal(keyIntent(ev("ArrowUp"), ctx({ menuOpen: true })), "menu_up"); assert.equal(keyIntent(ev("ArrowDown"), ctx({ menuOpen: true })), "menu_down"); assert.equal(keyIntent(ev("ArrowUp"), ctx()), "none"); assert.equal(keyIntent(ev("Tab"), ctx()), "none"); });