| 1 | import test from "node:test"; |
| 2 | import assert from "node:assert/strict"; |
| 3 | import { primaryModifier, terminalModifier, shortcut } from "./platform.mjs"; |
| 4 | |
| 5 | test("Linux defaults to Ctrl and macOS keeps Command", async () => { |
| 6 | const descriptor = Object.getOwnPropertyDescriptor(globalThis, "navigator"); |
| 7 | try { |
| 8 | for (const platform of ["Linux x86_64", "Win32", "MacIntel"]) { |
| 9 | Object.defineProperty(globalThis, "navigator", { configurable: true, value: { platform } }); |
| 10 | const api = await import(`./platform.mjs?platform=${encodeURIComponent(platform)}`); |
| 11 | const control = platform !== "MacIntel"; |
| 12 | assert.equal(api.usesControl, control); |
| 13 | assert.equal(api.isWindows, platform === "Win32"); |
| 14 | assert.equal(api.shortcut("⌘O"), control ? "Ctrl+O" : "⌘O"); |
| 15 | const event = { ctrlKey: true, metaKey: false, altKey: false, shiftKey: false }; |
| 16 | assert.equal(api.primaryModifier(event), control); |
| 17 | assert.equal(api.terminalModifier(event), false); |
| 18 | assert.equal(api.terminalModifier({ ...event, shiftKey: true }), control); |
| 19 | } |
| 20 | } finally { |
| 21 | if (descriptor) Object.defineProperty(globalThis, "navigator", descriptor); |
| 22 | else delete globalThis.navigator; |
| 23 | } |
| 24 | }); |
| 25 | |
| 26 | test("Windows shortcuts reserve Ctrl+C for terminal interruption and ignore AltGr", () => { |
| 27 | const ctrl = { ctrlKey: true, altKey: false, metaKey: false, shiftKey: false }; |
| 28 | assert.equal(primaryModifier(ctrl, true), true); |
| 29 | assert.equal(terminalModifier(ctrl, true), false); |
| 30 | assert.equal(terminalModifier({ ...ctrl, shiftKey: true }, true), true); |
| 31 | assert.equal(primaryModifier({ ...ctrl, altKey: true }, true), false); |
| 32 | assert.equal(primaryModifier({ ...ctrl, metaKey: true }, false), true); |
| 33 | assert.equal(shortcut("⌘⇧↵", true), "Ctrl+Shift+Enter"); |
| 34 | assert.equal(shortcut("⌘W", false), "⌘W"); |
| 35 | }); |