askrobots / dbbasic-browser
Public
A desktop browser with x402 built in: when a page asks for payment, it pays in stablecoins and shows the content.
danq9
toolbar: Back and Forward are greyed out when there's nowhere to go
cc08c7a
1 week, 2 days ago
History
shortcuts.test.ts · 2.5 KB · 33 lines
| 1 | import { describe, expect, it } from "vitest"; |
| 2 | import { reservedShortcut, type KeyInput } from "../src/shortcuts"; |
| 3 | |
| 4 | const k = (over: Partial<KeyInput>): KeyInput => ({ type: "keyDown", key: "", code: "", meta: false, control: false, shift: false, alt: false, ...over }); |
| 5 | |
| 6 | describe("the browser's own keys", () => { |
| 7 | it("⌘⇧] and ⌘⇧[ switch tabs on a Mac, by the key's place or by the character any layout reports", () => { |
| 8 | expect(reservedShortcut(k({ meta: true, shift: true, code: "BracketRight", key: "}" }), true)).toBe("next"); |
| 9 | expect(reservedShortcut(k({ meta: true, shift: true, code: "", key: "]" }), true)).toBe("next"); |
| 10 | expect(reservedShortcut(k({ meta: true, shift: true, code: "BracketLeft", key: "{" }), true)).toBe("prev"); |
| 11 | expect(reservedShortcut(k({ meta: true, alt: true, key: "ArrowRight" }), true)).toBe("next"); |
| 12 | }); |
| 13 | it("Ctrl+Tab everywhere, ⌘1–⌘9, ⌘T, ⌘W, ⌘L and ⌘R", () => { |
| 14 | expect(reservedShortcut(k({ control: true, key: "Tab" }), true)).toBe("next"); |
| 15 | expect(reservedShortcut(k({ control: true, shift: true, key: "Tab" }), false)).toBe("prev"); |
| 16 | expect(reservedShortcut(k({ meta: true, code: "Digit3", key: "3" }), true)).toBe("tab:3"); |
| 17 | expect(reservedShortcut(k({ meta: true, key: "t" }), true)).toBe("new"); |
| 18 | expect(reservedShortcut(k({ meta: true, key: "W" }), true)).toBe("close"); |
| 19 | expect(reservedShortcut(k({ meta: true, key: "l" }), true)).toBe("focus-url"); |
| 20 | expect(reservedShortcut(k({ control: true, key: "t" }), false)).toBe("new"); |
| 21 | expect(reservedShortcut(k({ meta: true, key: "r" }), true)).toBe("reload"); // even while the page has the keyboard |
| 22 | expect(reservedShortcut(k({ control: true, key: "r" }), false)).toBe("reload"); |
| 23 | expect(reservedShortcut(k({ meta: true, shift: true, key: "R" }), true)).toBeNull(); // ⌘⇧R is the AI Reader's (the menu's) |
| 24 | }); |
| 25 | it("leaves everything else to the page", () => { |
| 26 | expect(reservedShortcut(k({ meta: true, key: "k" }), true)).toBeNull(); // the page's own search box |
| 27 | expect(reservedShortcut(k({ meta: true, key: "]", code: "BracketRight" }), true)).toBeNull(); // ⌘] (forward) stays with the page first: editors indent with it |
| 28 | expect(reservedShortcut(k({ meta: true, key: "c" }), true)).toBeNull(); |
| 29 | expect(reservedShortcut(k({ key: "]" }), true)).toBeNull(); |
| 30 | expect(reservedShortcut(k({ control: true, key: "t" }), true)).toBeNull(); // Ctrl+T on a Mac is the page's |
| 31 | expect(reservedShortcut(k({ meta: true, shift: true, code: "BracketRight", key: "}", type: "keyUp" }), true)).toBeNull(); |
| 32 | }); |
| 33 | }); |