From 510fd8cbe53abb39cba2c7cbaaefcf2783dc0066 Mon Sep 17 00:00:00 2001 From: "netop://ウィビ" Date: Fri, 24 Apr 2026 16:37:33 -0700 Subject: Implement v0.6-1.0: shortcuts, format, export/import, splitter, timing, APQ - v0.6: matchShortcut + format(); Cmd+Shift+Enter/W/F + Cmd+Alt+arrows - v0.7: SessionStore.exportAll/importTabs with version-1 validator - v0.8: Splitter component + four resize handles persisted under layout.* - v0.10: createApqFetcher (HTTP-only) wrapping shared http-body helpers - Drop .svelte re-exports from index.ts for multi-entry JSR/npm publishing --- tests/keyboard.test.ts | 111 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 tests/keyboard.test.ts (limited to 'tests/keyboard.test.ts') diff --git a/tests/keyboard.test.ts b/tests/keyboard.test.ts new file mode 100644 index 0000000..3a7f3cc --- /dev/null +++ b/tests/keyboard.test.ts @@ -0,0 +1,111 @@ + + + + +/*** IMPORT ------------------------------------------- ***/ + +import { expect, test } from "vitest"; + +/*** UTILITY ------------------------------------------ ***/ + +import { matchShortcut } from "../source/library/state/keyboard.ts"; + +type EventInit = { + altKey?: boolean; + ctrlKey?: boolean; + key: string; + metaKey?: boolean; + shiftKey?: boolean; +}; + +function makeEvent(init: EventInit): KeyboardEvent { + return { + altKey: init.altKey ?? false, + ctrlKey: init.ctrlKey ?? false, + key: init.key, + metaKey: init.metaKey ?? false, + shiftKey: init.shiftKey ?? false + } as KeyboardEvent; +} + +/*** TESTS -------------------------------------------- ***/ + +test("matchShortcut returns null for plain Enter", () => { + expect(matchShortcut(makeEvent({ key: "Enter" }))).toEqual(null); +}); + +test("matchShortcut returns null when no modifier is pressed", () => { + expect(matchShortcut(makeEvent({ key: "f", shiftKey: true }))).toEqual(null); +}); + +test("matchShortcut maps Cmd+Enter to run", () => { + expect( + matchShortcut(makeEvent({ key: "Enter", metaKey: true })) + ).toEqual({ type: "run" }); +}); + +test("matchShortcut maps Ctrl+Enter to run", () => { + expect( + matchShortcut(makeEvent({ ctrlKey: true, key: "Enter" })) + ).toEqual({ type: "run" }); +}); + +test("matchShortcut maps Cmd+Shift+Enter to newTab", () => { + expect( + matchShortcut(makeEvent({ key: "Enter", metaKey: true, shiftKey: true })) + ).toEqual({ type: "newTab" }); +}); + +test("matchShortcut maps Ctrl+Shift+Enter to newTab", () => { + expect( + matchShortcut(makeEvent({ ctrlKey: true, key: "Enter", shiftKey: true })) + ).toEqual({ type: "newTab" }); +}); + +test("matchShortcut maps Cmd+Shift+W to closeTab", () => { + expect( + matchShortcut(makeEvent({ key: "w", metaKey: true, shiftKey: true })) + ).toEqual({ type: "closeTab" }); +}); + +test("matchShortcut maps Ctrl+Shift+W to closeTab", () => { + expect( + matchShortcut(makeEvent({ ctrlKey: true, key: "W", shiftKey: true })) + ).toEqual({ type: "closeTab" }); +}); + +test("matchShortcut maps Cmd+Shift+F to format on mac", () => { + expect( + matchShortcut(makeEvent({ key: "f", metaKey: true, shiftKey: true })) + ).toEqual({ type: "format" }); +}); + +test("matchShortcut maps Ctrl+Shift+F to format on non-mac", () => { + expect( + matchShortcut(makeEvent({ ctrlKey: true, key: "F", shiftKey: true })) + ).toEqual({ type: "format" }); +}); + +test("matchShortcut maps Cmd+Alt+ArrowRight to nextTab", () => { + expect( + matchShortcut(makeEvent({ altKey: true, key: "ArrowRight", metaKey: true })) + ).toEqual({ type: "nextTab" }); +}); + +test("matchShortcut maps Ctrl+Alt+ArrowLeft to prevTab", () => { + expect( + matchShortcut(makeEvent({ altKey: true, ctrlKey: true, key: "ArrowLeft" })) + ).toEqual({ type: "prevTab" }); +}); + +test("matchShortcut ignores unrelated Cmd+key combos", () => { + expect( + matchShortcut(makeEvent({ key: "s", metaKey: true })) + ).toEqual(null); +}); + +test("matchShortcut ignores Cmd+Alt+Enter", () => { + expect( + matchShortcut(makeEvent({ altKey: true, key: "Enter", metaKey: true })) + ).toEqual(null); +}); -- cgit v1.2.3