aboutsummaryrefslogtreecommitdiff
path: root/tests/keyboard.test.ts
diff options
context:
space:
mode:
authornetop://ウィビ <paul@webb.page>2026-04-24 16:37:33 -0700
committernetop://ウィビ <paul@webb.page>2026-04-24 16:37:33 -0700
commit510fd8cbe53abb39cba2c7cbaaefcf2783dc0066 (patch)
tree8f753a33c475b285f2a297785d34cda3b0a8faed /tests/keyboard.test.ts
parent261f3bdb77799009344aab4a60686b7186ebd3b0 (diff)
downloadgraphiql-510fd8cbe53abb39cba2c7cbaaefcf2783dc0066.tar.gz
graphiql-510fd8cbe53abb39cba2c7cbaaefcf2783dc0066.zip
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
Diffstat (limited to 'tests/keyboard.test.ts')
-rw-r--r--tests/keyboard.test.ts111
1 files changed, 111 insertions, 0 deletions
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);
+});