chore: cleanup
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { describe, expect, test } from "bun:test"
|
import { describe, expect, test } from "bun:test"
|
||||||
import { createOpenReviewFile, focusTerminalById, getTabReorderIndex } from "./helpers"
|
import { createOpenReviewFile, createOpenSessionFileTab, focusTerminalById, getTabReorderIndex } from "./helpers"
|
||||||
|
|
||||||
describe("createOpenReviewFile", () => {
|
describe("createOpenReviewFile", () => {
|
||||||
test("opens and loads selected review file", () => {
|
test("opens and loads selected review file", () => {
|
||||||
@@ -20,6 +20,37 @@ describe("createOpenReviewFile", () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("createOpenSessionFileTab", () => {
|
||||||
|
test("activates the opened file tab", () => {
|
||||||
|
const calls: string[] = []
|
||||||
|
const openTab = createOpenSessionFileTab({
|
||||||
|
normalizeTab: (value) => {
|
||||||
|
calls.push(`normalize:${value}`)
|
||||||
|
return `file://${value}`
|
||||||
|
},
|
||||||
|
openTab: (tab) => calls.push(`open:${tab}`),
|
||||||
|
pathFromTab: (tab) => {
|
||||||
|
calls.push(`path:${tab}`)
|
||||||
|
return tab.slice("file://".length)
|
||||||
|
},
|
||||||
|
loadFile: (path) => calls.push(`load:${path}`),
|
||||||
|
openReviewPanel: () => calls.push("review"),
|
||||||
|
setActive: (tab) => calls.push(`active:${tab}`),
|
||||||
|
})
|
||||||
|
|
||||||
|
openTab("src/a.ts")
|
||||||
|
|
||||||
|
expect(calls).toEqual([
|
||||||
|
"normalize:src/a.ts",
|
||||||
|
"open:file://src/a.ts",
|
||||||
|
"path:file://src/a.ts",
|
||||||
|
"load:src/a.ts",
|
||||||
|
"review",
|
||||||
|
"active:file://src/a.ts",
|
||||||
|
])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe("focusTerminalById", () => {
|
describe("focusTerminalById", () => {
|
||||||
test("focuses textarea when present", () => {
|
test("focuses textarea when present", () => {
|
||||||
document.body.innerHTML = `<div id="terminal-wrapper-one"><div data-component="terminal"><textarea></textarea></div></div>`
|
document.body.innerHTML = `<div id="terminal-wrapper-one"><div data-component="terminal"><textarea></textarea></div></div>`
|
||||||
|
|||||||
@@ -35,6 +35,27 @@ export const createOpenReviewFile = (input: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const createOpenSessionFileTab = (input: {
|
||||||
|
normalizeTab: (tab: string) => string
|
||||||
|
openTab: (tab: string) => void
|
||||||
|
pathFromTab: (tab: string) => string | undefined
|
||||||
|
loadFile: (path: string) => void
|
||||||
|
openReviewPanel: () => void
|
||||||
|
setActive: (tab: string) => void
|
||||||
|
}) => {
|
||||||
|
return (value: string) => {
|
||||||
|
const next = input.normalizeTab(value)
|
||||||
|
input.openTab(next)
|
||||||
|
|
||||||
|
const path = input.pathFromTab(next)
|
||||||
|
if (!path) return
|
||||||
|
|
||||||
|
input.loadFile(path)
|
||||||
|
input.openReviewPanel()
|
||||||
|
input.setActive(next)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const getTabReorderIndex = (tabs: readonly string[], from: string, to: string) => {
|
export const getTabReorderIndex = (tabs: readonly string[], from: string, to: string) => {
|
||||||
const fromIndex = tabs.indexOf(from)
|
const fromIndex = tabs.indexOf(from)
|
||||||
const toIndex = tabs.indexOf(to)
|
const toIndex = tabs.indexOf(to)
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import { useLayout } from "@/context/layout"
|
|||||||
import { useSync } from "@/context/sync"
|
import { useSync } from "@/context/sync"
|
||||||
import { createFileTabListSync } from "@/pages/session/file-tab-scroll"
|
import { createFileTabListSync } from "@/pages/session/file-tab-scroll"
|
||||||
import { FileTabContent } from "@/pages/session/file-tabs"
|
import { FileTabContent } from "@/pages/session/file-tabs"
|
||||||
import { getTabReorderIndex } from "@/pages/session/helpers"
|
import { createOpenSessionFileTab, getTabReorderIndex } from "@/pages/session/helpers"
|
||||||
import { StickyAddButton } from "@/pages/session/review-tab"
|
import { StickyAddButton } from "@/pages/session/review-tab"
|
||||||
import { setSessionHandoff } from "@/pages/session/handoff"
|
import { setSessionHandoff } from "@/pages/session/handoff"
|
||||||
|
|
||||||
@@ -96,15 +96,14 @@ export function SessionSidePanel(props: {
|
|||||||
if (!view().reviewPanel.opened()) view().reviewPanel.open()
|
if (!view().reviewPanel.opened()) view().reviewPanel.open()
|
||||||
}
|
}
|
||||||
|
|
||||||
const openTab = (value: string) => {
|
const openTab = createOpenSessionFileTab({
|
||||||
const next = normalizeTab(value)
|
normalizeTab,
|
||||||
tabs().open(next)
|
openTab: tabs().open,
|
||||||
|
pathFromTab: file.pathFromTab,
|
||||||
const path = file.pathFromTab(next)
|
loadFile: file.load,
|
||||||
if (!path) return
|
openReviewPanel,
|
||||||
file.load(path)
|
setActive: tabs().setActive,
|
||||||
openReviewPanel()
|
})
|
||||||
}
|
|
||||||
|
|
||||||
const contextOpen = createMemo(() => tabs().active() === "context" || tabs().all().includes("context"))
|
const contextOpen = createMemo(() => tabs().active() === "context" || tabs().all().includes("context"))
|
||||||
const openedTabs = createMemo(() =>
|
const openedTabs = createMemo(() =>
|
||||||
|
|||||||
Reference in New Issue
Block a user