Files
openhuman/app/src/test/commandTestUtils.ts
T
478c92e533 feat(commands): ⌘K palette + keyboard system + chat UX polish (#745)
- Implement command palette (⌘K) using cmdk and Radix Dialog with a global action registry.
- Add a keyboard shortcut system with a capture-phase hotkey manager and scope stack.
- Integrate seed navigation actions for Home, Chat, Intelligence, Skills, and Settings.
- Improve chat UX with a `useStickToBottom` hook for auto-scroll and fixed hydration errors.
- Refactor command UI to display shortcuts inline and remove the redundant help overlay.
- Fix Vite HMR connection issues within the Tauri/CEF environment.

Co-authored-by: Steven Enamakel <enamakel@tinyhumans.ai>
2026-04-23 22:52:54 -07:00

39 lines
1.0 KiB
TypeScript

import { expect } from 'vitest';
export interface PressKeyOptions {
key: string;
mod?: boolean;
shift?: boolean;
alt?: boolean;
ctrl?: boolean;
target?: EventTarget;
}
export function pressKey(opts: PressKeyOptions): KeyboardEvent {
const mac = navigator.platform.toLowerCase().includes('mac');
const modPair = opts.mod ? (mac ? { metaKey: true } : { ctrlKey: true }) : {};
const target = opts.target ?? window;
const event = new KeyboardEvent('keydown', {
key: opts.key,
bubbles: true,
cancelable: true,
shiftKey: !!opts.shift,
altKey: !!opts.alt,
ctrlKey: !!opts.ctrl,
...modPair,
});
target.dispatchEvent(event);
return event;
}
export function __metaAssertPressKeyReachesCaptureListener(): void {
let reached = false;
const listener = (_e: KeyboardEvent) => {
reached = true;
};
window.addEventListener('keydown', listener, { capture: true });
pressKey({ key: 'z' });
window.removeEventListener('keydown', listener, { capture: true });
expect(reached).toBe(true);
}