// Where the display stands and what its rows hold, by the width alone (src/tui/layout.ts). import { expect, test } from "bun:test" import { clipEnd, firstFit, LEFT_MIN_WIDTH, PANE_MAX_WIDTH, PANE_MIN_WIDTH, paneHints, placeDisplay, rowWidth, SIDE_MIN_WIDTH, tabAt, tabCells, transcriptMode, type TabSpec } from "../src/tui/layout.ts" test("the display stands beside the conversation from 80 columns, each column within its floor", () => { for (let width = SIDE_MIN_WIDTH; width <= 400; width++) { const p = placeDisplay({ width, enabled: true, zoomed: false }) expect(p.mode).toBe("side") // The two columns are the terminal, exactly. expect(p.left + p.pane).toBe(width) expect(p.pane).toBeGreaterThanOrEqual(PANE_MIN_WIDTH) expect(p.pane).toBeLessThanOrEqual(PANE_MAX_WIDTH) expect(p.left).toBeGreaterThanOrEqual(LEFT_MIN_WIDTH) } expect(placeDisplay({ width: 80, enabled: true, zoomed: false })).toEqual({ mode: "side", left: 45, pane: 35 }) expect(placeDisplay({ width: 120, enabled: true, zoomed: false })).toEqual({ mode: "side", left: 68, pane: 52 }) expect(placeDisplay({ width: 300, enabled: true, zoomed: false }).pane).toBe(PANE_MAX_WIDTH) // Being zoomed means nothing where there is room for both. expect(placeDisplay({ width: 120, enabled: true, zoomed: true }).mode).toBe("side") }) test("too narrow for two columns: the display is tucked away or stands in the transcript's place — never silently nothing", () => { for (let width = 1; width < SIDE_MIN_WIDTH; width++) { expect(placeDisplay({ width, enabled: true, zoomed: false })).toEqual({ mode: "tucked", left: width, pane: 0 }) expect(placeDisplay({ width, enabled: true, zoomed: true })).toEqual({ mode: "zoom", left: width, pane: width }) } expect(placeDisplay({ width: 60, enabled: false, zoomed: true })).toEqual({ mode: "off", left: 60, pane: 0 }) expect(placeDisplay({ width: 200, enabled: false, zoomed: false })).toEqual({ mode: "off", left: 200, pane: 0 }) }) test("transcript: auto is compact only while the display stands beside it; a choice holds everywhere", () => { expect(transcriptMode(undefined, "side")).toBe("compact") expect(transcriptMode("auto", "side")).toBe("compact") for (const mode of ["off", "tucked", "zoom"] as const) expect(transcriptMode("auto", mode)).toBe("full") for (const mode of ["off", "tucked", "zoom", "side"] as const) { expect(transcriptMode("full", mode)).toBe("full") expect(transcriptMode("compact", mode)).toBe("compact") } }) const TABS: TabSpec[] = [ { id: "live", names: ["Live", "Live", "L"], mark: "◉" }, { id: "files", names: ["Files", "Files", "F"], count: 12 }, { id: "changes", names: ["Changes", "Chg", "C"], count: 3, mark: "●" }, { id: "bash", names: ["Bash", "Bash", "B"], count: 140 }, { id: "images", names: ["Images", "Img", "I"] }, ] test("the tab bar takes the longest labels that fit and never runs past its row", () => { expect(tabCells(80, TABS).map((c) => c.text)).toEqual([" Live ◉ ", " Files (12) ", " Changes (3) ● ", " Bash (99+) ", " Images "]) expect(tabCells(48, TABS).map((c) => c.text)).toEqual([" Live ◉ ", " Files 12 ", " Chg 3 ● ", " Bash 99+ ", " Img "]) // The narrowest pane (29 columns inside): letters, with their counts and marks. expect(tabCells(29, TABS).map((c) => c.text)).toEqual([" L◉ ", " F12 ", " C3● ", " B99+ ", " I "]) expect(tabCells(24, TABS).map((c) => c.text)).toEqual([" L ", " F ", " C ", " B ", " I "]) for (let width = 1; width <= 120; width++) { const cells = tabCells(width, TABS) expect(rowWidth(cells)).toBeLessThanOrEqual(width) // From the narrowest pane there is, every tab is there. if (width >= PANE_MIN_WIDTH - 3) expect(cells.length).toBe(TABS.length) for (const c of cells) expect(c.width).toBe(Bun.stringWidth(c.text)) } }) test("a click finds the tab under it, and the gap between two tabs is no tab", () => { const cells = tabCells(80, TABS) expect(tabAt(cells, 0)).toBe("live") expect(tabAt(cells, cells[0]!.width - 1)).toBe("live") expect(tabAt(cells, cells[0]!.width)).toBeUndefined() expect(tabAt(cells, cells[0]!.width + 1)).toBe("files") expect(tabAt(cells, rowWidth(cells) - 1)).toBe("images") expect(tabAt(cells, rowWidth(cells))).toBeUndefined() }) test("the key line and a clipped sentence fit the columns they are given", () => { for (let width = 0; width <= 100; width++) { expect(Bun.stringWidth(paneHints(width))).toBeLessThanOrEqual(width) expect(Bun.stringWidth(paneHints(width, true))).toBeLessThanOrEqual(width) expect(Bun.stringWidth(clipEnd("Waiting for approval: bash — 日本語 too", width))).toBeLessThanOrEqual(width) } // The narrowest pane still says how to leave it. expect(paneHints(PANE_MIN_WIDTH - 3)).toContain("d hide") expect(paneHints(60, true)).toContain("alt+d transcript") expect(clipEnd("short", 10)).toBe("short") expect(clipEnd("a sentence that is too long", 12)).toBe("a sentence…") expect(firstFit(20, ["a rather long form of it", "a short form", "x"])).toBe("a short form") expect(firstFit(0, ["long", "x"])).toBe("x") })