- Added ChatBlock and ChatBlockHost with mount, finish, and dispose lifecycle callbacks. - Added InteractiveModeContext.present and resetTranscript APIs and used them to mount/repaint blocks. - Reworked controller rendering paths to emit command, event, extension, and selector outputs via ctx.present. - Implemented component and container dispose hooks in tui so loaders and child blocks cleanup timers/effects.
31 lines
949 B
TypeScript
31 lines
949 B
TypeScript
import { describe, expect, it } from "bun:test";
|
|
import { type Component, Container } from "@oh-my-pi/pi-tui";
|
|
|
|
function inert(dispose?: () => void): Component {
|
|
return { render: () => [], invalidate: () => {}, dispose };
|
|
}
|
|
|
|
describe("Container.dispose", () => {
|
|
it("calls dispose on each child and tolerates children without dispose", () => {
|
|
const order: string[] = [];
|
|
const container = new Container();
|
|
container.addChild(inert(() => order.push("a")));
|
|
container.addChild(inert()); // no dispose — must not throw
|
|
container.addChild(inert(() => order.push("c")));
|
|
|
|
expect(() => container.dispose()).not.toThrow();
|
|
expect(order).toEqual(["a", "c"]);
|
|
});
|
|
|
|
it("recurses through nested containers", () => {
|
|
let leafDisposed = 0;
|
|
const outer = new Container();
|
|
const inner = new Container();
|
|
inner.addChild(inert(() => leafDisposed++));
|
|
outer.addChild(inner);
|
|
|
|
outer.dispose();
|
|
expect(leafDisposed).toBe(1);
|
|
});
|
|
});
|