@dloizides/game-e2e 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,32 @@
2
2
 
3
3
  All notable changes to `@dloizides/game-e2e` are documented here.
4
4
 
5
+ ## 1.2.0
6
+
7
+ NAV-1 "Every game menu works with arrow keys and controller", walker gap:
8
+
9
+ - The walker now finds pointer-only items whose click / pointerdown / pointerup handler is set as a property
10
+ (`el.onclick = ...`) or added with `addEventListener`, not only the `[onclick]` attribute. A visible element
11
+ with such a handler that is not focusable is reported `unreached`.
12
+ - Listeners are read through CDP `DOMDebugger.getEventListeners` (Chromium). Without CDP (Firefox, WebKit) only
13
+ the attribute and properties are checked, and each result carries a `notes` line saying so.
14
+ - Delegation: an element that contains a walk control, or sits inside one, is never flagged, so a listener on a
15
+ menu container does not flag the container or its children. When nested elements are both flagged, only the
16
+ innermost is reported.
17
+ - `WalkResult.notes` (new, printed as `note:` by `renderWalk`).
18
+
19
+ ## 1.1.0
20
+
21
+ NAV-1 "Every game menu works with arrow keys and controller", phase 1:
22
+
23
+ - `walkMenus()` / `expectMenuWalkable()`: open each screen, walk every focusable control by arrow keys and
24
+ by a stubbed gamepad (breadth-first from the focused control), report unreached controls, a dialog that
25
+ opens without focus inside it, sliders that ignore Left/Right, and Escape / B that does not close a dialog.
26
+ Exemptions take a selector and a printed reason.
27
+ - `stubGamepad()`: a `navigator.getGamepads()` stand-in driven from the test (`PadDriver.press`).
28
+ - `renderWalk()`, `walkFailed()`, `WALK_INPUTS`.
29
+ - Depends on `@dloizides/game-input` ^1.5.1 for the shared focusable and dialog selectors.
30
+
5
31
  ## 1.0.0
6
32
 
7
33
  First release. Playwright helpers that Aurora, Surge and Morphe each carried a copy of, unified on the
