|
7 | 7 | createSessionTabs, |
8 | 8 | focusTerminalById, |
9 | 9 | getTabReorderIndex, |
| 10 | + shouldFocusTerminalOnKeyDown, |
10 | 11 | } from "./helpers" |
11 | 12 |
|
12 | 13 | describe("createOpenReviewFile", () => { |
@@ -86,6 +87,26 @@ describe("focusTerminalById", () => { |
86 | 87 | }) |
87 | 88 | }) |
88 | 89 |
|
| 90 | +describe("shouldFocusTerminalOnKeyDown", () => { |
| 91 | + test("skips pure modifier keys", () => { |
| 92 | + expect(shouldFocusTerminalOnKeyDown(new KeyboardEvent("keydown", { key: "Meta", metaKey: true }))).toBe(false) |
| 93 | + expect(shouldFocusTerminalOnKeyDown(new KeyboardEvent("keydown", { key: "Control", ctrlKey: true }))).toBe(false) |
| 94 | + expect(shouldFocusTerminalOnKeyDown(new KeyboardEvent("keydown", { key: "Alt", altKey: true }))).toBe(false) |
| 95 | + expect(shouldFocusTerminalOnKeyDown(new KeyboardEvent("keydown", { key: "Shift", shiftKey: true }))).toBe(false) |
| 96 | + }) |
| 97 | + |
| 98 | + test("skips shortcut key combos", () => { |
| 99 | + expect(shouldFocusTerminalOnKeyDown(new KeyboardEvent("keydown", { key: "c", metaKey: true }))).toBe(false) |
| 100 | + expect(shouldFocusTerminalOnKeyDown(new KeyboardEvent("keydown", { key: "c", ctrlKey: true }))).toBe(false) |
| 101 | + expect(shouldFocusTerminalOnKeyDown(new KeyboardEvent("keydown", { key: "ArrowLeft", altKey: true }))).toBe(false) |
| 102 | + }) |
| 103 | + |
| 104 | + test("keeps plain typing focused on terminal", () => { |
| 105 | + expect(shouldFocusTerminalOnKeyDown(new KeyboardEvent("keydown", { key: "a" }))).toBe(true) |
| 106 | + expect(shouldFocusTerminalOnKeyDown(new KeyboardEvent("keydown", { key: "A", shiftKey: true }))).toBe(true) |
| 107 | + }) |
| 108 | +}) |
| 109 | + |
89 | 110 | describe("getTabReorderIndex", () => { |
90 | 111 | test("returns target index for valid drag reorder", () => { |
91 | 112 | expect(getTabReorderIndex(["a", "b", "c"], "a", "c")).toBe(2) |
|
0 commit comments