Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
91 lines
3.4 KiB
TypeScript
91 lines
3.4 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
|
|
import { keyEventToString, keyStringToKeyboardEvent, matchesKeyBinding, tabShortcutDigitFromEvent } from './models.ts';
|
|
|
|
const keyboardEvent = (
|
|
key: string,
|
|
code: string,
|
|
modifiers: Partial<KeyboardEvent> = {},
|
|
): KeyboardEvent => ({
|
|
key,
|
|
code,
|
|
altKey: false,
|
|
ctrlKey: false,
|
|
metaKey: false,
|
|
shiftKey: false,
|
|
...modifiers,
|
|
}) as KeyboardEvent;
|
|
|
|
test('shortcut matching falls back to physical keys for non-Latin layouts', () => {
|
|
const event = keyboardEvent('\u0446', 'KeyW', { ctrlKey: true });
|
|
|
|
assert.equal(matchesKeyBinding(event, 'Ctrl + W', false), true);
|
|
assert.equal(keyEventToString(event, false), 'Ctrl + W');
|
|
});
|
|
|
|
test('shortcut matching respects Latin characters from non-QWERTY layouts', () => {
|
|
const event = keyboardEvent('w', 'Comma', { ctrlKey: true });
|
|
|
|
assert.equal(matchesKeyBinding(event, 'Ctrl + W', false), true);
|
|
assert.equal(matchesKeyBinding(event, 'Ctrl + ,', false), false);
|
|
assert.equal(keyEventToString(event, false), 'Ctrl + W');
|
|
});
|
|
|
|
test('shortcut matching respects non-ASCII Latin layout characters', () => {
|
|
const event = keyboardEvent('ß', 'Minus', { ctrlKey: true });
|
|
|
|
assert.equal(matchesKeyBinding(event, 'Ctrl + ß', false), true);
|
|
assert.equal(matchesKeyBinding(event, 'Ctrl + -', false), false);
|
|
assert.equal(keyEventToString(event, false), 'Ctrl + ß');
|
|
});
|
|
|
|
test('shortcut matching respects punctuation characters from non-QWERTY layouts', () => {
|
|
const event = keyboardEvent(',', 'KeyW', { ctrlKey: true });
|
|
|
|
assert.equal(matchesKeyBinding(event, 'Ctrl + ,', false), true);
|
|
assert.equal(matchesKeyBinding(event, 'Ctrl + W', false), false);
|
|
assert.equal(keyEventToString(event, false), 'Ctrl + ,');
|
|
});
|
|
|
|
test('shortcut matching keeps physical digit ranges layout-independent', () => {
|
|
const event = keyboardEvent('&', 'Digit1', { ctrlKey: true });
|
|
|
|
assert.equal(matchesKeyBinding(event, 'Ctrl + [1...9]', false), true);
|
|
assert.equal(keyEventToString(event, false), 'Ctrl + &');
|
|
});
|
|
|
|
test('shortcut matching preserves shifted number-row symbols', () => {
|
|
const event = keyboardEvent('!', 'Digit1', { ctrlKey: true, shiftKey: true });
|
|
|
|
assert.equal(matchesKeyBinding(event, 'Ctrl + Shift + !', false), true);
|
|
assert.equal(matchesKeyBinding(event, 'Ctrl + Shift + 1', false), false);
|
|
assert.equal(keyEventToString(event, false), 'Ctrl + Shift + !');
|
|
});
|
|
|
|
test('shifted digit ranges still match via physical Digit code', () => {
|
|
const event = keyboardEvent('!', 'Digit1', { ctrlKey: true, shiftKey: true });
|
|
|
|
assert.equal(matchesKeyBinding(event, 'Ctrl + Shift + [1...9]', false), true);
|
|
assert.equal(tabShortcutDigitFromEvent(event), 1);
|
|
});
|
|
|
|
test('tab shortcut digit falls back to e.key when code is missing', () => {
|
|
assert.equal(tabShortcutDigitFromEvent({ key: '3', code: '' }), 3);
|
|
assert.equal(tabShortcutDigitFromEvent({ key: '!', code: '' }), null);
|
|
});
|
|
|
|
test('stored shortcut strings rebuild matching keyboard events', () => {
|
|
const event = keyStringToKeyboardEvent('Ctrl + 1');
|
|
assert.ok(event);
|
|
assert.equal(event.key, '1');
|
|
assert.equal(event.ctrlKey, true);
|
|
assert.equal(matchesKeyBinding(event, 'Ctrl + [1...9]', false), true);
|
|
|
|
const macEvent = keyStringToKeyboardEvent('⌘ + B');
|
|
assert.ok(macEvent);
|
|
assert.equal(macEvent.key, 'b');
|
|
assert.equal(macEvent.metaKey, true);
|
|
assert.equal(matchesKeyBinding(macEvent, '⌘ + B', true), true);
|
|
});
|