package/dist/index.d.mts CHANGED
@@ -211,4 +211,49 @@ declare function expectNoHorizontalOverflowAcrossRoutes(readings: readonly Route
211
211
  /** Single-route convenience over `expectNoHorizontalOverflowAcrossRoutes`. */
212
212
  declare function expectNoHorizontalOverflow(page: Page, where: string): Promise<OverflowReading>;
213
213
 
214
- export { ANTI_ALIAS_TOLERANCE, type Band, type Box, CANVAS_TIMEOUT_MS, CONTROL_SELECTOR, type CanvasFrame, type CanvasOptions, type ControlIdentity, DEFAULT_CANVAS_SELECTOR, DESKTOP_DEVICE, DESKTOP_SIZE, type DiffOptions, type DiffResult, EXACT, FIT_TIMEOUT_MS, type FitOptions, GAME_SHELL_HEIGHT_VAR, type GameProject, type GameProjectsOptions, type GateSummary, MAX_REPORTED, MIN_TARGET_PX, type OverflowMetrics, type OverflowReading, PHONE_DEVICE, PHONE_SIZE, type PageFactory, RELAYOUT_TIMEOUT_MS, type Rect, type Region, type RegionInput, type RouteAudit, type RouteOverflow, type ShrinkOptions, type Size, type TargetAudit, type TargetFinding, type TargetProbeFunnel, armVisibleHeight, auditRoute, auditTouchTargets, canvasBoxToPage, controlName, countDiff, desktop, deviceDescriptor, diffPngs, domControls, expectCanvasHeight, expectCanvasInside, expectFitTo, expectNoHorizontalOverflow, expectNoHorizontalOverflowAcrossRoutes, expectTouchTargets, expectTouchTargetsAcrossRoutes, findOverlaps, findOverlapsWithin, gameProjects, horizontalOverflowPx, measureHorizontalOverflow, overlaps, phone, readHorizontalOverflow, regionDiff, renderFindings, renderOverflow, renderRouteAudit, routeProblems, shrinkVisibleHeight, summariseOverflow, summariseTouchTargets, toOverflowReading };
214
+ declare const WALK_INPUTS: {
215
+ readonly keys: "keys";
216
+ readonly pad: "pad";
217
+ };
218
+ type WalkInput = (typeof WALK_INPUTS)[keyof typeof WALK_INPUTS];
219
+ interface WalkResult {
220
+ screen: string;
221
+ via: WalkInput;
222
+ reached: number;
223
+ total: number;
224
+ unreached: string[];
225
+ problems: string[];
226
+ exempt: string[];
227
+ notes: string[];
228
+ }
229
+ declare const walkFailed: (r: WalkResult) => boolean;
230
+ /** One block per screen and input: reached/total, then every unreached control, problem and exemption. */
231
+ declare function renderWalk(results: readonly WalkResult[]): string;
232
+
233
+ interface WalkScreen {
234
+ name: string;
235
+ /** Opens the screen from a fresh page (clicks, a URL, a test hook). */
236
+ open: (page: Page) => Promise<void>;
237
+ /** Controls deliberately not walkable, each with a reason (printed in the report). */
238
+ exempt?: ReadonlyArray<{
239
+ selector: string;
240
+ reason: string;
241
+ }>;
242
+ }
243
+ interface WalkOptions {
244
+ via?: readonly WalkInput[];
245
+ }
246
+ /** Walks every screen by arrow keys and by a stubbed pad (default both) and returns one result per screen and input. */
247
+ declare function walkMenus(page: Page, screens: readonly WalkScreen[], options?: WalkOptions): Promise<WalkResult[]>;
248
+ /** NAV-1 gate: throws, listing every unreached control and problem, unless every screen walks by keys and pad. */
249
+ declare function expectMenuWalkable(page: Page, screens: readonly WalkScreen[], options?: WalkOptions): Promise<void>;
250
+
251
+ interface PadDriver {
252
+ press(button: number): Promise<void>;
253
+ hold(axis: number, value: number): Promise<void>;
254
+ }
255
+ declare const STUB_FRAMES = 3;
256
+ /** Replaces navigator.getGamepads with one standard pad (call before the page loads); returns its driver. */
257
+ declare function stubGamepad(page: Page): Promise<PadDriver>;
258
+
259
+ export { ANTI_ALIAS_TOLERANCE, type Band, type Box, CANVAS_TIMEOUT_MS, CONTROL_SELECTOR, type CanvasFrame, type CanvasOptions, type ControlIdentity, DEFAULT_CANVAS_SELECTOR, DESKTOP_DEVICE, DESKTOP_SIZE, type DiffOptions, type DiffResult, EXACT, FIT_TIMEOUT_MS, type FitOptions, GAME_SHELL_HEIGHT_VAR, type GameProject, type GameProjectsOptions, type GateSummary, MAX_REPORTED, MIN_TARGET_PX, type OverflowMetrics, type OverflowReading, PHONE_DEVICE, PHONE_SIZE, type PadDriver, type PageFactory, RELAYOUT_TIMEOUT_MS, type Rect, type Region, type RegionInput, type RouteAudit, type RouteOverflow, STUB_FRAMES, type ShrinkOptions, type Size, type TargetAudit, type TargetFinding, type TargetProbeFunnel, WALK_INPUTS, type WalkInput, type WalkOptions, type WalkResult, type WalkScreen, armVisibleHeight, auditRoute, auditTouchTargets, canvasBoxToPage, controlName, countDiff, desktop, deviceDescriptor, diffPngs, domControls, expectCanvasHeight, expectCanvasInside, expectFitTo, expectMenuWalkable, expectNoHorizontalOverflow, expectNoHorizontalOverflowAcrossRoutes, expectTouchTargets, expectTouchTargetsAcrossRoutes, findOverlaps, findOverlapsWithin, gameProjects, horizontalOverflowPx, measureHorizontalOverflow, overlaps, phone, readHorizontalOverflow, regionDiff, renderFindings, renderOverflow, renderRouteAudit, renderWalk, routeProblems, shrinkVisibleHeight, stubGamepad, summariseOverflow, summariseTouchTargets, toOverflowReading, walkFailed, walkMenus };
package/dist/index.d.ts CHANGED
@@ -211,4 +211,49 @@ declare function expectNoHorizontalOverflowAcrossRoutes(readings: readonly Route
211
211
  /** Single-route convenience over `expectNoHorizontalOverflowAcrossRoutes`. */
212
212
  declare function expectNoHorizontalOverflow(page: Page, where: string): Promise<OverflowReading>;
213
213
 
214
- export { ANTI_ALIAS_TOLERANCE, type Band, type Box, CANVAS_TIMEOUT_MS, CONTROL_SELECTOR, type CanvasFrame, type CanvasOptions, type ControlIdentity, DEFAULT_CANVAS_SELECTOR, DESKTOP_DEVICE, DESKTOP_SIZE, type DiffOptions, type DiffResult, EXACT, FIT_TIMEOUT_MS, type FitOptions, GAME_SHELL_HEIGHT_VAR, type GameProject, type GameProjectsOptions, type GateSummary, MAX_REPORTED, MIN_TARGET_PX, type OverflowMetrics, type OverflowReading, PHONE_DEVICE, PHONE_SIZE, type PageFactory, RELAYOUT_TIMEOUT_MS, type Rect, type Region, type RegionInput, type RouteAudit, type RouteOverflow, type ShrinkOptions, type Size, type TargetAudit, type TargetFinding, type TargetProbeFunnel, armVisibleHeight, auditRoute, auditTouchTargets, canvasBoxToPage, controlName, countDiff, desktop, deviceDescriptor, diffPngs, domControls, expectCanvasHeight, expectCanvasInside, expectFitTo, expectNoHorizontalOverflow, expectNoHorizontalOverflowAcrossRoutes, expectTouchTargets, expectTouchTargetsAcrossRoutes, findOverlaps, findOverlapsWithin, gameProjects, horizontalOverflowPx, measureHorizontalOverflow, overlaps, phone, readHorizontalOverflow, regionDiff, renderFindings, renderOverflow, renderRouteAudit, routeProblems, shrinkVisibleHeight, summariseOverflow, summariseTouchTargets, toOverflowReading };
214
+ declare const WALK_INPUTS: {
215
+ readonly keys: "keys";
216
+ readonly pad: "pad";
217
+ };
218
+ type WalkInput = (typeof WALK_INPUTS)[keyof typeof WALK_INPUTS];
219
+ interface WalkResult {
220
+ screen: string;
221
+ via: WalkInput;
222
+ reached: number;
223
+ total: number;
224
+ unreached: string[];
225
+ problems: string[];
226
+ exempt: string[];
227
+ notes: string[];
228
+ }
229
+ declare const walkFailed: (r: WalkResult) => boolean;
230
+ /** One block per screen and input: reached/total, then every unreached control, problem and exemption. */
231
+ declare function renderWalk(results: readonly WalkResult[]): string;
232
+
233
+ interface WalkScreen {
234
+ name: string;
235
+ /** Opens the screen from a fresh page (clicks, a URL, a test hook). */
236
+ open: (page: Page) => Promise<void>;
237
+ /** Controls deliberately not walkable, each with a reason (printed in the report). */
238
+ exempt?: ReadonlyArray<{
239
+ selector: string;
240
+ reason: string;
241
+ }>;
242
+ }
243
+ interface WalkOptions {
244
+ via?: readonly WalkInput[];
245
+ }
246
+ /** Walks every screen by arrow keys and by a stubbed pad (default both) and returns one result per screen and input. */
247
+ declare function walkMenus(page: Page, screens: readonly WalkScreen[], options?: WalkOptions): Promise<WalkResult[]>;
248
+ /** NAV-1 gate: throws, listing every unreached control and problem, unless every screen walks by keys and pad. */
249
+ declare function expectMenuWalkable(page: Page, screens: readonly WalkScreen[], options?: WalkOptions): Promise<void>;
250
+
251
+ interface PadDriver {
252
+ press(button: number): Promise<void>;
253
+ hold(axis: number, value: number): Promise<void>;
254
+ }
255
+ declare const STUB_FRAMES = 3;
256
+ /** Replaces navigator.getGamepads with one standard pad (call before the page loads); returns its driver. */
257
+ declare function stubGamepad(page: Page): Promise<PadDriver>;
258
+
259
+ export { ANTI_ALIAS_TOLERANCE, type Band, type Box, CANVAS_TIMEOUT_MS, CONTROL_SELECTOR, type CanvasFrame, type CanvasOptions, type ControlIdentity, DEFAULT_CANVAS_SELECTOR, DESKTOP_DEVICE, DESKTOP_SIZE, type DiffOptions, type DiffResult, EXACT, FIT_TIMEOUT_MS, type FitOptions, GAME_SHELL_HEIGHT_VAR, type GameProject, type GameProjectsOptions, type GateSummary, MAX_REPORTED, MIN_TARGET_PX, type OverflowMetrics, type OverflowReading, PHONE_DEVICE, PHONE_SIZE, type PadDriver, type PageFactory, RELAYOUT_TIMEOUT_MS, type Rect, type Region, type RegionInput, type RouteAudit, type RouteOverflow, STUB_FRAMES, type ShrinkOptions, type Size, type TargetAudit, type TargetFinding, type TargetProbeFunnel, WALK_INPUTS, type WalkInput, type WalkOptions, type WalkResult, type WalkScreen, armVisibleHeight, auditRoute, auditTouchTargets, canvasBoxToPage, controlName, countDiff, desktop, deviceDescriptor, diffPngs, domControls, expectCanvasHeight, expectCanvasInside, expectFitTo, expectMenuWalkable, expectNoHorizontalOverflow, expectNoHorizontalOverflowAcrossRoutes, expectTouchTargets, expectTouchTargetsAcrossRoutes, findOverlaps, findOverlapsWithin, gameProjects, horizontalOverflowPx, measureHorizontalOverflow, overlaps, phone, readHorizontalOverflow, regionDiff, renderFindings, renderOverflow, renderRouteAudit, renderWalk, routeProblems, shrinkVisibleHeight, stubGamepad, summariseOverflow, summariseTouchTargets, toOverflowReading, walkFailed, walkMenus };
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var test = require('@playwright/test');
4
+ var gameInput = require('@dloizides/game-input');
4
5
 
5
6
  // src/boxes.ts
6
7
  var CONTROL_TEXT_CHARS = 12;
@@ -466,6 +467,244 @@ async function expectNoHorizontalOverflow(page, where) {
466
467
  return r.reading;
467
468
  }
468
469
 
470
+ // src/gamepad-stub.ts
471
+ var STUB_FRAMES = 3;
472
+ var STANDARD_BUTTON_COUNT = 17;
473
+ var AXIS_COUNT = 4;
474
+ async function stubGamepad(page) {
475
+ await page.addInitScript(([buttons, axes]) => {
476
+ const pad = { id: "nav-walk-stub", index: 0, connected: true, mapping: "standard", timestamp: 0, axes: new Array(axes).fill(0), buttons: Array.from({ length: buttons }, () => ({ pressed: false, touched: false, value: 0 })) };
477
+ Object.assign(window, { __navPad: pad });
478
+ Object.defineProperty(navigator, "getGamepads", { configurable: true, value: () => [pad, null, null, null] });
479
+ window.addEventListener("load", () => window.dispatchEvent(Object.assign(new Event("gamepadconnected"), { gamepad: pad })));
480
+ }, [STANDARD_BUTTON_COUNT, AXIS_COUNT]);
481
+ return {
482
+ press: (button) => page.evaluate(async ([b, n]) => {
483
+ const pad = window.__navPad;
484
+ const frames = (k) => new Promise((resolve) => {
485
+ const step = (left) => {
486
+ if (left === 0) {
487
+ resolve();
488
+ return;
489
+ }
490
+ requestAnimationFrame(() => step(left - 1));
491
+ };
492
+ step(k);
493
+ });
494
+ const target = pad.buttons[b] ?? { pressed: false, value: 0 };
495
+ target.pressed = true;
496
+ target.value = 1;
497
+ await frames(n);
498
+ target.pressed = false;
499
+ target.value = 0;
500
+ await frames(n);
501
+ }, [button, STUB_FRAMES]),
502
+ hold: (axis, value) => page.evaluate(([a, v]) => {
503
+ window.__navPad.axes[a] = v;
504
+ }, [axis, value])
505
+ };
506
+ }
507
+
508
+ // src/menu-walk-listeners.ts
509
+ var POINTER_EVENTS = ["click", "pointerdown", "pointerup"];
510
+ var NO_CDP_NOTE = "CDP unavailable (not Chromium): click/pointer listeners added with addEventListener were not checked; only [onclick] and handler properties were";
511
+ function markProbes(a) {
512
+ const shown = (el) => el.getClientRects().length > 0 && el.closest('[hidden], [inert], [aria-hidden="true"]') === null && getComputedStyle(el).visibility !== "hidden";
513
+ const root = document.querySelector(`[${a.rootAttr}]`) ?? document.body;
514
+ const probes = Array.from(root.querySelectorAll("*")).filter((el) => !el.hasAttribute(a.attr) && el.closest(`[${a.attr}]`) === null && el.querySelector(`[${a.attr}]`) === null && shown(el) && !a.exempt.some((s) => el.matches(s)));
515
+ probes.forEach((el, i) => el.setAttribute(a.probeAttr, String(i)));
516
+ const props = ["onclick", "onpointerdown", "onpointerup"];
517
+ return { probes: probes.length, withProperty: probes.flatMap((el, i) => props.some((p) => typeof el[p] === "function") ? [i] : []) };
518
+ }
519
+ function flagProbes([attr, probeAttr, ids, start]) {
520
+ const els = ids.flatMap((i) => Array.from(document.querySelectorAll(`[${probeAttr}="${i}"]`)));
521
+ const innermost = els.filter((el) => !els.some((o) => o !== el && el.contains(o)));
522
+ document.querySelectorAll(`[${probeAttr}]`).forEach((el) => el.removeAttribute(probeAttr));
523
+ innermost.forEach((el, k) => el.setAttribute(attr, String(start + k)));
524
+ return innermost.map((el) => ({ tag: el.tagName, id: el.id, className: el.getAttribute("class") ?? "", text: el.textContent ?? "" }));
525
+ }
526
+ async function openCdp(page) {
527
+ try {
528
+ return await page.context().newCDPSession(page);
529
+ } catch {
530
+ return null;
531
+ }
532
+ }
533
+ async function listenerProbes(cdp, probeAttr, count) {
534
+ const hits = [];
535
+ for (let i = 0; i < count; i += 1) {
536
+ const { result } = await cdp.send("Runtime.evaluate", { expression: `document.querySelector('[${probeAttr}="${i}"]')` });
537
+ if (result.objectId === void 0) {
538
+ continue;
539
+ }
540
+ const { listeners } = await cdp.send("DOMDebugger.getEventListeners", { objectId: result.objectId });
541
+ if (listeners.some((l) => POINTER_EVENTS.includes(l.type))) {
542
+ hits.push(i);
543
+ }
544
+ await cdp.send("Runtime.releaseObject", { objectId: result.objectId });
545
+ }
546
+ return hits;
547
+ }
548
+ async function pointerOnlyControls(page, cdp, args, start) {
549
+ const marks = await page.evaluate(markProbes, args);
550
+ const viaListener = cdp === null ? [] : await listenerProbes(cdp, args.probeAttr, marks.probes);
551
+ const ids = [.../* @__PURE__ */ new Set([...marks.withProperty, ...viaListener])];
552
+ const identities = await page.evaluate(flagProbes, [args.attr, args.probeAttr, ids, start]);
553
+ return { identities, notes: cdp === null ? [NO_CDP_NOTE] : [] };
554
+ }
555
+
556
+ // src/menu-walk-page.ts
557
+ function scanScreen(a) {
558
+ const shown = (el) => el.getClientRects().length > 0 && el.closest('[hidden], [inert], [aria-hidden="true"]') === null && getComputedStyle(el).visibility !== "hidden";
559
+ const dialogs = Array.from(document.querySelectorAll(a.dialogSel)).filter(shown);
560
+ const modal = dialogs.filter((d) => d.getAttribute("aria-modal") === "true");
561
+ const root = (modal.length > 0 ? modal : dialogs).pop() ?? document.body;
562
+ document.querySelectorAll(`[${a.attr}], [${a.rootAttr}]`).forEach((el) => {
563
+ el.removeAttribute(a.attr);
564
+ el.removeAttribute(a.rootAttr);
565
+ });
566
+ root.setAttribute(a.rootAttr, "");
567
+ const list = Array.from(root.querySelectorAll(`${a.focusSel}, [onclick]`)).filter((el) => shown(el) && el.disabled !== true && !a.exempt.some((s) => el.matches(s)));
568
+ list.forEach((el, i) => el.setAttribute(a.attr, String(i)));
569
+ const nonText = ["range", "checkbox", "radio", "button", "submit", "reset", "color", "file", "image"];
570
+ const isText = (el) => el.tagName === "TEXTAREA" || el instanceof HTMLInputElement && !nonText.includes(el.type);
571
+ const isSlider = (el) => el instanceof HTMLInputElement && el.type === "range" || el.getAttribute("role") === "slider";
572
+ const active2 = document.activeElement;
573
+ return {
574
+ identities: list.map((el) => ({ tag: el.tagName, id: el.id, className: el.getAttribute("class") ?? "", text: el.textContent ?? "" })),
575
+ isDialog: root !== document.body,
576
+ focusedInRoot: active2 instanceof HTMLElement && active2 !== root && root.contains(active2),
577
+ sliders: list.flatMap((el, i) => isSlider(el) ? [i] : []),
578
+ textFields: list.flatMap((el, i) => isText(el) ? [i] : [])
579
+ };
580
+ }
581
+ function activeWalkId(attr) {
582
+ const v = document.activeElement?.getAttribute(attr) ?? null;
583
+ return v === null ? null : Number(v);
584
+ }
585
+ function focusWalkId([attr, id]) {
586
+ document.querySelector(`[${attr}="${id}"]`)?.focus();
587
+ }
588
+ function controlValue([attr, id]) {
589
+ const el = document.querySelector(`[${attr}="${id}"]`);
590
+ return el instanceof HTMLInputElement ? el.value : el?.getAttribute("aria-valuenow") ?? "";
591
+ }
592
+ function rootOpen(rootAttr) {
593
+ const r = document.querySelector(`[${rootAttr}]`);
594
+ return r !== null && r.getClientRects().length > 0 && r.closest("[hidden]") === null;
595
+ }
596
+
597
+ // src/menu-walk-report.ts
598
+ var WALK_INPUTS = { keys: "keys", pad: "pad" };
599
+ var walkFailed = (r) => r.unreached.length > 0 || r.problems.length > 0;
600
+ function renderWalk(results) {
601
+ return results.map((r) => [
602
+ `${r.screen} [${r.via}] reached ${r.reached}/${r.total}`,
603
+ ...r.unreached.map((n) => ` unreached: ${n}`),
604
+ ...r.problems.map((p) => ` problem: ${p}`),
605
+ ...r.exempt.map((e) => ` exempt: ${e}`),
606
+ ...r.notes.map((n) => ` note: ${n}`)
607
+ ].join("\n")).join("\n");
608
+ }
609
+
610
+ // src/menu-walk.ts
611
+ var WALK_ATTR = "data-walk-id";
612
+ var ROOT_ATTR = "data-walk-root";
613
+ var PROBE_ATTR = "data-walk-probe";
614
+ var PRESSES_PER_CONTROL = 4;
615
+ var DIRS = ["up", "down", "left", "right"];
616
+ var KEYS = { up: "ArrowUp", down: "ArrowDown", left: "ArrowLeft", right: "ArrowRight" };
617
+ var PAD_BUTTONS = { up: gameInput.STANDARD_BUTTON.dpadUp, down: gameInput.STANDARD_BUTTON.dpadDown, left: gameInput.STANDARD_BUTTON.dpadLeft, right: gameInput.STANDARD_BUTTON.dpadRight };
618
+ function driverFor(page, via, pad) {
619
+ if (via === WALK_INPUTS.pad && pad !== null) {
620
+ return { dir: (d) => pad.press(PAD_BUTTONS[d]), back: () => pad.press(gameInput.STANDARD_BUTTON.east) };
621
+ }
622
+ return { dir: (d) => page.keyboard.press(KEYS[d]), back: () => page.keyboard.press("Escape") };
623
+ }
624
+ var active = (page) => page.evaluate(activeWalkId, WALK_ATTR);
625
+ var focusId = (page, id) => page.evaluate(focusWalkId, [WALK_ATTR, id]);
626
+ async function bfs(page, driver, total) {
627
+ const reached = /* @__PURE__ */ new Set();
628
+ let start = await active(page);
629
+ if (start === null) {
630
+ await driver.dir("down");
631
+ start = await active(page);
632
+ }
633
+ if (start === null) {
634
+ return reached;
635
+ }
636
+ reached.add(start);
637
+ const queue = [start];
638
+ let presses = 0;
639
+ while (queue.length > 0 && presses < PRESSES_PER_CONTROL * total) {
640
+ const from = queue.shift();
641
+ for (const d of DIRS) {
642
+ await focusId(page, from);
643
+ await driver.dir(d);
644
+ presses += 1;
645
+ const at2 = await active(page);
646
+ if (at2 !== null && !reached.has(at2)) {
647
+ reached.add(at2);
648
+ queue.push(at2);
649
+ }
650
+ }
651
+ }
652
+ return reached;
653
+ }
654
+ async function sliderProblems(page, driver, scan, reached, names) {
655
+ const problems = [];
656
+ for (const i of scan.sliders.filter((s) => reached.has(s))) {
657
+ await focusId(page, i);
658
+ const before = await page.evaluate(controlValue, [WALK_ATTR, i]);
659
+ await driver.dir("right");
660
+ const right = await page.evaluate(controlValue, [WALK_ATTR, i]);
661
+ await driver.dir("left");
662
+ const left = await page.evaluate(controlValue, [WALK_ATTR, i]);
663
+ if (right === before && left === before) {
664
+ problems.push(`slider ${names[i]} does not move on Left/Right`);
665
+ }
666
+ }
667
+ return problems;
668
+ }
669
+ async function walkScreen(page, screen, via, env) {
670
+ const driver = driverFor(page, via, env.pad);
671
+ const exempt = screen.exempt ?? [];
672
+ await screen.open(page);
673
+ const scan = await page.evaluate(scanScreen, { focusSel: gameInput.MENU_FOCUSABLE_SELECTOR, dialogSel: gameInput.DIALOG_SELECTOR, exempt: exempt.map((e) => e.selector), attr: WALK_ATTR, rootAttr: ROOT_ATTR });
674
+ const pointerOnly = await pointerOnlyControls(page, env.cdp, { attr: WALK_ATTR, rootAttr: ROOT_ATTR, probeAttr: PROBE_ATTR, exempt: exempt.map((e) => e.selector) }, scan.identities.length);
675
+ const names = [...scan.identities, ...pointerOnly.identities].map(controlName);
676
+ const reached = await bfs(page, driver, names.length);
677
+ const problems = scan.isDialog && !scan.focusedInRoot ? ["focus is not inside the dialog when it opens"] : [];
678
+ problems.push(...await sliderProblems(page, driver, scan, reached, names));
679
+ const closer = [...reached].find((i) => !scan.textFields.includes(i) && !scan.sliders.includes(i));
680
+ if (scan.isDialog && closer !== void 0) {
681
+ await focusId(page, closer);
682
+ await driver.back();
683
+ if (await page.evaluate(rootOpen, ROOT_ATTR)) {
684
+ problems.push(`${via === WALK_INPUTS.pad ? "B" : "Escape"} does not close the dialog`);
685
+ }
686
+ }
687
+ return { screen: screen.name, via, reached: reached.size, total: names.length, unreached: names.filter((_, i) => !reached.has(i)), problems, exempt: exempt.map((e) => `${e.selector}: ${e.reason}`), notes: pointerOnly.notes };
688
+ }
689
+ async function walkMenus(page, screens, options = {}) {
690
+ const via = options.via ?? [WALK_INPUTS.keys, WALK_INPUTS.pad];
691
+ const env = { pad: via.includes(WALK_INPUTS.pad) ? await stubGamepad(page) : null, cdp: await openCdp(page) };
692
+ const results = [];
693
+ for (const screen of screens) {
694
+ for (const v of via) {
695
+ results.push(await walkScreen(page, screen, v, env));
696
+ }
697
+ }
698
+ return results;
699
+ }
700
+ async function expectMenuWalkable(page, screens, options = {}) {
701
+ const results = await walkMenus(page, screens, options);
702
+ if (results.some(walkFailed)) {
703
+ throw new Error(`Menus not walkable by arrow keys / pad:
704
+ ${renderWalk(results)}`);
705
+ }
706
+ }
707
+
469
708
  exports.ANTI_ALIAS_TOLERANCE = ANTI_ALIAS_TOLERANCE;
470
709
  exports.CANVAS_TIMEOUT_MS = CANVAS_TIMEOUT_MS;
471
710
  exports.CONTROL_SELECTOR = CONTROL_SELECTOR;
@@ -480,6 +719,8 @@ exports.MIN_TARGET_PX = MIN_TARGET_PX;
480
719
  exports.PHONE_DEVICE = PHONE_DEVICE;
481
720
  exports.PHONE_SIZE = PHONE_SIZE;
482
721
  exports.RELAYOUT_TIMEOUT_MS = RELAYOUT_TIMEOUT_MS;
722
+ exports.STUB_FRAMES = STUB_FRAMES;
723
+ exports.WALK_INPUTS = WALK_INPUTS;
483
724
  exports.armVisibleHeight = armVisibleHeight;
484
725
  exports.auditRoute = auditRoute;
485
726
  exports.auditTouchTargets = auditTouchTargets;
@@ -493,6 +734,7 @@ exports.domControls = domControls;
493
734
  exports.expectCanvasHeight = expectCanvasHeight;
494
735
  exports.expectCanvasInside = expectCanvasInside;
495
736
  exports.expectFitTo = expectFitTo;
737
+ exports.expectMenuWalkable = expectMenuWalkable;
496
738
  exports.expectNoHorizontalOverflow = expectNoHorizontalOverflow;
497
739
  exports.expectNoHorizontalOverflowAcrossRoutes = expectNoHorizontalOverflowAcrossRoutes;
498
740
  exports.expectTouchTargets = expectTouchTargets;
@@ -509,10 +751,14 @@ exports.regionDiff = regionDiff;
509
751
  exports.renderFindings = renderFindings;
510
752
  exports.renderOverflow = renderOverflow;
511
753
  exports.renderRouteAudit = renderRouteAudit;
754
+ exports.renderWalk = renderWalk;
512
755
  exports.routeProblems = routeProblems;
513
756
  exports.shrinkVisibleHeight = shrinkVisibleHeight;
757
+ exports.stubGamepad = stubGamepad;
514
758
  exports.summariseOverflow = summariseOverflow;
515
759
  exports.summariseTouchTargets = summariseTouchTargets;
516
760
  exports.toOverflowReading = toOverflowReading;
761
+ exports.walkFailed = walkFailed;
762
+ exports.walkMenus = walkMenus;
517
763
  //# sourceMappingURL=index.js.map
518
764
  //# sourceMappingURL=index.js.map