@dloizides/game-e2e 1.5.0 → 1.6.1

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/dist/index.mjs CHANGED
@@ -1013,6 +1013,89 @@ async function expectTextFits(page, selector = TEXT_FIT_SELECTOR, options = {})
1013
1013
  return measured;
1014
1014
  }
1015
1015
 
1016
- export { ANTI_ALIAS_TOLERANCE, CANVAS_TIMEOUT_MS, CONTROL_SELECTOR, DEFAULT_CANVAS_SELECTOR, DESKTOP_DEVICE, DESKTOP_SIZE, EXACT, FIT_TIMEOUT_MS, GAME_SHELL_HEIGHT_VAR, HOOK_WALK_SIZES, MAX_REPORTED, MIN_TARGET_PX, PHONE_DEVICE, PHONE_SIZE, RELAYOUT_TIMEOUT_MS, STUB_FRAMES, TEXT_FIT_SELECTOR, TEXT_FIT_TOLERANCE_PX, WALK_INPUTS, armVisibleHeight, auditRoute, auditTouchTargets, canvasBoxToPage, controlName, countDiff, desktop, deviceDescriptor, diffPngs, domControls, expectCanvasHeight, expectCanvasInside, expectFitTo, expectHookMenuWalkable, expectMenuWalkable, expectNoHorizontalOverflow, expectNoHorizontalOverflowAcrossRoutes, expectTextFits, expectTouchTargets, expectTouchTargetsAcrossRoutes, findOverlaps, findOverlapsWithin, gameProjects, horizontalOverflowPx, measureHorizontalOverflow, measureTextFit, overlaps, phone, readHorizontalOverflow, readTextBoxes, regionDiff, renderFindings, renderOverflow, renderRouteAudit, renderWalk, routeProblems, shrinkVisibleHeight, stubGamepad, summariseOverflow, summariseTextFit, summariseTouchTargets, textFitFindings, toOverflowReading, walkFailed, walkHookMenus, walkMenus };
1016
+ // src/action-binding-report.ts
1017
+ function bindingFindings(r, action) {
1018
+ const found = [];
1019
+ if (r.key === null) {
1020
+ found.push({ name: r.name, why: `action ${action} has no key binding` });
1021
+ }
1022
+ if (r.pad === null) {
1023
+ found.push({ name: r.name, why: `action ${action} has no pad binding` });
1024
+ }
1025
+ return found;
1026
+ }
1027
+ function promptFinding(r) {
1028
+ if (r.expectedPromptText === null || r.promptText === r.expectedPromptText) {
1029
+ return null;
1030
+ }
1031
+ if (r.promptText === null) {
1032
+ return { name: r.name, why: `prompt missing: the current binding is "${r.expectedPromptText}" but no visible data-gi-prompt shows it` };
1033
+ }
1034
+ return { name: r.name, why: `prompt shows "${String(r.promptText)}" but the current binding is "${String(r.expectedPromptText)}"` };
1035
+ }
1036
+ function actionBindingFindings(r) {
1037
+ if (r.action === null) {
1038
+ return r.hasPointerHandler ? [{ name: r.name, why: "pointer handler but no data-gi-action" }] : [];
1039
+ }
1040
+ const prompt = promptFinding(r);
1041
+ const bindings = bindingFindings(r, r.action);
1042
+ return prompt === null ? bindings : [...bindings, prompt];
1043
+ }
1044
+ var renderFinding2 = (f) => `
1045
+ ${f.name}: ${f.why}`;
1046
+ function summariseActionBinding(readings, where) {
1047
+ if (readings.length === 0) {
1048
+ return { problems: 1, message: `${where}: BLIND - no clickable or data-gi-action element was read` };
1049
+ }
1050
+ const found = readings.flatMap(actionBindingFindings);
1051
+ const head = `${where}: ${String(readings.length)} element(s), ${String(found.length)} problem(s)`;
1052
+ return { problems: found.length, message: `${head}${found.map(renderFinding2).join("")}` };
1053
+ }
1054
+ var ACTION_ATTR = "data-gi-action";
1055
+ var PROMPT_ATTR = "data-gi-prompt";
1056
+ var POINTER_SELECTOR = 'button, a[href], [role="button"], [onclick]';
1057
+ var ACTION_ROOT_SELECTOR = "body";
1058
+ function toActionReading(el, bindings) {
1059
+ const b = el.action === null ? void 0 : bindings[el.action];
1060
+ return { ...el, key: b?.key ?? null, pad: b?.pad ?? null, expectedPromptText: b?.prompt ?? null };
1061
+ }
1062
+ async function readActionElements(page, root = ACTION_ROOT_SELECTOR, pointerSelector = POINTER_SELECTOR) {
1063
+ return page.evaluate(({ rootSel, pointerSel, actionAttr, promptAttr }) => {
1064
+ const shown = (el) => {
1065
+ const r = el.getBoundingClientRect();
1066
+ return r.width > 0 && r.height > 0 && getComputedStyle(el).visibility !== "hidden" && el.closest('[aria-hidden="true"]') === null;
1067
+ };
1068
+ const label = (el) => {
1069
+ const id = el.id !== "" ? `#${el.id}` : "";
1070
+ const tag = el.getAttribute(actionAttr);
1071
+ const suffix = tag !== null && id === "" ? `[${actionAttr}=${tag}]` : "";
1072
+ return `${el.tagName.toLowerCase()}${id}${suffix}`;
1073
+ };
1074
+ const prompt = (el) => {
1075
+ const p = el.hasAttribute(promptAttr) ? el : el.querySelector(`[${promptAttr}]`);
1076
+ return p !== null && shown(p) ? (p.textContent ?? "").trim() : null;
1077
+ };
1078
+ const roots = [...document.querySelectorAll(rootSel)];
1079
+ const els = new Set(roots.flatMap((r) => [...r.querySelectorAll(`${pointerSel}, [${actionAttr}]`)]));
1080
+ return [...els].filter(shown).map((el) => ({
1081
+ name: label(el),
1082
+ action: el.getAttribute(actionAttr),
1083
+ hasPointerHandler: el.matches(pointerSel),
1084
+ promptText: prompt(el)
1085
+ }));
1086
+ }, { rootSel: root, pointerSel: pointerSelector, actionAttr: ACTION_ATTR, promptAttr: PROMPT_ATTR });
1087
+ }
1088
+ async function measureActionBinding(page, bindings, options = {}) {
1089
+ const els = await readActionElements(page, options.root, options.pointerSelector);
1090
+ return els.map((el) => toActionReading(el, bindings));
1091
+ }
1092
+ async function expectActionsBound(page, bindings, options = {}) {
1093
+ const readings = await measureActionBinding(page, bindings, options);
1094
+ const summary = summariseActionBinding(readings, options.where ?? options.root ?? ACTION_ROOT_SELECTOR);
1095
+ expect(summary.problems, summary.message).toBe(0);
1096
+ return readings;
1097
+ }
1098
+
1099
+ export { ACTION_ATTR, ACTION_ROOT_SELECTOR, ANTI_ALIAS_TOLERANCE, CANVAS_TIMEOUT_MS, CONTROL_SELECTOR, DEFAULT_CANVAS_SELECTOR, DESKTOP_DEVICE, DESKTOP_SIZE, EXACT, FIT_TIMEOUT_MS, GAME_SHELL_HEIGHT_VAR, HOOK_WALK_SIZES, MAX_REPORTED, MIN_TARGET_PX, PHONE_DEVICE, PHONE_SIZE, POINTER_SELECTOR, PROMPT_ATTR, RELAYOUT_TIMEOUT_MS, STUB_FRAMES, TEXT_FIT_SELECTOR, TEXT_FIT_TOLERANCE_PX, WALK_INPUTS, actionBindingFindings, armVisibleHeight, auditRoute, auditTouchTargets, canvasBoxToPage, controlName, countDiff, desktop, deviceDescriptor, diffPngs, domControls, expectActionsBound, expectCanvasHeight, expectCanvasInside, expectFitTo, expectHookMenuWalkable, expectMenuWalkable, expectNoHorizontalOverflow, expectNoHorizontalOverflowAcrossRoutes, expectTextFits, expectTouchTargets, expectTouchTargetsAcrossRoutes, findOverlaps, findOverlapsWithin, gameProjects, horizontalOverflowPx, measureActionBinding, measureHorizontalOverflow, measureTextFit, overlaps, phone, readActionElements, readHorizontalOverflow, readTextBoxes, regionDiff, renderFindings, renderOverflow, renderRouteAudit, renderWalk, routeProblems, shrinkVisibleHeight, stubGamepad, summariseActionBinding, summariseOverflow, summariseTextFit, summariseTouchTargets, textFitFindings, toActionReading, toOverflowReading, walkFailed, walkHookMenus, walkMenus };
1017
1100
  //# sourceMappingURL=index.mjs.map
1018
1101
  //# sourceMappingURL=index.mjs.map