52 lines · 2.3 KB · TypeScriptRaw
import { describe, expect, it } from "vitest";import { parseScreen } from "../lib/describe-screen";/** What `describe` answers, as argent prints it: a header, the root, one element a line. */const SCREEN = [ "Source: ax-service", "Mode: flat", "", "ROOT AXGroup (0.000, 0.000, 1.000, 1.000)", "", ' AXStaticText "Start a session" (0.069, 0.074, 0.543, 0.046)', ' AXButton "loop" id="new-session-project-loop" (0.117, 0.230, 0.767, 0.038)', ' AXGroup value="Walk one" id="new-session-prompt" (0.117, 0.596, 0.767, 0.024)', ' AXGroup id="join-screen" (0.095, 0.705, 0.810, 0.024)', ' AXGroup "Typing Predictions" (0.000, 0.620, 0.886, 0.048)', ' AXImage "q" (0.006, 0.675, 0.098, 0.061)', ' AXButton "Start" id="new-session-start" (0.683, 0.733, 0.200, 0.092)', ' AXButton "shift" id="shift" (0.011, 0.798, 0.128, 0.061)', ' AXButton "Walk one, loop · loop-mac · 0s, stand-in: heard "Walk one"" id="code-card-32e5d0b3-4f96-41d3-8ef3-25dfe22f1574" (0.112, 0.295, 0.776, 0.059)', ' AXGroup "Send an instruction — a session that isn\'t listening picks it up on its next poll" value="plan the day" id="page-session-card" (0.121, 0.364, 0.757, 0.048)',].join("\n");describe("reading the screen", () => { const screen = parseScreen(SCREEN); const byId = (id: string) => screen.find((element) => element.id === id); it("takes one element a line, and neither the header nor the root", () => { expect(screen).toHaveLength(10); expect(screen[0]).toEqual({ role: "AXStaticText", label: "Start a session", value: "", id: "", frame: { x: 0.069, y: 0.074, width: 0.543, height: 0.046 }, }); }); it("keeps a label that holds quotes of its own whole", () => { const card = screen.find((element) => element.id.startsWith("code-card-")); expect(card?.label).toBe('Walk one, loop · loop-mac · 0s, stand-in: heard "Walk one"'); expect(card?.id).toBe("code-card-32e5d0b3-4f96-41d3-8ef3-25dfe22f1574"); }); it("reads a label, a value and an id off one line", () => { expect(byId("page-session-card")).toMatchObject({ label: "Send an instruction — a session that isn't listening picks it up on its next poll", value: "plan the day", }); expect(byId("new-session-prompt")).toMatchObject({ label: "", value: "Walk one" }); });});