summaryrefslogtreecommitdiffhomepage
path: root/packages/app/src/pages/session/helpers.test.ts
diff options
context:
space:
mode:
authorAdam <[email protected]>2026-02-06 09:37:49 -0600
committerGitHub <[email protected]>2026-02-06 09:37:49 -0600
commita4bc883595df9ea0f752079519081bc602408553 (patch)
tree583f21642f431899abe1dfb1f6bd9b2c01dc0206 /packages/app/src/pages/session/helpers.test.ts
parentc07077f96c0019b2e18e0e8e1e0383deda08b3e6 (diff)
downloadopencode-a4bc883595df9ea0f752079519081bc602408553.tar.gz
opencode-a4bc883595df9ea0f752079519081bc602408553.zip
chore: refactoring and tests (#12468)
Diffstat (limited to 'packages/app/src/pages/session/helpers.test.ts')
-rw-r--r--packages/app/src/pages/session/helpers.test.ts61
1 files changed, 61 insertions, 0 deletions
diff --git a/packages/app/src/pages/session/helpers.test.ts b/packages/app/src/pages/session/helpers.test.ts
new file mode 100644
index 000000000..0afc7eb6a
--- /dev/null
+++ b/packages/app/src/pages/session/helpers.test.ts
@@ -0,0 +1,61 @@
+import { describe, expect, test } from "bun:test"
+import { combineCommandSections, createOpenReviewFile, focusTerminalById } from "./helpers"
+
+describe("createOpenReviewFile", () => {
+ test("opens and loads selected review file", () => {
+ const calls: string[] = []
+ const openReviewFile = createOpenReviewFile({
+ showAllFiles: () => calls.push("show"),
+ tabForPath: (path) => {
+ calls.push(`tab:${path}`)
+ return `file://${path}`
+ },
+ openTab: (tab) => calls.push(`open:${tab}`),
+ loadFile: (path) => calls.push(`load:${path}`),
+ })
+
+ openReviewFile("src/a.ts")
+
+ expect(calls).toEqual(["show", "tab:src/a.ts", "open:file://src/a.ts", "load:src/a.ts"])
+ })
+})
+
+describe("focusTerminalById", () => {
+ test("focuses textarea when present", () => {
+ document.body.innerHTML = `<div id="terminal-wrapper-one"><div data-component="terminal"><textarea></textarea></div></div>`
+
+ const focused = focusTerminalById("one")
+
+ expect(focused).toBe(true)
+ expect(document.activeElement?.tagName).toBe("TEXTAREA")
+ })
+
+ test("falls back to terminal element focus", () => {
+ document.body.innerHTML = `<div id="terminal-wrapper-two"><div data-component="terminal" tabindex="0"></div></div>`
+ const terminal = document.querySelector('[data-component="terminal"]') as HTMLElement
+ let pointerDown = false
+ terminal.addEventListener("pointerdown", () => {
+ pointerDown = true
+ })
+
+ const focused = focusTerminalById("two")
+
+ expect(focused).toBe(true)
+ expect(document.activeElement).toBe(terminal)
+ expect(pointerDown).toBe(true)
+ })
+})
+
+describe("combineCommandSections", () => {
+ test("keeps section order stable", () => {
+ const result = combineCommandSections([
+ [{ id: "a", title: "A" }],
+ [
+ { id: "b", title: "B" },
+ { id: "c", title: "C" },
+ ],
+ ])
+
+ expect(result.map((item) => item.id)).toEqual(["a", "b", "c"])
+ })
+})