import type { Theme } from "@earendil-works/pi-coding-agent"; import { visibleWidth } from "@earendil-works/pi-tui"; import { describe, expect, it, vi } from "vitest"; import { DIMENSIONS, type ModelAggregate } from "../core"; import { type DashboardData, IqDashboardComponent, IqScanComponent, } from "../ui"; const theme = { fg: (_color: string, text: string) => text, bold: (text: string) => text, } as Theme; function model(): ModelAggregate { return { model: "openai-codex/gpt-5.6-sol", score: 113.6, sessions: 8, minimum: 111, maximum: 116, lastScoredAt: "2026-08-24T00:00:00Z", dimensions: Object.fromEntries( DIMENSIONS.map((dimension) => [dimension.name, 112]), ) as ModelAggregate["dimensions"], evidence: 742, }; } function data(): DashboardData { return { judge: "openai-codex/gpt-5.6-luna", stateDirectory: "/state/pi/iq", leaderboard: [model()], records: [], pending: 3, unranked: 0, storageErrors: 0, }; } describe("IQ UI", () => { it.each([32, 42, 60, 92])( "renders responsive leaderboard within %i columns", (width) => { const component = new IqDashboardComponent( theme, data(), vi.fn(), vi.fn(), ); const lines = component.render(width); const rendered = lines.join("\n"); expect(rendered).toContain("personal work ability"); expect(rendered).toContain("[LEADERBOARD]"); expect(rendered).toContain("113.6"); expect(rendered.match(/3 unscored/g)).toHaveLength(1); for (const line of lines) expect(visibleWidth(line)).toBeLessThanOrEqual(width); }, ); it("supports scan, tabs, and close without hidden actions", () => { const done = vi.fn(); const component = new IqDashboardComponent(theme, data(), vi.fn(), done); component.handleInput("s"); expect(done).toHaveBeenCalledWith("scan"); component.handleInput("q"); expect(done).toHaveBeenCalledWith(undefined); }); it("renders cancellable scan progress within narrow and wide terminals", () => { const requestRender = vi.fn(); const component = new IqScanComponent({ requestRender } as never, theme, { phase: "judge", model: "openai-codex/gpt-5.6-luna", currentName: "long representative session", session: 1, sessions: 3, chunk: 4, chunks: 27, evidence: 12, cost: 0.1, failures: 0, startedAt: Date.now(), }); for (const width of [32, 92]) for (const line of component.render(width)) expect(visibleWidth(line)).toBeLessThanOrEqual(width); component.handleInput("\u001b"); expect(component.signal.aborted).toBe(true); component.dispose(); }); });