|
| 1 | +import { readFileSync } from "node:fs"; |
| 2 | +import { join } from "node:path"; |
1 | 3 | import { describe, expect, it } from "vitest"; |
2 | | -import { composerKeepsEscape } from "./composer-escape"; |
| 4 | +import { composerEscapeAction } from "./composer-escape"; |
| 5 | + |
| 6 | +const COMPOSER = readFileSync(join(__dirname, "DashboardAgentComposer.tsx"), "utf8"); |
3 | 7 |
|
4 | 8 | describe("Escape while the composer has focus", () => { |
5 | | - it("is kept by the composer while there is a draft, so the panel stays open", () => { |
6 | | - expect(composerKeepsEscape("half a question about a failing run")).toBe(true); |
| 9 | + it("is kept by the composer on the first Escape with a draft, so the panel stays open", () => { |
| 10 | + expect(composerEscapeAction("half a question about a failing run", true)).toBe("swallow"); |
| 11 | + }); |
| 12 | + |
| 13 | + it("lets a second consecutive Escape through, so the panel closes", () => { |
| 14 | + expect(composerEscapeAction("half a question about a failing run", false)).toBe("pass"); |
| 15 | + }); |
| 16 | + |
| 17 | + it("guards the draft again once the guard is re-armed by typing", () => { |
| 18 | + expect(composerEscapeAction("half a question, now longer", true)).toBe("swallow"); |
7 | 19 | }); |
8 | 20 |
|
9 | | - it("closes the panel when there is nothing to lose", () => { |
10 | | - expect(composerKeepsEscape("")).toBe(false); |
| 21 | + it("closes the panel on the first Escape when there is nothing to lose", () => { |
| 22 | + expect(composerEscapeAction("", true)).toBe("pass"); |
11 | 23 | }); |
12 | 24 |
|
13 | 25 | it("reads whitespace as nothing to lose, matching what Send accepts", () => { |
14 | | - expect(composerKeepsEscape(" \n ")).toBe(false); |
| 26 | + expect(composerEscapeAction(" \n ", true)).toBe("pass"); |
| 27 | + }); |
| 28 | +}); |
| 29 | + |
| 30 | +// Source-level checks: the guard's step is spent in the composer, not in the pure helper. |
| 31 | +describe("the composer's Escape wiring", () => { |
| 32 | + it("disarms the guard in the swallow branch, so the next Escape passes", () => { |
| 33 | + expect(COMPOSER).toMatch( |
| 34 | + /=== "swallow"\s*\)\s*\{\s*e\.preventDefault\(\);\s*escapeGuardArmed\.current = false;/ |
| 35 | + ); |
| 36 | + }); |
| 37 | + |
| 38 | + it("swallows an IME-cancelling Escape without spending the guard's step", () => { |
| 39 | + expect(COMPOSER).toMatch( |
| 40 | + /e\.key === "Escape" && e\.nativeEvent\.isComposing\s*\)\s*\{\s*e\.preventDefault\(\);\s*return;/ |
| 41 | + ); |
15 | 42 | }); |
16 | 43 | }); |
0 commit comments