opencode/packages/tui/test/plugin/slots.test.tsx

39 lines
846 B
TypeScript
Raw Permalink Normal View History

2026-04-01 05:54:13 +08:00
/** @jsxImportSource @opentui/solid */
import { expect, test } from "bun:test"
import { createSlot, createSolidSlotRegistry, testRender, useRenderer } from "@opentui/solid"
import { onMount } from "solid-js"
type Slots = {
prompt: {}
}
test("replace slot mounts plugin content once", async () => {
let mounts = 0
const Probe = () => {
onMount(() => {
mounts += 1
})
return <box />
}
const App = () => {
const registry = createSolidSlotRegistry<Slots>(useRenderer(), {})
const Slot = createSlot(registry)
registry.register({ id: "plugin", slots: { prompt: () => <Probe /> } })
2026-04-01 05:54:13 +08:00
return (
<Slot name="prompt" mode="replace">
<box />
</Slot>
2026-04-01 05:54:13 +08:00
)
}
2026-05-18 19:44:08 +08:00
const app = await testRender(() => <App />)
try {
expect(mounts).toBe(1)
} finally {
app.renderer.destroy()
}
2026-04-01 05:54:13 +08:00
})