From d768b152ec1a48463e6d658fba7f04da04bf4d83 Mon Sep 17 00:00:00 2001 From: quickbeard Date: Mon, 13 Jul 2026 20:23:46 +0700 Subject: [PATCH] test(tui): cover home hint placement alignment Export the which-key HomeHint and add a render test asserting the home_bottom hint left-aligns when placement is "start" (the top-left session banner) and stays centered by default (the home route). Co-Authored-By: Claude Opus 4.8 (1M context) --- .../src/feature-plugins/system/which-key.tsx | 2 +- .../which-key-home-hint.test.tsx | 48 +++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 packages/tui/test/feature-plugins/which-key-home-hint.test.tsx diff --git a/packages/tui/src/feature-plugins/system/which-key.tsx b/packages/tui/src/feature-plugins/system/which-key.tsx index 646c02ff53..bcb1942f5d 100644 --- a/packages/tui/src/feature-plugins/system/which-key.tsx +++ b/packages/tui/src/feature-plugins/system/which-key.tsx @@ -168,7 +168,7 @@ function layout(value: unknown): Layout { return "dock" } -function HomeHint(props: { api: TuiPluginApi; placement?: "center" | "start" }) { +export function HomeHint(props: { api: TuiPluginApi; placement?: "center" | "start" }) { const trigger = commandShortcut(props.api, command.toggle) const look = createMemo(() => skin(props.api)) diff --git a/packages/tui/test/feature-plugins/which-key-home-hint.test.tsx b/packages/tui/test/feature-plugins/which-key-home-hint.test.tsx new file mode 100644 index 0000000000..7b5decd868 --- /dev/null +++ b/packages/tui/test/feature-plugins/which-key-home-hint.test.tsx @@ -0,0 +1,48 @@ +/** @jsxImportSource @opentui/solid */ +import { expect, test } from "bun:test" +import { testRender, useRenderer } from "@opentui/solid" +import { createDefaultOpenTuiKeymap } from "@opentui/keymap/opentui" +import { RGBA } from "@opentui/core" +import type { JSX } from "solid-js" +import type { TuiPluginApi } from "@opencode-ai/plugin/tui" +import { OpencodeKeymapProvider } from "../../src/keymap" +import { HomeHint } from "../../src/feature-plugins/system/which-key" + +const api = { + theme: { current: new Proxy({}, { get: () => RGBA.fromInts(200, 200, 200) }) }, + keys: { formatSequence: () => "" }, +} as unknown as TuiPluginApi + +function Harness(props: { children: JSX.Element }) { + return {props.children} +} + +async function hintIndent(placement?: "center" | "start") { + const app = await testRender( + () => ( + + + + ), + { width: 80, height: 10 }, + ) + try { + await app.renderOnce() + const line = app + .captureCharFrame() + .split("\n") + .find((row) => row.includes("shortcuts")) + expect(line).toBeDefined() + return line!.length - line!.trimStart().length + } finally { + app.renderer.destroy() + } +} + +test("left-aligns the home hint when placement is start", async () => { + expect(await hintIndent("start")).toBe(0) +}) + +test("centers the home hint by default", async () => { + expect(await hintIndent()).toBeGreaterThan(0) +})