@dloizides/game-e2e 1.0.0 → 1.1.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
@@ -1,21 +1,33 @@
1
- # Changelog
2
-
3
- All notable changes to `@dloizides/game-e2e` are documented here.
4
-
5
- ## 1.0.0
6
-
7
- First release. Playwright helpers that Aurora, Surge and Morphe each carried a copy of, unified on the
8
- strictest behaviour of the three:
9
-
10
- - `phone()` / `desktop()` / `gameProjects()`: Galaxy S5 and Desktop Chrome device descriptors (touch,
11
- mobile UA, isMobile on the phone), resized; never a bare viewport.
12
- - `armVisibleHeight()` / `shrinkVisibleHeight()`: a simulated browser toolbar. `relayoutGlobal` waits for
13
- every active Phaser scene to re-create and throws when the global is missing.
14
- - `expectFitTo()`, `expectCanvasHeight()`, `expectCanvasInside()`: game-shell fit assertions with a
15
- configurable canvas selector.
16
- - `domControls()`, `overlaps()`, `findOverlaps()`, `findOverlapsWithin()`, `canvasBoxToPage()`.
17
- - `diffPngs()` / `regionDiff()` / `countDiff()`: exact by default (tolerance 0, sizes must match);
18
- `ANTI_ALIAS_TOLERANCE` (48) and `width`/`height` opt into Surge's tolerant, scaled comparison.
19
- - `auditTouchTargets()` + `expectTouchTargets(AcrossRoutes)()`: the 44x44 hit-box gate.
20
- - `readHorizontalOverflow()` + `expectNoHorizontalOverflow(AcrossRoutes)()`: the no-horizontal-scroll
21
- gate, measured against the narrower of visualViewport width and clientWidth.
1
+ # Changelog
2
+
3
+ All notable changes to `@dloizides/game-e2e` are documented here.
4
+
5
+ ## 1.1.0
6
+
7
+ NAV-1 "Every game menu works with arrow keys and controller", phase 1:
8
+
9
+ - `walkMenus()` / `expectMenuWalkable()`: open each screen, walk every focusable control by arrow keys and
10
+ by a stubbed gamepad (breadth-first from the focused control), report unreached controls, a dialog that
11
+ opens without focus inside it, sliders that ignore Left/Right, and Escape / B that does not close a dialog.
12
+ Exemptions take a selector and a printed reason.
13
+ - `stubGamepad()`: a `navigator.getGamepads()` stand-in driven from the test (`PadDriver.press`).
14
+ - `renderWalk()`, `walkFailed()`, `WALK_INPUTS`.
15
+ - Depends on `@dloizides/game-input` ^1.5.1 for the shared focusable and dialog selectors.
16
+
17
+ ## 1.0.0
18
+
19
+ First release. Playwright helpers that Aurora, Surge and Morphe each carried a copy of, unified on the
20
+ strictest behaviour of the three:
21
+
22
+ - `phone()` / `desktop()` / `gameProjects()`: Galaxy S5 and Desktop Chrome device descriptors (touch,
23
+ mobile UA, isMobile on the phone), resized; never a bare viewport.
24
+ - `armVisibleHeight()` / `shrinkVisibleHeight()`: a simulated browser toolbar. `relayoutGlobal` waits for
25
+ every active Phaser scene to re-create and throws when the global is missing.
26
+ - `expectFitTo()`, `expectCanvasHeight()`, `expectCanvasInside()`: game-shell fit assertions with a
27
+ configurable canvas selector.
28
+ - `domControls()`, `overlaps()`, `findOverlaps()`, `findOverlapsWithin()`, `canvasBoxToPage()`.
29
+ - `diffPngs()` / `regionDiff()` / `countDiff()`: exact by default (tolerance 0, sizes must match);
30
+ `ANTI_ALIAS_TOLERANCE` (48) and `width`/`height` opt into Surge's tolerant, scaled comparison.
31
+ - `auditTouchTargets()` + `expectTouchTargets(AcrossRoutes)()`: the 44x44 hit-box gate.
32
+ - `readHorizontalOverflow()` + `expectNoHorizontalOverflow(AcrossRoutes)()`: the no-horizontal-scroll
33
+ gate, measured against the narrower of visualViewport width and clientWidth.
package/dist/index.d.mts CHANGED
@@ -211,4 +211,48 @@ 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
+ }
228
+ declare const walkFailed: (r: WalkResult) => boolean;
229
+ /** One block per screen and input: reached/total, then every unreached control, problem and exemption. */
230
+ declare function renderWalk(results: readonly WalkResult[]): string;
231
+
232
+ interface WalkScreen {
233
+ name: string;
234
+ /** Opens the screen from a fresh page (clicks, a URL, a test hook). */
235
+ open: (page: Page) => Promise<void>;
236
+ /** Controls deliberately not walkable, each with a reason (printed in the report). */
237
+ exempt?: ReadonlyArray<{
238
+ selector: string;
239
+ reason: string;
240
+ }>;
241
+ }
242
+ interface WalkOptions {
243
+ via?: readonly WalkInput[];
244
+ }
245
+ /** Walks every screen by arrow keys and by a stubbed pad (default both) and returns one result per screen and input. */
246
+ declare function walkMenus(page: Page, screens: readonly WalkScreen[], options?: WalkOptions): Promise<WalkResult[]>;
247
+ /** NAV-1 gate: throws, listing every unreached control and problem, unless every screen walks by keys and pad. */
248
+ declare function expectMenuWalkable(page: Page, screens: readonly WalkScreen[], options?: WalkOptions): Promise<void>;
249
+
250
+ interface PadDriver {
251
+ press(button: number): Promise<void>;
252
+ hold(axis: number, value: number): Promise<void>;
253
+ }
254
+ declare const STUB_FRAMES = 3;
255
+ /** Replaces navigator.getGamepads with one standard pad (call before the page loads); returns its driver. */
256
+ declare function stubGamepad(page: Page): Promise<PadDriver>;
257
+
258
+ 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,48 @@ 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
+ }
228
+ declare const walkFailed: (r: WalkResult) => boolean;
229
+ /** One block per screen and input: reached/total, then every unreached control, problem and exemption. */
230
+ declare function renderWalk(results: readonly WalkResult[]): string;
231
+
232
+ interface WalkScreen {
233
+ name: string;
234
+ /** Opens the screen from a fresh page (clicks, a URL, a test hook). */
235
+ open: (page: Page) => Promise<void>;
236
+ /** Controls deliberately not walkable, each with a reason (printed in the report). */
237
+ exempt?: ReadonlyArray<{
238
+ selector: string;
239
+ reason: string;
240
+ }>;
241
+ }
242
+ interface WalkOptions {
243
+ via?: readonly WalkInput[];
244
+ }
245
+ /** Walks every screen by arrow keys and by a stubbed pad (default both) and returns one result per screen and input. */
246
+ declare function walkMenus(page: Page, screens: readonly WalkScreen[], options?: WalkOptions): Promise<WalkResult[]>;
247
+ /** NAV-1 gate: throws, listing every unreached control and problem, unless every screen walks by keys and pad. */
248
+ declare function expectMenuWalkable(page: Page, screens: readonly WalkScreen[], options?: WalkOptions): Promise<void>;
249
+
250
+ interface PadDriver {
251
+ press(button: number): Promise<void>;
252
+ hold(axis: number, value: number): Promise<void>;
253
+ }
254
+ declare const STUB_FRAMES = 3;
255
+ /** Replaces navigator.getGamepads with one standard pad (call before the page loads); returns its driver. */
256
+ declare function stubGamepad(page: Page): Promise<PadDriver>;
257
+
258
+ 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,193 @@ 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-page.ts
509
+ function scanScreen(a) {
510
+ const shown = (el) => el.getClientRects().length > 0 && el.closest('[hidden], [inert], [aria-hidden="true"]') === null && getComputedStyle(el).visibility !== "hidden";
511
+ const dialogs = Array.from(document.querySelectorAll(a.dialogSel)).filter(shown);
512
+ const modal = dialogs.filter((d) => d.getAttribute("aria-modal") === "true");
513
+ const root = (modal.length > 0 ? modal : dialogs).pop() ?? document.body;
514
+ document.querySelectorAll(`[${a.attr}], [${a.rootAttr}]`).forEach((el) => {
515
+ el.removeAttribute(a.attr);
516
+ el.removeAttribute(a.rootAttr);
517
+ });
518
+ root.setAttribute(a.rootAttr, "");
519
+ const list = Array.from(root.querySelectorAll(`${a.focusSel}, [onclick]`)).filter((el) => shown(el) && el.disabled !== true && !a.exempt.some((s) => el.matches(s)));
520
+ list.forEach((el, i) => el.setAttribute(a.attr, String(i)));
521
+ const nonText = ["range", "checkbox", "radio", "button", "submit", "reset", "color", "file", "image"];
522
+ const isText = (el) => el.tagName === "TEXTAREA" || el instanceof HTMLInputElement && !nonText.includes(el.type);
523
+ const isSlider = (el) => el instanceof HTMLInputElement && el.type === "range" || el.getAttribute("role") === "slider";
524
+ const active2 = document.activeElement;
525
+ return {
526
+ identities: list.map((el) => ({ tag: el.tagName, id: el.id, className: el.getAttribute("class") ?? "", text: el.textContent ?? "" })),
527
+ isDialog: root !== document.body,
528
+ focusedInRoot: active2 instanceof HTMLElement && active2 !== root && root.contains(active2),
529
+ sliders: list.flatMap((el, i) => isSlider(el) ? [i] : []),
530
+ textFields: list.flatMap((el, i) => isText(el) ? [i] : [])
531
+ };
532
+ }
533
+ function activeWalkId(attr) {
534
+ const v = document.activeElement?.getAttribute(attr) ?? null;
535
+ return v === null ? null : Number(v);
536
+ }
537
+ function focusWalkId([attr, id]) {
538
+ document.querySelector(`[${attr}="${id}"]`)?.focus();
539
+ }
540
+ function controlValue([attr, id]) {
541
+ const el = document.querySelector(`[${attr}="${id}"]`);
542
+ return el instanceof HTMLInputElement ? el.value : el?.getAttribute("aria-valuenow") ?? "";
543
+ }
544
+ function rootOpen(rootAttr) {
545
+ const r = document.querySelector(`[${rootAttr}]`);
546
+ return r !== null && r.getClientRects().length > 0 && r.closest("[hidden]") === null;
547
+ }
548
+
549
+ // src/menu-walk-report.ts
550
+ var WALK_INPUTS = { keys: "keys", pad: "pad" };
551
+ var walkFailed = (r) => r.unreached.length > 0 || r.problems.length > 0;
552
+ function renderWalk(results) {
553
+ return results.map((r) => [
554
+ `${r.screen} [${r.via}] reached ${r.reached}/${r.total}`,
555
+ ...r.unreached.map((n) => ` unreached: ${n}`),
556
+ ...r.problems.map((p) => ` problem: ${p}`),
557
+ ...r.exempt.map((e) => ` exempt: ${e}`)
558
+ ].join("\n")).join("\n");
559
+ }
560
+
561
+ // src/menu-walk.ts
562
+ var WALK_ATTR = "data-walk-id";
563
+ var ROOT_ATTR = "data-walk-root";
564
+ var PRESSES_PER_CONTROL = 4;
565
+ var DIRS = ["up", "down", "left", "right"];
566
+ var KEYS = { up: "ArrowUp", down: "ArrowDown", left: "ArrowLeft", right: "ArrowRight" };
567
+ var PAD_BUTTONS = { up: gameInput.STANDARD_BUTTON.dpadUp, down: gameInput.STANDARD_BUTTON.dpadDown, left: gameInput.STANDARD_BUTTON.dpadLeft, right: gameInput.STANDARD_BUTTON.dpadRight };
568
+ function driverFor(page, via, pad) {
569
+ if (via === WALK_INPUTS.pad && pad !== null) {
570
+ return { dir: (d) => pad.press(PAD_BUTTONS[d]), back: () => pad.press(gameInput.STANDARD_BUTTON.east) };
571
+ }
572
+ return { dir: (d) => page.keyboard.press(KEYS[d]), back: () => page.keyboard.press("Escape") };
573
+ }
574
+ var active = (page) => page.evaluate(activeWalkId, WALK_ATTR);
575
+ var focusId = (page, id) => page.evaluate(focusWalkId, [WALK_ATTR, id]);
576
+ async function bfs(page, driver, total) {
577
+ const reached = /* @__PURE__ */ new Set();
578
+ let start = await active(page);
579
+ if (start === null) {
580
+ await driver.dir("down");
581
+ start = await active(page);
582
+ }
583
+ if (start === null) {
584
+ return reached;
585
+ }
586
+ reached.add(start);
587
+ const queue = [start];
588
+ let presses = 0;
589
+ while (queue.length > 0 && presses < PRESSES_PER_CONTROL * total) {
590
+ const from = queue.shift();
591
+ for (const d of DIRS) {
592
+ await focusId(page, from);
593
+ await driver.dir(d);
594
+ presses += 1;
595
+ const at2 = await active(page);
596
+ if (at2 !== null && !reached.has(at2)) {
597
+ reached.add(at2);
598
+ queue.push(at2);
599
+ }
600
+ }
601
+ }
602
+ return reached;
603
+ }
604
+ async function sliderProblems(page, driver, scan, reached, names) {
605
+ const problems = [];
606
+ for (const i of scan.sliders.filter((s) => reached.has(s))) {
607
+ await focusId(page, i);
608
+ const before = await page.evaluate(controlValue, [WALK_ATTR, i]);
609
+ await driver.dir("right");
610
+ const right = await page.evaluate(controlValue, [WALK_ATTR, i]);
611
+ await driver.dir("left");
612
+ const left = await page.evaluate(controlValue, [WALK_ATTR, i]);
613
+ if (right === before && left === before) {
614
+ problems.push(`slider ${names[i]} does not move on Left/Right`);
615
+ }
616
+ }
617
+ return problems;
618
+ }
619
+ async function walkScreen(page, screen, via, pad) {
620
+ const driver = driverFor(page, via, pad);
621
+ const exempt = screen.exempt ?? [];
622
+ await screen.open(page);
623
+ 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 });
624
+ const names = scan.identities.map(controlName);
625
+ const reached = await bfs(page, driver, names.length);
626
+ const problems = scan.isDialog && !scan.focusedInRoot ? ["focus is not inside the dialog when it opens"] : [];
627
+ problems.push(...await sliderProblems(page, driver, scan, reached, names));
628
+ const closer = [...reached].find((i) => !scan.textFields.includes(i) && !scan.sliders.includes(i));
629
+ if (scan.isDialog && closer !== void 0) {
630
+ await focusId(page, closer);
631
+ await driver.back();
632
+ if (await page.evaluate(rootOpen, ROOT_ATTR)) {
633
+ problems.push(`${via === WALK_INPUTS.pad ? "B" : "Escape"} does not close the dialog`);
634
+ }
635
+ }
636
+ 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}`) };
637
+ }
638
+ async function walkMenus(page, screens, options = {}) {
639
+ const via = options.via ?? [WALK_INPUTS.keys, WALK_INPUTS.pad];
640
+ const pad = via.includes(WALK_INPUTS.pad) ? await stubGamepad(page) : null;
641
+ const results = [];
642
+ for (const screen of screens) {
643
+ for (const v of via) {
644
+ results.push(await walkScreen(page, screen, v, pad));
645
+ }
646
+ }
647
+ return results;
648
+ }
649
+ async function expectMenuWalkable(page, screens, options = {}) {
650
+ const results = await walkMenus(page, screens, options);
651
+ if (results.some(walkFailed)) {
652
+ throw new Error(`Menus not walkable by arrow keys / pad:
653
+ ${renderWalk(results)}`);
654
+ }
655
+ }
656
+
469
657
  exports.ANTI_ALIAS_TOLERANCE = ANTI_ALIAS_TOLERANCE;
470
658
  exports.CANVAS_TIMEOUT_MS = CANVAS_TIMEOUT_MS;
471
659
  exports.CONTROL_SELECTOR = CONTROL_SELECTOR;
@@ -480,6 +668,8 @@ exports.MIN_TARGET_PX = MIN_TARGET_PX;
480
668
  exports.PHONE_DEVICE = PHONE_DEVICE;
481
669
  exports.PHONE_SIZE = PHONE_SIZE;
482
670
  exports.RELAYOUT_TIMEOUT_MS = RELAYOUT_TIMEOUT_MS;
671
+ exports.STUB_FRAMES = STUB_FRAMES;
672
+ exports.WALK_INPUTS = WALK_INPUTS;
483
673
  exports.armVisibleHeight = armVisibleHeight;
484
674
  exports.auditRoute = auditRoute;
485
675
  exports.auditTouchTargets = auditTouchTargets;
@@ -493,6 +683,7 @@ exports.domControls = domControls;
493
683
  exports.expectCanvasHeight = expectCanvasHeight;
494
684
  exports.expectCanvasInside = expectCanvasInside;
495
685
  exports.expectFitTo = expectFitTo;
686
+ exports.expectMenuWalkable = expectMenuWalkable;
496
687
  exports.expectNoHorizontalOverflow = expectNoHorizontalOverflow;
497
688
  exports.expectNoHorizontalOverflowAcrossRoutes = expectNoHorizontalOverflowAcrossRoutes;
498
689
  exports.expectTouchTargets = expectTouchTargets;
@@ -509,10 +700,14 @@ exports.regionDiff = regionDiff;
509
700
  exports.renderFindings = renderFindings;
510
701
  exports.renderOverflow = renderOverflow;
511
702
  exports.renderRouteAudit = renderRouteAudit;
703
+ exports.renderWalk = renderWalk;
512
704
  exports.routeProblems = routeProblems;
513
705
  exports.shrinkVisibleHeight = shrinkVisibleHeight;
706
+ exports.stubGamepad = stubGamepad;
514
707
  exports.summariseOverflow = summariseOverflow;
515
708
  exports.summariseTouchTargets = summariseTouchTargets;
516
709
  exports.toOverflowReading = toOverflowReading;
710
+ exports.walkFailed = walkFailed;
711
+ exports.walkMenus = walkMenus;
517
712
  //# sourceMappingURL=index.js.map
518
713
  //# sourceMappingURL=index.js.map