forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindowShortcuts.test.ts
More file actions
42 lines (35 loc) · 1.52 KB
/
Copy pathwindowShortcuts.test.ts
File metadata and controls
42 lines (35 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { describe, it, expect } from 'vitest'
import { isHideWindowShortcut, type KeyboardInput } from './windowShortcuts'
// A fully-modifier-free keyDown of a given key; spread over per-test overrides.
const input = (over: Partial<KeyboardInput> = {}): KeyboardInput => ({
type: 'keyDown',
key: 'w',
control: false,
alt: false,
meta: false,
...over
})
describe('isHideWindowShortcut', () => {
it('matches Ctrl+W on keyDown', () => {
expect(isHideWindowShortcut(input({ control: true }))).toBe(true)
})
it('is case-insensitive on the key (some layouts report uppercase)', () => {
expect(isHideWindowShortcut(input({ control: true, key: 'W' }))).toBe(true)
})
// The whole point of gating on keyDown: keyUp must not fire a second hide.
it('ignores the keyUp half of the keystroke', () => {
expect(isHideWindowShortcut(input({ control: true, type: 'keyUp' }))).toBe(false)
})
// Ctrl+Alt is AltGr on some layouts — a character key, not a shortcut.
it('does not match Ctrl+Alt+W (AltGr)', () => {
expect(isHideWindowShortcut(input({ control: true, alt: true }))).toBe(false)
})
it('does not match Cmd/Meta+W', () => {
expect(isHideWindowShortcut(input({ meta: true }))).toBe(false)
expect(isHideWindowShortcut(input({ control: true, meta: true }))).toBe(false)
})
it('does not match W without Ctrl, nor other Ctrl keys', () => {
expect(isHideWindowShortcut(input({ control: false }))).toBe(false)
expect(isHideWindowShortcut(input({ control: true, key: 'q' }))).toBe(false)
})
})