|
7 | 7 | * spot (docs/TUI.md); headless, the mock delivers it like any click. |
8 | 8 | */ |
9 | 9 | import { describe, expect, test } from "bun:test"; |
| 10 | +import { TextRenderable } from "@opentui/core"; |
10 | 11 |
|
11 | 12 | import { defined } from "../../tests/helpers/defined.js"; |
12 | 13 | import { withTestRenderer } from "./harness"; |
13 | 14 | import { appendStreamRow } from "./shell/chrome"; |
14 | 15 | import { createAppShell } from "./shell/index"; |
15 | | -import { isUnderlined, resetUrlOpener, setUrlOpener } from "./url-links"; |
| 16 | +import { |
| 17 | + isUnderlined, |
| 18 | + paintLinkLine, |
| 19 | + resetUrlOpener, |
| 20 | + setUrlOpener, |
| 21 | + splitLinkSpans, |
| 22 | +} from "./url-links"; |
16 | 23 | import { type StreamRow } from "./stream"; |
17 | 24 |
|
18 | 25 | const CALL: StreamRow = { |
@@ -123,4 +130,62 @@ describe("Ctrl+clicking a transcript URL", () => { |
123 | 130 | { width: 80, height: 24 }, |
124 | 131 | ); |
125 | 132 | }); |
| 133 | + |
| 134 | + test("retexting the URL away disarms the node: old columns open nothing", async () => { |
| 135 | + await withTestRenderer( |
| 136 | + async (h) => { |
| 137 | + const opened: string[] = []; |
| 138 | + setUrlOpener((url) => { |
| 139 | + opened.push(url); |
| 140 | + }); |
| 141 | + try { |
| 142 | + const line = "see https://example.com/x ok"; |
| 143 | + const node = new TextRenderable(h.renderer, { content: line }); |
| 144 | + h.root.add(node); |
| 145 | + paintLinkLine(node, [splitLinkSpans([{ text: line, fg: "#fff" }])]); |
| 146 | + await h.renderOnce(); |
| 147 | + |
| 148 | + const link = findCell(h.captureCharFrame(), "example.com"); |
| 149 | + expect(link).not.toBeNull(); |
| 150 | + const at = defined(link); |
| 151 | + |
| 152 | + await h.mockMouse.click(at.x, at.y, 0, { |
| 153 | + modifiers: { ctrl: true }, |
| 154 | + }); |
| 155 | + await h.renderOnce(); |
| 156 | + expect(opened).toEqual(["https://example.com/x"]); |
| 157 | + |
| 158 | + // Retext the URL away, exactly as the row retext path does. The |
| 159 | + // handlers are setter-only (no getter to assert on), so pin the |
| 160 | + // disarm behaviorally: the old columns open nothing and hover |
| 161 | + // leaves the painted text intact. |
| 162 | + const retexted = "see nothing here"; |
| 163 | + paintLinkLine(node, [ |
| 164 | + splitLinkSpans([{ text: retexted, fg: "#fff" }]), |
| 165 | + ]); |
| 166 | + await h.renderOnce(); |
| 167 | + const frame = h.captureCharFrame(); |
| 168 | + expect(frame).toContain("nothing here"); |
| 169 | + expect(frame).not.toContain("example.com"); |
| 170 | + |
| 171 | + opened.length = 0; |
| 172 | + await h.mockMouse.click(at.x, at.y, 0, { |
| 173 | + modifiers: { ctrl: true }, |
| 174 | + }); |
| 175 | + await h.renderOnce(); |
| 176 | + expect(opened).toEqual([]); |
| 177 | + |
| 178 | + const before = h.captureCharFrame(); |
| 179 | + await h.mockMouse.moveTo(at.x, at.y, { |
| 180 | + modifiers: { ctrl: true }, |
| 181 | + }); |
| 182 | + await h.renderOnce(); |
| 183 | + expect(h.captureCharFrame()).toBe(before); |
| 184 | + } finally { |
| 185 | + resetUrlOpener(); |
| 186 | + } |
| 187 | + }, |
| 188 | + { width: 80, height: 24 }, |
| 189 | + ); |
| 190 | + }); |
126 | 191 | }); |
0 commit comments