opencode/packages/tui/test/panel.test.ts

71 lines
2.7 KiB
TypeScript

import { expect, test } from "bun:test"
import { createRoot } from "solid-js"
import { createPanelState } from "../src/context/panel"
import { SESSION_PANEL_SPLIT_MIN_WIDTH } from "../src/ui/layout"
test("presentation changes preserve the selected panel identity", () => {
createRoot((dispose) => {
const panels = createPanelState()
panels.setWidth(160)
panels.open({ plugin: "review", name: "diff", sessionID: "session" })
const current = panels.current()
expect(panels.presentation()).toBe("panel")
panels.toggleFullscreen()
expect(panels.presentation()).toBe("fullscreen")
expect(panels.current()).toBe(current)
panels.toggleFullscreen()
expect(panels.presentation()).toBe("panel")
expect(panels.current()).toBe(current)
panels.open({ plugin: "review", name: "diff", sessionID: "session" })
expect(panels.current()).toBe(current)
dispose()
})
})
test("narrow geometry overrides presentation without discarding the user's choice", () => {
createRoot((dispose) => {
const panels = createPanelState()
panels.open({ plugin: "review", name: "diff", sessionID: "session" })
panels.setWidth(SESSION_PANEL_SPLIT_MIN_WIDTH - 1)
expect(panels.canSplit()).toBe(false)
expect(panels.presentation()).toBe("fullscreen")
panels.toggleFullscreen()
panels.setWidth(SESSION_PANEL_SPLIT_MIN_WIDTH)
expect(panels.canSplit()).toBe(true)
expect(panels.presentation()).toBe("panel")
panels.toggleFullscreen()
panels.setWidth(60)
panels.setWidth(160)
expect(panels.presentation()).toBe("fullscreen")
dispose()
})
})
test("opening a different name changes the panel selection", () => {
createRoot((dispose) => {
const panels = createPanelState()
panels.open({ plugin: "review", name: "review.diff", sessionID: "session" })
const current = panels.current()
panels.open({ plugin: "review", name: "review.history", sessionID: "session" })
expect(panels.current()).not.toBe(current)
expect(panels.current()?.name).toBe("review.history")
panels.open({ plugin: "tasks", name: "tasks.list", sessionID: "session" })
expect(panels.current()).toEqual({ plugin: "tasks", name: "tasks.list", sessionID: "session" })
panels.release("review")
expect(panels.current()?.name).toBe("tasks.list")
dispose()
})
})
test("releasing a plugin contribution only closes its own selected panel", () => {
createRoot((dispose) => {
const panels = createPanelState()
panels.open({ plugin: "review", name: "diff", sessionID: "session" })
const current = panels.current()
panels.release("other")
expect(panels.current()).toBe(current)
panels.release("review")
expect(panels.current()).toBeUndefined()
dispose()
})
})