|
| 1 | +/** @jsxImportSource @opentui/solid */ |
| 2 | +import { expect, test } from "bun:test" |
| 3 | +import type { TuiSlotPlugin } from "@opencode-ai/plugin/tui" |
| 4 | +import { testRender } from "@opentui/solid" |
| 5 | +import { createSignal } from "solid-js" |
| 6 | +import Mcp from "../../src/feature-plugins/sidebar/mcp" |
| 7 | +import Lsp from "../../src/feature-plugins/sidebar/lsp" |
| 8 | +import { createTuiPluginApi } from "../fixture/tui-plugin" |
| 9 | + |
| 10 | +test.each([ |
| 11 | + { plugin: Mcp, label: "MCP", row: "server-one" }, |
| 12 | + { plugin: Lsp, label: "LSP", row: "server-one" }, |
| 13 | +])("$label collapse survives remounts and is shared across sessions", async ({ plugin, label, row }) => { |
| 14 | + const api = createTuiPluginApi() |
| 15 | + Object.assign(api.state, { config: { lsp: true } }) |
| 16 | + api.state.mcp = () => ["server-one", "server-two", "server-three"].map((name) => ({ name, status: "connected" })) |
| 17 | + api.state.lsp = () => |
| 18 | + ["server-one", "server-two", "server-three"].map((id) => ({ id, root: "/tmp", status: "connected" })) |
| 19 | + let slot: TuiSlotPlugin["slots"]["sidebar_content"] |
| 20 | + const calls: string[] = [] |
| 21 | + api.slots = { |
| 22 | + register(value: TuiSlotPlugin) { |
| 23 | + const render = value.slots.sidebar_content |
| 24 | + slot = (context, props) => { |
| 25 | + calls.push(props.session_id) |
| 26 | + return render?.(context, props) |
| 27 | + } |
| 28 | + return "sidebar-test" |
| 29 | + }, |
| 30 | + } |
| 31 | + const writes: [string, unknown][] = [] |
| 32 | + const [values, setValues] = createSignal<Record<string, unknown>>({}) |
| 33 | + api.kv.get = <Value,>(key: string, fallback?: Value) => (values()[key] ?? fallback) as Value |
| 34 | + api.kv.set = (key, value) => { |
| 35 | + writes.push([key, value]) |
| 36 | + setValues((previous) => ({ ...previous, [key]: value })) |
| 37 | + } |
| 38 | + await plugin.tui(api, undefined, {} as Parameters<typeof plugin.tui>[2]) |
| 39 | + |
| 40 | + const first = await testRender(() => slot?.({ theme: api.theme }, { session_id: "one" }), { |
| 41 | + width: 70, |
| 42 | + height: 20, |
| 43 | + }) |
| 44 | + try { |
| 45 | + await first.renderOnce() |
| 46 | + expect(first.captureCharFrame()).toContain(row) |
| 47 | + await first.mockMouse.click(2, 0) |
| 48 | + await first.renderOnce() |
| 49 | + expect(first.captureCharFrame()).toContain(label) |
| 50 | + expect(first.captureCharFrame()).not.toContain(row) |
| 51 | + } finally { |
| 52 | + first.renderer.destroy() |
| 53 | + } |
| 54 | + |
| 55 | + const second = await testRender(() => slot?.({ theme: api.theme }, { session_id: "two" }), { |
| 56 | + width: 70, |
| 57 | + height: 20, |
| 58 | + }) |
| 59 | + try { |
| 60 | + await second.renderOnce() |
| 61 | + expect(calls).toEqual(["one", "two"]) |
| 62 | + expect(second.captureCharFrame()).toContain(label) |
| 63 | + expect(second.captureCharFrame()).not.toContain(row) |
| 64 | + expect(writes).toEqual([[`sidebar:${label.toLowerCase()}:open`, false]]) |
| 65 | + expect(api.kv.get(`sidebar:${label.toLowerCase()}:open`, true)).toBe(false) |
| 66 | + } finally { |
| 67 | + second.renderer.destroy() |
| 68 | + } |
| 69 | +}) |
0 commit comments