import { describe, expect, test } from 'bun:test'; import type { Key } from 'ink'; import { handleKey } from './keymap'; function key(over: Partial = {}): Key { return { upArrow: false, downArrow: false, leftArrow: false, rightArrow: false, pageDown: false, pageUp: false, return: false, escape: false, ctrl: false, shift: false, tab: false, backspace: false, delete: false, meta: false, ...over, } as Key; } describe('handleKey — quit', () => { test('q quits', () => { expect(handleKey('q', key(), 'categories').signal).toBe('quit'); }); test('Ctrl-C quits', () => { expect(handleKey('c', key({ ctrl: true }), 'categories').signal).toBe('quit'); }); test('Esc on summary quits', () => { expect(handleKey('', key({ escape: true }), 'summary').signal).toBe('quit'); }); test('Esc on categories quits', () => { expect(handleKey('', key({ escape: true }), 'categories').signal).toBe('quit'); }); test('Esc on findings dispatches escape (not quit)', () => { const r = handleKey('', key({ escape: true }), 'findings'); expect(r.signal).toBeUndefined(); expect(r.actions).toEqual([{ type: 'escape' }]); }); }); describe('handleKey — pane jump', () => { test.each(['1', '2', '3', '4', '5'] as const)('%s focuses corresponding pane', (n) => { const r = handleKey(n, key(), 'summary'); expect(r.actions).toHaveLength(1); expect(r.actions[0].type).toBe('focus'); }); }); describe('handleKey — movement', () => { test('up arrow → move -1', () => { expect(handleKey('', key({ upArrow: true }), 'categories').actions).toEqual([ { type: 'move', direction: -1 }, ]); }); test('k → move -1', () => { expect(handleKey('k', key(), 'categories').actions).toEqual([{ type: 'move', direction: -1 }]); }); test('j → move +1', () => { expect(handleKey('j', key(), 'categories').actions).toEqual([{ type: 'move', direction: 1 }]); }); }); describe('handleKey — Enter / Tab', () => { test('Enter dispatches enter', () => { expect(handleKey('', key({ return: true }), 'categories').actions).toEqual([{ type: 'enter' }]); }); test('Tab dispatches cycle +1', () => { expect(handleKey('', key({ tab: true }), 'categories').actions).toEqual([ { type: 'cycle', direction: 1 }, ]); }); test('Shift-Tab dispatches cycle -1', () => { expect(handleKey('', key({ tab: true, shift: true }), 'categories').actions).toEqual([ { type: 'cycle', direction: -1 }, ]); }); }); describe('handleKey — Phase 3 hooks', () => { test('r signals remediate', () => { expect(handleKey('r', key(), 'findings').signal).toBe('remediate'); }); test('R signals reaudit', () => { expect(handleKey('R', key(), 'summary').signal).toBe('reaudit'); }); }); describe('handleKey — help', () => { test('? toggles help', () => { expect(handleKey('?', key(), 'summary').actions).toEqual([{ type: 'toggle-help' }]); }); });