|
1 | 1 | import type { DevframeCommandEntry, DevframeCommandKeybinding } from '@devframes/hub' |
2 | 2 | import type { WhenContext } from 'devframe/utils/when' |
3 | 3 | import { describe, expect, it } from 'vitest' |
4 | | -import { collectAllKeybindings, filterCommandsByWhen, findCommandDeep, findKeybindingConflict, getShortcutRows, walkCommands } from './keybindings' |
| 4 | +import { collectAllKeybindings, filterCommandsByWhen, findCommandDeep, findKeybindingConflict, getShortcutRows, normalizeKeyEvent, walkCommands } from './keybindings' |
5 | 5 |
|
6 | 6 | describe('findKeybindingConflict', () => { |
7 | 7 | const commands: DevframeCommandEntry[] = [ |
@@ -259,3 +259,17 @@ describe('filterCommandsByWhen', () => { |
259 | 259 | expect(filterCommandsByWhen(withWhen, whenContext)).toEqual([]) |
260 | 260 | }) |
261 | 261 | }) |
| 262 | + |
| 263 | +describe('normalizeKeyEvent', () => { |
| 264 | + // Chrome's native autofill dispatches `keydown` events without `key` |
| 265 | + it('ignores key events without a key, like Chrome autofill', () => { |
| 266 | + const event = { ctrlKey: false, metaKey: false, altKey: false, shiftKey: false } as KeyboardEvent |
| 267 | + expect(() => normalizeKeyEvent(event)).not.toThrow() |
| 268 | + expect(normalizeKeyEvent(event)).toBe('') |
| 269 | + }) |
| 270 | + |
| 271 | + it('normalizes a regular shortcut', () => { |
| 272 | + const event = { key: 'k', ctrlKey: false, metaKey: false, altKey: false, shiftKey: true } as KeyboardEvent |
| 273 | + expect(normalizeKeyEvent(event)).toBe('Shift+K') |
| 274 | + }) |
| 275 | +}) |
0 commit comments