|
| 1 | +import { beforeEach, expect, test } from "bun:test" |
| 2 | +import { InputRenderable } from "@opentui/core" |
| 3 | +import path from "node:path" |
| 4 | +import { takeDraft } from "../src/component/prompt/draft-stash" |
| 5 | +import { createAppFixture } from "./fixture/app" |
| 6 | +import { json } from "./fixture/tui-client" |
| 7 | + |
| 8 | +const sizes = [ |
| 9 | + { width: 100, height: 42 }, |
| 10 | + { width: 36, height: 30 }, |
| 11 | +] |
| 12 | + |
| 13 | +const exampleLogo = "█▀▀ █ █ █▀▀ ▀█▀ █▀█ █▄█" |
| 14 | + |
| 15 | +const customLogo = "█▀▀▀ █ █ █▀▀▀ ▀▀█▀▀ █▀▀█ █▄ ▄█" |
| 16 | + |
| 17 | +beforeEach(() => { |
| 18 | + takeDraft(undefined) |
| 19 | +}) |
| 20 | + |
| 21 | +test.each(sizes)("custom logos replace home and stats and restore on disable (%j)", async (size) => { |
| 22 | + await using setup = await createAppFixture({ |
| 23 | + ...size, |
| 24 | + config: { |
| 25 | + animations: false, |
| 26 | + tabs: { mode: "off" }, |
| 27 | + plugins: ["-local.custom-logo", path.join(import.meta.dir, "fixture/plugin/custom-logo")], |
| 28 | + }, |
| 29 | + fetch: stats, |
| 30 | + }) |
| 31 | + await setup.ready |
| 32 | + await setup.waitForFrame((frame) => frame.includes(exampleLogo) && frame.includes("Ask anything")) |
| 33 | + expect(setup.captureCharFrame()).toContain("█ █ █ ▀▀█ █ █ █ █▀█") |
| 34 | + expect(setup.captureCharFrame()).toContain("▀▀▀ ▀▀▀ ▀▀▀ ▀ ▀▀▀ █ █") |
| 35 | + expect(setup.captureCharFrame()).toContain("Your coding companion") |
| 36 | + expect(setup.captureCharFrame()).not.toContain("█▀▀█ █▀▀█ █▀▀█ █▀▀▄") |
| 37 | + |
| 38 | + await openStats(setup) |
| 39 | + await setup.waitForFrame((frame) => frame.includes(exampleLogo) && frame.includes("TOKENS")) |
| 40 | + expect(setup.captureCharFrame()).toContain("█ █ █ ▀▀█ █ █ █ █▀█") |
| 41 | + expect(setup.captureCharFrame()).toContain("▀▀▀ ▀▀▀ ▀▀▀ ▀ ▀▀▀ █ █") |
| 42 | + expect(setup.captureCharFrame()).toContain("Your coding companion") |
| 43 | + expect(setup.captureCharFrame()).not.toContain("█▀▀█ █▀▀█ █▀▀█ █▀▀▄") |
| 44 | + setup.mockInput.pressEscape() |
| 45 | + await setup.waitForFrame((frame) => frame.includes("Ask anything") && !frame.includes("TOKENS")) |
| 46 | + |
| 47 | + await openPlugin(setup) |
| 48 | + await setup.waitForFrame((frame) => frame.includes("disable")) |
| 49 | + setup.mockInput.pressEnter() |
| 50 | + await setup.waitForFrame((frame) => frame.includes("inactive")) |
| 51 | + setup.mockInput.pressEscape() |
| 52 | + await setup.waitForFrame((frame) => frame.includes("█▀▀█") && frame.includes("Ask anything")) |
| 53 | + expect(setup.captureCharFrame()).not.toContain(exampleLogo) |
| 54 | + |
| 55 | + await openStats(setup) |
| 56 | + await setup.waitForFrame((frame) => frame.includes("TOKENS")) |
| 57 | + expect(setup.captureCharFrame()).not.toContain(exampleLogo) |
| 58 | + expect(setup.captureCharFrame().includes("█▀▀█")).toBe(size.height >= 38) |
| 59 | + setup.mockInput.pressEscape() |
| 60 | + await setup.waitForFrame((frame) => frame.includes("Ask anything") && !frame.includes("TOKENS")) |
| 61 | + |
| 62 | + await openPlugin(setup) |
| 63 | + await setup.waitForFrame((frame) => frame.includes("inactive")) |
| 64 | + setup.mockInput.pressEnter() |
| 65 | + await setup.waitForFrame((frame) => frame.includes("disable")) |
| 66 | + setup.mockInput.pressEscape() |
| 67 | + await setup.waitForFrame((frame) => frame.includes(exampleLogo) && frame.includes("Ask anything")) |
| 68 | + await openStats(setup) |
| 69 | + await setup.waitForFrame((frame) => frame.includes(exampleLogo) && frame.includes("TOKENS")) |
| 70 | +}) |
| 71 | + |
| 72 | +test.each(sizes)("built-in logos remain without a custom plugin (%j)", async (size) => { |
| 73 | + await using setup = await createAppFixture({ |
| 74 | + ...size, |
| 75 | + config: { animations: false, tabs: { mode: "off" }, plugins: ["-local.custom-logo"] }, |
| 76 | + fetch: stats, |
| 77 | + }) |
| 78 | + await setup.ready |
| 79 | + await setup.waitForFrame((frame) => frame.includes("█▀▀█") && frame.includes("Ask anything")) |
| 80 | + await openStats(setup) |
| 81 | + await setup.waitForFrame((frame) => frame.includes("TOKENS")) |
| 82 | + expect(setup.captureCharFrame().includes("█▀▀█")).toBe(size.height >= 38) |
| 83 | +}) |
| 84 | + |
| 85 | +test.each(sizes)("project plugin shows CUSTOM glyphs on Home and keeps the stats logo (%j)", async (size) => { |
| 86 | + await using setup = await createAppFixture({ |
| 87 | + ...size, |
| 88 | + config: { |
| 89 | + animations: false, |
| 90 | + tabs: { mode: "off" }, |
| 91 | + plugins: ["local.custom-logo"], |
| 92 | + }, |
| 93 | + fetch: stats, |
| 94 | + }) |
| 95 | + await setup.ready |
| 96 | + await setup.waitForFrame((frame) => frame.includes(customLogo) && frame.includes("Ask anything")) |
| 97 | + expect(setup.captureCharFrame()).toContain("█ █ █ ▀▀▀█ █ █ █ █ ▀ █") |
| 98 | + expect(setup.captureCharFrame()).toContain("▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀ ▀▀▀▀ ▀ ▀") |
| 99 | + expect(setup.captureCharFrame()).not.toContain("█▀▀█ █▀▀█ █▀▀█ █▀▀▄") |
| 100 | + await openStats(setup) |
| 101 | + await setup.waitForFrame((frame) => frame.includes("TOKENS")) |
| 102 | + expect(setup.captureCharFrame()).not.toContain(customLogo) |
| 103 | + expect(setup.captureCharFrame().includes("█▀▀█")).toBe(size.height >= 38) |
| 104 | +}) |
| 105 | + |
| 106 | +function stats(url: URL) { |
| 107 | + if (url.pathname !== "/api/experimental/session/stats") return undefined |
| 108 | + return json({ |
| 109 | + data: { |
| 110 | + range: { from: new Date(new Date().getFullYear(), 0, 1).getTime(), to: Date.now() }, |
| 111 | + sessions: 123, |
| 112 | + subagents: 0, |
| 113 | + prompts: 1, |
| 114 | + steps: 1, |
| 115 | + tokens: { input: 10, output: 5, reasoning: 2, cache: { read: 20, write: 0 } }, |
| 116 | + cost: 0, |
| 117 | + tools: { mode: "none" }, |
| 118 | + activeDays: 1, |
| 119 | + streak: 1, |
| 120 | + activity: [], |
| 121 | + models: [], |
| 122 | + }, |
| 123 | + }) |
| 124 | +} |
| 125 | + |
| 126 | +async function openStats(setup: Awaited<ReturnType<typeof createAppFixture>>) { |
| 127 | + await setup.mockInput.typeText("/stats") |
| 128 | + await setup.waitForFrame((frame) => frame.includes("Usage statistics")) |
| 129 | + setup.mockInput.pressEnter() |
| 130 | +} |
| 131 | + |
| 132 | +async function openPlugin(setup: Awaited<ReturnType<typeof createAppFixture>>) { |
| 133 | + await setup.mockInput.typeText("/plugins") |
| 134 | + await setup.waitForFrame((frame) => frame.includes("/plugins")) |
| 135 | + setup.mockInput.pressEnter() |
| 136 | + await setup.waitForFrame((frame) => frame.includes("Plugins")) |
| 137 | + await setup.waitFor(() => setup.renderer.currentFocusedEditor instanceof InputRenderable) |
| 138 | + await setup.mockInput.typeText("custom-logo") |
| 139 | +} |
0 commit comments