import { describe, expect, test } from "bun:test"; import * as scripts from "./page-scripts.ts"; import { type ActionNode, navigationOf, type TextTreeNode, visibleTextOf, } from "./page-scripts.ts"; import { type ElementFacts, forbiddenReason } from "./verify/safety.ts"; /** Minimal tree: string = text node; [tag, ...children] = element. */ type Spec = string | [string, ...Spec[]]; function tree(spec: Spec): TextTreeNode { if (typeof spec === "string") { return { nodeType: 3, nodeValue: spec, firstChild: null, nextSibling: null, }; } const [tag, ...kids] = spec; const nodes = kids.map(tree); nodes.forEach((n, i) => { n.nextSibling = nodes[i + 1] ?? null; }); return { nodeType: 1, nodeValue: null, localName: tag, firstChild: nodes[0] ?? null, nextSibling: null, }; } // A store's buy button: the event JSON sits inside it. const BUY_BUTTON: Spec = [ "button", [ "script", '{"name":"add_to_cart","params":{"currency":"BRL","value":1299,"items":[{"item_id":"123"}]}}', ], ["span", "Adicionar à sacola"], ]; describe("visibleTextOf", () => { test("skips the