This repository has been archived on 2026-10-08. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
maestro/web/src/keys.test.ts
T
Miguel PalhasandClaude Opus 5 031c80a40b
ci / rust (pull_request) Successful in 2m28s
ci / web (pull_request) Successful in 23s
ci / web (push) Successful in 26s
ci / rust (push) Successful in 1m38s
test(maestro): give the SPA a test runner and a reachable pure core
The browser app had no tests and no way to run any: package.json shipped
dev/build/preview/typecheck, and CI installed Node and pnpm but never ran
anything with them. Its densest logic was module-private, so even with a
runner none of it was reachable.

Extracts four pure modules out of DOM-heavy ones — tree.ts (directory
grouping), keys.ts (terminal escape encoding), paths.ts (completion
arithmetic), html.ts (one escaper, replacing four copies). Extraction
rather than `export` because attach.ts imports xterm's CSS at module
level, which a node test cannot load.

CatalogStore takes an injectable socket factory, scheduler and refetch, so
the reducer and the backoff schedule run without a server. snapshot() now
returns a copy: it returned the live object while events mutated it in
place, so listeners could not diff and every event rebuilt the whole tree.

36 tests across 6 files, and a `web` CI job running typecheck, test and
build. vitest is pinned to 2.x — 4.x requires vite >= 6 and this is vite 5.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-22 14:08:14 +01:00

46 lines
1.5 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { applyModsToChar, cursorSeq, toCtrl } from "./keys.js";
describe("toCtrl", () => {
it("maps letters to their control code, case-insensitively", () => {
expect(toCtrl("a")).toBe("\x01");
expect(toCtrl("A")).toBe("\x01");
expect(toCtrl("c")).toBe("\x03");
expect(toCtrl("[")).toBe("\x1b");
});
it("handles the two specials outside the @-_ range", () => {
expect(toCtrl(" ")).toBe("\x00");
expect(toCtrl("?")).toBe("\x7f");
});
it("passes through anything it has no mapping for", () => {
expect(toCtrl("1")).toBe("1");
expect(toCtrl("é")).toBe("é");
expect(toCtrl("abc")).toBe("abc");
expect(toCtrl("")).toBe("");
});
});
describe("applyModsToChar", () => {
it("composes ctrl and alt, with ESC outermost", () => {
expect(applyModsToChar("a", false, false)).toBe("a");
expect(applyModsToChar("a", true, false)).toBe("\x01");
expect(applyModsToChar("a", false, true)).toBe("\x1ba");
expect(applyModsToChar("a", true, true)).toBe("\x1b\x01");
});
});
describe("cursorSeq", () => {
it("uses the bare CSI form when unmodified", () => {
expect(cursorSeq("A", false, false)).toBe("\x1b[A");
});
it("uses the xterm modifier encoding n = 1 + alt(2) + ctrl(4)", () => {
expect(cursorSeq("A", false, true)).toBe("\x1b[1;3A");
expect(cursorSeq("A", true, false)).toBe("\x1b[1;5A");
expect(cursorSeq("A", true, true)).toBe("\x1b[1;7A");
});
});