Repository navigation
Expand file tree
/
Copy pathtest.js
More file actions
38 lines (32 loc) · 1.5 KB
/
Copy pathtest.js
File metadata and controls
38 lines (32 loc) · 1.5 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
import test from "node:test";
import assert from "node:assert/strict";
import {
normalizeShortcut,
formatKeycaps,
checkBrowserConflict,
matchesKeyboardEvent
} from "./index.js";
test("normalizeShortcut canonicalizes modifier order and platform Mod alias", () => {
assert.equal(normalizeShortcut("Shift + Ctrl + P"), "ctrl+shift+p");
assert.equal(normalizeShortcut("Mod + K", { platform: "mac" }), "meta+k");
assert.equal(normalizeShortcut("Mod + K", { platform: "windows" }), "ctrl+k");
});
test("formatKeycaps renders OS-specific keycap symbols", () => {
assert.deepEqual(formatKeycaps("Mod+Shift+P", "mac"), ["⇧", "⌘", "P"]);
assert.deepEqual(formatKeycaps("Mod+Shift+P", "windows"), ["Ctrl", "Shift", "P"]);
});
test("checkBrowserConflict detects critical and interceptable browser shortcuts", () => {
const critical = checkBrowserConflict("Ctrl+W");
assert.equal(critical.hasConflict, true);
assert.equal(critical.severity, "critical");
const interceptable = checkBrowserConflict("Ctrl+P");
assert.equal(interceptable.hasConflict, true);
assert.equal(interceptable.severity, "interceptable");
const safe = checkBrowserConflict("Alt+Shift+F");
assert.equal(safe.hasConflict, false);
});
test("matchesKeyboardEvent accurately matches synthetic KeyboardEvents", () => {
const event = { ctrlKey: true, shiftKey: true, altKey: false, metaKey: false, key: "P" };
assert.equal(matchesKeyboardEvent(event, "Ctrl+Shift+P"), true);
assert.equal(matchesKeyboardEvent(event, "Ctrl+P"), false);
});