formatShortcut.test.ts99 lines · main
| 1 | import { describe, expect, it } from 'vitest' |
| 2 | |
| 3 | import { hotkeyToKeys } from './formatShortcut' |
| 4 | |
| 5 | describe('hotkeyToKeys', () => { |
| 6 | describe('single-step hotkeys', () => { |
| 7 | it('returns a single letter key unchanged', () => { |
| 8 | expect(hotkeyToKeys('K')).toEqual(['K']) |
| 9 | }) |
| 10 | |
| 11 | it('preserves named keys', () => { |
| 12 | expect(hotkeyToKeys('Enter')).toEqual(['Enter']) |
| 13 | expect(hotkeyToKeys('Escape')).toEqual(['Escape']) |
| 14 | expect(hotkeyToKeys('Tab')).toEqual(['Tab']) |
| 15 | expect(hotkeyToKeys('ArrowUp')).toEqual(['ArrowUp']) |
| 16 | expect(hotkeyToKeys('ArrowDown')).toEqual(['ArrowDown']) |
| 17 | expect(hotkeyToKeys('ArrowLeft')).toEqual(['ArrowLeft']) |
| 18 | expect(hotkeyToKeys('ArrowRight')).toEqual(['ArrowRight']) |
| 19 | }) |
| 20 | |
| 21 | it('preserves punctuation keys', () => { |
| 22 | expect(hotkeyToKeys(',')).toEqual([',']) |
| 23 | expect(hotkeyToKeys('.')).toEqual(['.']) |
| 24 | expect(hotkeyToKeys('/')).toEqual(['/']) |
| 25 | }) |
| 26 | }) |
| 27 | |
| 28 | describe('Mod mapping', () => { |
| 29 | it('converts standalone Mod to Meta', () => { |
| 30 | expect(hotkeyToKeys('Mod')).toEqual(['Meta']) |
| 31 | }) |
| 32 | |
| 33 | it('converts Mod to Meta when combined with a single key', () => { |
| 34 | expect(hotkeyToKeys('Mod+K')).toEqual(['Meta', 'K']) |
| 35 | }) |
| 36 | |
| 37 | it('is case sensitive — only exact "Mod" is converted', () => { |
| 38 | expect(hotkeyToKeys('mod+K')).toEqual(['mod', 'K']) |
| 39 | expect(hotkeyToKeys('MOD+K')).toEqual(['MOD', 'K']) |
| 40 | }) |
| 41 | |
| 42 | it('does not rewrite keys that merely contain "Mod" as a substring', () => { |
| 43 | expect(hotkeyToKeys('Model')).toEqual(['Model']) |
| 44 | expect(hotkeyToKeys('Mod+Model')).toEqual(['Meta', 'Model']) |
| 45 | }) |
| 46 | }) |
| 47 | |
| 48 | describe('modifier combos', () => { |
| 49 | it('handles Mod+Shift combos', () => { |
| 50 | expect(hotkeyToKeys('Mod+Shift+M')).toEqual(['Meta', 'Shift', 'M']) |
| 51 | expect(hotkeyToKeys('Mod+Shift+J')).toEqual(['Meta', 'Shift', 'J']) |
| 52 | expect(hotkeyToKeys('Mod+Shift+C')).toEqual(['Meta', 'Shift', 'C']) |
| 53 | }) |
| 54 | |
| 55 | it('preserves modifier order', () => { |
| 56 | expect(hotkeyToKeys('Shift+Mod+K')).toEqual(['Shift', 'Meta', 'K']) |
| 57 | expect(hotkeyToKeys('Alt+Mod+K')).toEqual(['Alt', 'Meta', 'K']) |
| 58 | }) |
| 59 | |
| 60 | it('leaves Ctrl, Alt, Shift, Meta literals untouched', () => { |
| 61 | expect(hotkeyToKeys('Ctrl+K')).toEqual(['Ctrl', 'K']) |
| 62 | expect(hotkeyToKeys('Alt+K')).toEqual(['Alt', 'K']) |
| 63 | expect(hotkeyToKeys('Shift+K')).toEqual(['Shift', 'K']) |
| 64 | expect(hotkeyToKeys('Meta+K')).toEqual(['Meta', 'K']) |
| 65 | }) |
| 66 | |
| 67 | it('handles three-modifier combos', () => { |
| 68 | expect(hotkeyToKeys('Mod+Alt+Shift+K')).toEqual(['Meta', 'Alt', 'Shift', 'K']) |
| 69 | }) |
| 70 | }) |
| 71 | |
| 72 | describe('named-key combos from the registry', () => { |
| 73 | it('handles Mod+ArrowUp/Down/Left/Right', () => { |
| 74 | expect(hotkeyToKeys('Mod+ArrowUp')).toEqual(['Meta', 'ArrowUp']) |
| 75 | expect(hotkeyToKeys('Mod+ArrowDown')).toEqual(['Meta', 'ArrowDown']) |
| 76 | expect(hotkeyToKeys('Mod+ArrowLeft')).toEqual(['Meta', 'ArrowLeft']) |
| 77 | expect(hotkeyToKeys('Mod+ArrowRight')).toEqual(['Meta', 'ArrowRight']) |
| 78 | }) |
| 79 | |
| 80 | it('handles Mod+Enter and Mod+Escape', () => { |
| 81 | expect(hotkeyToKeys('Mod+Enter')).toEqual(['Meta', 'Enter']) |
| 82 | expect(hotkeyToKeys('Mod+Escape')).toEqual(['Meta', 'Escape']) |
| 83 | }) |
| 84 | |
| 85 | it('handles Mod+. (operation queue toggle / logs reset)', () => { |
| 86 | expect(hotkeyToKeys('Mod+.')).toEqual(['Meta', '.']) |
| 87 | }) |
| 88 | }) |
| 89 | |
| 90 | describe('edge cases', () => { |
| 91 | it('returns a single-element array for empty input', () => { |
| 92 | expect(hotkeyToKeys('')).toEqual(['']) |
| 93 | }) |
| 94 | |
| 95 | it('preserves empty segments from trailing plus', () => { |
| 96 | expect(hotkeyToKeys('Mod+')).toEqual(['Meta', '']) |
| 97 | }) |
| 98 | }) |
| 99 | }) |