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
site icons (favicons) in tabs, address bar suggestions and the bookmarks panel
7249579
15 hours, 50 minutes ago
History
shortcuts.test.ts · 2.2 KB · 30 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 and ⌘L", () => { |
| 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 | }); |
| 22 | it("leaves everything else to the page", () => { |
| 23 | expect(reservedShortcut(k({ meta: true, key: "k" }), true)).toBeNull(); // the page's own search box |
| 24 | expect(reservedShortcut(k({ meta: true, key: "]", code: "BracketRight" }), true)).toBeNull(); // ⌘] (forward) stays with the page first: editors indent with it |
| 25 | expect(reservedShortcut(k({ meta: true, key: "c" }), true)).toBeNull(); |
| 26 | expect(reservedShortcut(k({ key: "]" }), true)).toBeNull(); |
| 27 | expect(reservedShortcut(k({ control: true, key: "t" }), true)).toBeNull(); // Ctrl+T on a Mac is the page's |
| 28 | expect(reservedShortcut(k({ meta: true, shift: true, code: "BracketRight", key: "}", type: "keyUp" }), true)).toBeNull(); |
| 29 | }); |
| 30 | }); |