The best way to control Claude Code, Codex and more from any computer or phone
| 1 | /// <reference lib="dom" /> |
| 2 | // The DOM lib types the function this scenario runs in the page. |
| 3 | import { expect } from "e2e"; |
| 4 | import * as Effect from "effect/Effect"; |
| 5 | import * as FileSystem from "effect/FileSystem"; |
| 6 | |
| 7 | import { T3_HOME } from "../e2e.config.ts"; |
| 8 | import { runPromise, test, WEB } from "./t3.ts"; |
| 9 | |
| 10 | const EDITOR_ARGS = `${T3_HOME}/editor-args.txt`; |
| 11 | |
| 12 | /** The file's lines, or none while it does not exist. */ |
| 13 | const readLines = (file: string) => |
| 14 | runPromise( |
| 15 | Effect.gen(function* () { |
| 16 | const fs = yield* FileSystem.FileSystem; |
| 17 | if (!(yield* fs.exists(file))) return []; |
| 18 | return (yield* fs.readFileString(file)).trim().split("\n"); |
| 19 | }), |
| 20 | ); |
| 21 | |
| 22 | test( |
| 23 | "Ctrl+click on a GNU ls --hyperlink filename, whose file URI names this machine, opens that file", |
| 24 | WEB, |
| 25 | async ({ t3, app, browser, screen }) => { |
| 26 | await runPromise( |
| 27 | Effect.flatMap(FileSystem.FileSystem, (fs) => fs.remove(EDITOR_ARGS, { force: true })), |
| 28 | ); |
| 29 | const project = await t3.project("demo", { "one.txt": "hello\n" }); |
| 30 | const thread = await t3.thread({ project, title: "List", messages: ["List it"] }); |
| 31 | await t3.open(thread); |
| 32 | |
| 33 | await screen.getByRole("button", "Toggle terminal drawer").tap(); |
| 34 | const input = screen.getByRole("textbox", "Terminal input"); |
| 35 | // The input mounts before fonts and WASM finish loading and its handlers are installed. |
| 36 | await expect(input).toHaveAttribute("data-workspace-focus-default", ""); |
| 37 | await input.focus(); |
| 38 | // GNU ls writes `file://<hostname>/<path>`. Enough rows to scroll, so every row is the link. |
| 39 | await browser.keyboard.type( |
| 40 | "for i in $(seq 1 100); do command ls --hyperlink=always --color=never -1 one.txt; done; touch ls.done\n", |
| 41 | ); |
| 42 | await expect.poll(() => readLines(`${project}/ls.done`), { timeout: 30_000 }).toEqual([""]); |
| 43 | await browser.setViewport({ width: 1000, height: 700 }); |
| 44 | await app.screenshot("listed-and-resized"); |
| 45 | |
| 46 | // The terminal draws on a canvas, so point at the first cells of its middle row. |
| 47 | const canvas = await browser.evaluate(() => { |
| 48 | const box = document |
| 49 | .querySelector('[aria-label="Terminal input"]') |
| 50 | ?.parentElement?.querySelector("canvas") |
| 51 | ?.getBoundingClientRect(); |
| 52 | return box ? { x: box.x, y: box.y, width: box.width, height: box.height } : null; |
| 53 | }); |
| 54 | if (!canvas) throw new Error("The terminal canvas is not on the page."); |
| 55 | await browser.mouse.move(canvas.x + 16, canvas.y + canvas.height / 2); |
| 56 | await browser.keyboard.down("Control"); |
| 57 | await browser.mouse.down(); |
| 58 | await browser.mouse.up(); |
| 59 | await browser.keyboard.up("Control"); |
| 60 | await app.screenshot("after-ctrl-click"); |
| 61 | |
| 62 | await expect |
| 63 | .poll(() => readLines(EDITOR_ARGS), { timeout: 15_000 }) |
| 64 | .toEqual(["--classic", `${project}/one.txt`]); |
| 65 | }, |
| 66 | ); |