feat(ui): accessibility pass — WCAG 2.2 AA for login/lobby/shell (F2)
Add the a11y foundation and bring login, lobby, and the in-game shell to WCAG 2.2 AA: - Primitives: .sr-only + .skip-link (base.css), trapFocus (modal focus trap + restore) and restoreFocus (menu focus restore) actions, the --color-focus visible ring. - In-game shell: skip link + focusable main landmark; WAI-ARIA sidebar tabs (roving tabindex, arrow/Home/End, tabpanel wiring); menu Escape + focus restore (account / view / turn-navigator / map-toggles / bottom-tabs); mail compose as a role=dialog modal with a focus trap. - login / lobby / lobby-create: skip link + main landmark, field labels, role=alert / role=status live regions. - Map canvas: aria-label naming it a visual overview, with its data reachable by keyboard via the sidebar inspector and tables (accessible alternative; in-canvas keyboard nav deferred). Gates (chromium-desktop): tests/e2e/a11y-axe.spec.ts scans every top-level view for WCAG 2.2 AA violations (zero); a11y-keyboard.spec.ts covers the skip link, menu Escape+restore, and tab roving. Adds @axe-core/playwright. Docs: ui/docs/a11y.md (+ index). Marks F1 and F2 done in ui/PLAN-finalize.md. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
"pixi.js": "^8.18.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@axe-core/playwright": "4.11.3",
|
||||
"@bufbuild/protobuf": "^2.12.0",
|
||||
"@bufbuild/protoc-gen-es": "^2.12.0",
|
||||
"@connectrpc/connect": "^2.1.1",
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* Focus management for modal dialogs.
|
||||
*
|
||||
* `trapFocus` is a Svelte action for an element with `role="dialog"` and
|
||||
* `aria-modal="true"`. On mount it remembers the currently-focused
|
||||
* element, moves focus into the dialog, and keeps Tab / Shift+Tab cycling
|
||||
* within it; on destroy it restores focus to the original element. ESC
|
||||
* handling stays with the component (it owns the open/close state).
|
||||
*
|
||||
* Initial focus goes to the element marked `data-autofocus`, else the
|
||||
* first focusable element, else the dialog node itself.
|
||||
*/
|
||||
|
||||
const FOCUSABLE_SELECTOR = [
|
||||
"a[href]",
|
||||
"button:not([disabled])",
|
||||
"input:not([disabled])",
|
||||
"select:not([disabled])",
|
||||
"textarea:not([disabled])",
|
||||
'[tabindex]:not([tabindex="-1"])',
|
||||
].join(",");
|
||||
|
||||
function focusableWithin(node: HTMLElement): HTMLElement[] {
|
||||
return Array.from(
|
||||
node.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR),
|
||||
).filter((el) => el.offsetParent !== null || el === document.activeElement);
|
||||
}
|
||||
|
||||
/** Svelte action: trap and restore focus for a modal dialog node. */
|
||||
export function trapFocus(node: HTMLElement): { destroy(): void } {
|
||||
const previouslyFocused =
|
||||
document.activeElement instanceof HTMLElement
|
||||
? document.activeElement
|
||||
: null;
|
||||
|
||||
function onKeydown(event: KeyboardEvent): void {
|
||||
if (event.key !== "Tab") return;
|
||||
const items = focusableWithin(node);
|
||||
if (items.length === 0) {
|
||||
event.preventDefault();
|
||||
node.focus();
|
||||
return;
|
||||
}
|
||||
const first = items[0];
|
||||
const last = items[items.length - 1];
|
||||
const active = document.activeElement;
|
||||
if (event.shiftKey && active === first) {
|
||||
event.preventDefault();
|
||||
last.focus();
|
||||
} else if (!event.shiftKey && active === last) {
|
||||
event.preventDefault();
|
||||
first.focus();
|
||||
}
|
||||
}
|
||||
|
||||
const initial =
|
||||
node.querySelector<HTMLElement>("[data-autofocus]") ??
|
||||
focusableWithin(node)[0] ??
|
||||
node;
|
||||
initial.focus();
|
||||
|
||||
node.addEventListener("keydown", onKeydown);
|
||||
|
||||
return {
|
||||
destroy(): void {
|
||||
node.removeEventListener("keydown", onKeydown);
|
||||
previouslyFocused?.focus();
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Focus restoration for transient popovers and menus.
|
||||
*
|
||||
* `restoreFocus` is a Svelte action for a surface that is rendered only
|
||||
* while open (an `{#if open}` popover/menu/drawer). On mount it records
|
||||
* the element that had focus — the trigger that opened it — and on
|
||||
* destroy it returns focus there, so dismissing the surface (Escape,
|
||||
* outside click, or selecting an item) never drops keyboard focus to the
|
||||
* document body.
|
||||
*
|
||||
* Unlike `trapFocus`, it neither traps focus nor moves it into the
|
||||
* surface: menus are non-modal, so the user tabs in only if they want.
|
||||
* Focus is restored only when it would otherwise be lost (it is inside
|
||||
* the closing surface or already on `<body>`); if the user has
|
||||
* deliberately moved focus to another control, that choice is left
|
||||
* alone.
|
||||
*/
|
||||
export function restoreFocus(node: HTMLElement): { destroy(): void } {
|
||||
const trigger =
|
||||
document.activeElement instanceof HTMLElement
|
||||
? document.activeElement
|
||||
: null;
|
||||
|
||||
return {
|
||||
destroy(): void {
|
||||
const active = document.activeElement;
|
||||
const lost =
|
||||
active === null ||
|
||||
active === document.body ||
|
||||
node.contains(active);
|
||||
if (lost) trigger?.focus();
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -10,6 +10,7 @@ surfaces the resulting 403 inline.
|
||||
import { getContext } from "svelte";
|
||||
|
||||
import { i18n } from "$lib/i18n/index.svelte";
|
||||
import { trapFocus } from "$lib/a11y/focus-trap";
|
||||
import { mailStore } from "$lib/mail-store.svelte";
|
||||
import {
|
||||
RENDERED_REPORT_CONTEXT_KEY,
|
||||
@@ -51,6 +52,10 @@ surfaces the resulting 403 inline.
|
||||
}
|
||||
});
|
||||
|
||||
function onWindowKeydown(event: KeyboardEvent): void {
|
||||
if (event.key === "Escape") onClose();
|
||||
}
|
||||
|
||||
async function submit(event: SubmitEvent): Promise<void> {
|
||||
event.preventDefault();
|
||||
error = null;
|
||||
@@ -84,16 +89,30 @@ surfaces the resulting 403 inline.
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="overlay" data-testid="mail-compose">
|
||||
<svelte:window onkeydown={onWindowKeydown} />
|
||||
|
||||
<div
|
||||
class="overlay"
|
||||
data-testid="mail-compose"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="mail-compose-title"
|
||||
use:trapFocus
|
||||
>
|
||||
<form class="dialog" onsubmit={submit}>
|
||||
<header>
|
||||
<h3>{i18n.t("game.mail.compose_action")}</h3>
|
||||
<button type="button" class="close" onclick={onClose}>×</button>
|
||||
<h3 id="mail-compose-title">{i18n.t("game.mail.compose_action")}</h3>
|
||||
<button
|
||||
type="button"
|
||||
class="close"
|
||||
aria-label={i18n.t("common.dismiss")}
|
||||
onclick={onClose}>×</button
|
||||
>
|
||||
</header>
|
||||
|
||||
<label>
|
||||
{i18n.t("game.mail.compose.target_label")}
|
||||
<select bind:value={kind} data-testid="mail-compose-kind">
|
||||
<select bind:value={kind} data-testid="mail-compose-kind" data-autofocus>
|
||||
<option value="personal">{i18n.t("game.mail.compose.target_personal")}</option>
|
||||
<option value="broadcast">{i18n.t("game.mail.compose.target_broadcast")}</option>
|
||||
</select>
|
||||
@@ -111,7 +130,7 @@ surfaces the resulting 403 inline.
|
||||
{/if}
|
||||
|
||||
<label>
|
||||
<span class="visually-hidden">{i18n.t("game.mail.subject_placeholder")}</span>
|
||||
<span class="sr-only">{i18n.t("game.mail.subject_placeholder")}</span>
|
||||
<input
|
||||
type="text"
|
||||
bind:value={subject}
|
||||
@@ -121,7 +140,7 @@ surfaces the resulting 403 inline.
|
||||
</label>
|
||||
|
||||
<label>
|
||||
<span class="visually-hidden">{i18n.t("game.mail.body_placeholder")}</span>
|
||||
<span class="sr-only">{i18n.t("game.mail.body_placeholder")}</span>
|
||||
<textarea
|
||||
bind:value={body}
|
||||
placeholder={i18n.t("game.mail.body_placeholder")}
|
||||
@@ -229,12 +248,4 @@ surfaces the resulting 403 inline.
|
||||
font-size: 0.85rem;
|
||||
margin: 0;
|
||||
}
|
||||
.visually-hidden {
|
||||
position: absolute;
|
||||
clip: rect(0 0 0 0);
|
||||
clip-path: inset(50%);
|
||||
height: 1px;
|
||||
width: 1px;
|
||||
overflow: hidden;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -14,6 +14,7 @@ bottom-tabs bar.
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import { i18n } from "$lib/i18n/index.svelte";
|
||||
import { restoreFocus } from "$lib/a11y/restore-focus";
|
||||
import type { MapToggles, GameStateStore } from "$lib/game-state.svelte";
|
||||
import type { WrapMode } from "../../map/world";
|
||||
|
||||
@@ -83,7 +84,12 @@ bottom-tabs bar.
|
||||
<span aria-hidden="true">⚙</span>
|
||||
</button>
|
||||
{#if open}
|
||||
<div class="surface" role="menu" data-testid="map-toggles-surface">
|
||||
<div
|
||||
class="surface"
|
||||
role="menu"
|
||||
data-testid="map-toggles-surface"
|
||||
use:restoreFocus
|
||||
>
|
||||
<fieldset>
|
||||
<legend>{i18n.t("game.map.toggles.section.objects")}</legend>
|
||||
<label>
|
||||
|
||||
@@ -706,7 +706,12 @@ preference the store already manages.
|
||||
data-planet-count={store?.report?.planets.length ?? 0}
|
||||
bind:this={containerEl}
|
||||
>
|
||||
<canvas bind:this={canvasEl}></canvas>
|
||||
<canvas
|
||||
bind:this={canvasEl}
|
||||
aria-label={i18n.t("game.map.aria_label", {
|
||||
count: String(store?.report?.planets.length ?? 0),
|
||||
})}
|
||||
></canvas>
|
||||
{#if store !== undefined && store.status === "ready"}
|
||||
<MapTogglesControl {store} />
|
||||
{/if}
|
||||
|
||||
@@ -15,6 +15,7 @@ Sessions and Theme) take over.
|
||||
} from "$lib/i18n/index.svelte";
|
||||
import { session } from "$lib/session-store.svelte";
|
||||
import { theme, type ThemeChoice } from "$lib/theme/theme.svelte";
|
||||
import { restoreFocus } from "$lib/a11y/restore-focus";
|
||||
|
||||
const THEME_CHOICES: ReadonlyArray<{ id: ThemeChoice; key: TranslationKey }> = [
|
||||
{ id: "system", key: "game.shell.menu.theme_system" },
|
||||
@@ -79,7 +80,12 @@ Sessions and Theme) take over.
|
||||
⚙
|
||||
</button>
|
||||
{#if open}
|
||||
<div class="surface" role="menu" data-testid="account-menu-list">
|
||||
<div
|
||||
class="surface"
|
||||
role="menu"
|
||||
data-testid="account-menu-list"
|
||||
use:restoreFocus
|
||||
>
|
||||
<button type="button" role="menuitem" data-testid="account-menu-settings" disabled>
|
||||
{i18n.t("game.shell.menu.settings")}
|
||||
</button>
|
||||
|
||||
@@ -17,6 +17,7 @@ Selecting a row calls `gameState.viewTurn(N)`; the row that matches
|
||||
<script lang="ts">
|
||||
import { getContext, onMount } from "svelte";
|
||||
import { i18n } from "$lib/i18n/index.svelte";
|
||||
import { restoreFocus } from "$lib/a11y/restore-focus";
|
||||
import {
|
||||
GAME_STATE_CONTEXT_KEY,
|
||||
type GameStateStore,
|
||||
@@ -139,7 +140,12 @@ Selecting a row calls `gameState.viewTurn(N)`; the row that matches
|
||||
→
|
||||
</button>
|
||||
{#if open}
|
||||
<div class="surface" role="menu" data-testid="turn-navigator-list">
|
||||
<div
|
||||
class="surface"
|
||||
role="menu"
|
||||
data-testid="turn-navigator-list"
|
||||
use:restoreFocus
|
||||
>
|
||||
{#each turns as turn (turn)}
|
||||
<button
|
||||
type="button"
|
||||
|
||||
@@ -16,6 +16,7 @@ polishes microcopy.
|
||||
import { goto } from "$app/navigation";
|
||||
import { i18n, type TranslationKey } from "$lib/i18n/index.svelte";
|
||||
import { mailStore } from "$lib/mail-store.svelte";
|
||||
import { restoreFocus } from "$lib/a11y/restore-focus";
|
||||
|
||||
type Props = { gameId: string };
|
||||
let { gameId }: Props = $props();
|
||||
@@ -81,7 +82,12 @@ polishes microcopy.
|
||||
<span class="icon-hamburger" aria-hidden="true">☰</span>
|
||||
</button>
|
||||
{#if open}
|
||||
<div class="surface" role="menu" data-testid="view-menu-list">
|
||||
<div
|
||||
class="surface"
|
||||
role="menu"
|
||||
data-testid="view-menu-list"
|
||||
use:restoreFocus
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
role="menuitem"
|
||||
|
||||
@@ -8,6 +8,7 @@ const en = {
|
||||
"common.language": "language",
|
||||
"common.loading": "loading…",
|
||||
"common.dismiss": "dismiss",
|
||||
"common.skip_to_content": "skip to main content",
|
||||
"common.browser_not_supported_title": "browser not supported",
|
||||
"common.browser_not_supported_body":
|
||||
"Galaxy requires Ed25519 in WebCrypto. See supported browsers.",
|
||||
@@ -117,6 +118,8 @@ const en = {
|
||||
"game.shell.history.current_badge": "current",
|
||||
"game.view.map": "map",
|
||||
"game.map.toggles.open": "open map visibility menu",
|
||||
"game.map.aria_label":
|
||||
"galaxy map ({count} planets) — a visual overview; planet, ship-group and route details are available in the sidebar inspector and the tables view",
|
||||
"game.map.toggles.close": "close map visibility menu",
|
||||
"game.map.toggles.section.objects": "Objects",
|
||||
"game.map.toggles.section.planets": "Planets",
|
||||
|
||||
@@ -9,6 +9,7 @@ const ru: Record<keyof typeof en, string> = {
|
||||
"common.language": "язык",
|
||||
"common.loading": "загрузка…",
|
||||
"common.dismiss": "закрыть",
|
||||
"common.skip_to_content": "к основному содержимому",
|
||||
"common.browser_not_supported_title": "браузер не поддерживается",
|
||||
"common.browser_not_supported_body":
|
||||
"Galaxy требует поддержки Ed25519 в WebCrypto. См. список поддерживаемых браузеров.",
|
||||
@@ -118,6 +119,8 @@ const ru: Record<keyof typeof en, string> = {
|
||||
"game.shell.history.current_badge": "текущий",
|
||||
"game.view.map": "карта",
|
||||
"game.map.toggles.open": "открыть меню видимости карты",
|
||||
"game.map.aria_label":
|
||||
"карта галактики ({count} планет) — визуальный обзор; детали планет, групп кораблей и маршрутов доступны в инспекторе сайдбара и в таблицах",
|
||||
"game.map.toggles.close": "закрыть меню видимости карты",
|
||||
"game.map.toggles.section.objects": "Объекты",
|
||||
"game.map.toggles.section.planets": "Планеты",
|
||||
|
||||
@@ -16,6 +16,7 @@ destinations beats the duplication.
|
||||
import { onMount } from "svelte";
|
||||
import { goto } from "$app/navigation";
|
||||
import { i18n, type TranslationKey } from "$lib/i18n/index.svelte";
|
||||
import { restoreFocus } from "$lib/a11y/restore-focus";
|
||||
import type { MobileTool } from "./types";
|
||||
|
||||
type Props = {
|
||||
@@ -131,7 +132,12 @@ destinations beats the duplication.
|
||||
</button>
|
||||
</div>
|
||||
{#if moreOpen}
|
||||
<div class="drawer" role="menu" data-testid="bottom-tabs-more-drawer">
|
||||
<div
|
||||
class="drawer"
|
||||
role="menu"
|
||||
data-testid="bottom-tabs-more-drawer"
|
||||
use:restoreFocus
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
role="menuitem"
|
||||
|
||||
@@ -91,7 +91,13 @@ through the binding without extra plumbing.
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
<div class="content" data-testid="sidebar-content">
|
||||
<div
|
||||
class="content"
|
||||
role="tabpanel"
|
||||
id="sidebar-panel"
|
||||
aria-labelledby="sidebar-tab-{activeTab}"
|
||||
data-testid="sidebar-content"
|
||||
>
|
||||
{#if activeTab === "calculator"}
|
||||
<Calculator />
|
||||
{:else if activeTab === "inspector"}
|
||||
|
||||
@@ -29,17 +29,60 @@ flips it on.
|
||||
const tabs = $derived(
|
||||
hideOrder ? allTabs.filter((t) => t.id !== "order") : allTabs,
|
||||
);
|
||||
|
||||
let tablistEl: HTMLDivElement | undefined = $state();
|
||||
|
||||
// WAI-ARIA tabs keyboard pattern: arrows move between tabs (with
|
||||
// wrap-around), Home/End jump to the ends. Activation is automatic —
|
||||
// moving focus also selects the tab — and focus follows to the
|
||||
// newly-active tab button.
|
||||
function onKeydown(event: KeyboardEvent, index: number): void {
|
||||
const ids = tabs.map((t) => t.id);
|
||||
let next = index;
|
||||
switch (event.key) {
|
||||
case "ArrowRight":
|
||||
case "ArrowDown":
|
||||
next = (index + 1) % ids.length;
|
||||
break;
|
||||
case "ArrowLeft":
|
||||
case "ArrowUp":
|
||||
next = (index - 1 + ids.length) % ids.length;
|
||||
break;
|
||||
case "Home":
|
||||
next = 0;
|
||||
break;
|
||||
case "End":
|
||||
next = ids.length - 1;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
onSelect(ids[next]);
|
||||
tablistEl
|
||||
?.querySelector<HTMLElement>(`[data-testid="sidebar-tab-${ids[next]}"]`)
|
||||
?.focus();
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="tab-bar" role="tablist" data-testid="sidebar-tab-bar">
|
||||
{#each tabs as tab (tab.id)}
|
||||
<div
|
||||
class="tab-bar"
|
||||
role="tablist"
|
||||
data-testid="sidebar-tab-bar"
|
||||
bind:this={tablistEl}
|
||||
>
|
||||
{#each tabs as tab, i (tab.id)}
|
||||
<button
|
||||
type="button"
|
||||
role="tab"
|
||||
id="sidebar-tab-{tab.id}"
|
||||
data-testid="sidebar-tab-{tab.id}"
|
||||
aria-selected={tab.id === activeTab}
|
||||
aria-controls="sidebar-panel"
|
||||
tabindex={tab.id === activeTab ? 0 : -1}
|
||||
class:active={tab.id === activeTab}
|
||||
onclick={() => onSelect(tab.id)}
|
||||
onkeydown={(e) => onKeydown(e, i)}
|
||||
>
|
||||
{i18n.t(tab.key)}
|
||||
</button>
|
||||
|
||||
@@ -27,3 +27,41 @@ body {
|
||||
::selection {
|
||||
background: var(--color-accent-subtle);
|
||||
}
|
||||
|
||||
/*
|
||||
* Visually-hidden content that stays available to assistive tech. Use
|
||||
* for labels/announcements a sighted user gets from layout or icons.
|
||||
*/
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
padding: 0;
|
||||
margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Skip link: visually hidden until focused, then slides into the
|
||||
* top-left so a keyboard user can jump straight to the main content.
|
||||
* Each layout renders one as its first focusable element, targeting a
|
||||
* `tabindex="-1"` main region.
|
||||
*/
|
||||
.skip-link {
|
||||
position: absolute;
|
||||
left: var(--space-2);
|
||||
top: -4rem;
|
||||
z-index: 100;
|
||||
padding: var(--space-2) var(--space-3);
|
||||
background: var(--color-surface-overlay);
|
||||
color: var(--color-text);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-sm);
|
||||
transition: top 120ms ease;
|
||||
}
|
||||
.skip-link:focus-visible {
|
||||
top: var(--space-2);
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ fresh.
|
||||
import { onDestroy, onMount, setContext, untrack } from "svelte";
|
||||
import { goto } from "$app/navigation";
|
||||
import { page } from "$app/state";
|
||||
import { i18n } from "$lib/i18n/index.svelte";
|
||||
import Header from "$lib/header/header.svelte";
|
||||
import HistoryBanner from "$lib/header/history-banner.svelte";
|
||||
import Sidebar from "$lib/sidebar/sidebar.svelte";
|
||||
@@ -528,6 +529,9 @@ fresh.
|
||||
</script>
|
||||
|
||||
<div class="game-shell" data-testid="game-shell">
|
||||
<a class="skip-link" href="#active-view-host">
|
||||
{i18n.t("common.skip_to_content")}
|
||||
</a>
|
||||
<Header
|
||||
{gameId}
|
||||
{sidebarOpen}
|
||||
@@ -535,7 +539,12 @@ fresh.
|
||||
/>
|
||||
<HistoryBanner />
|
||||
<div class="body">
|
||||
<main class="active-view-host" data-testid="active-view-host">
|
||||
<main
|
||||
class="active-view-host"
|
||||
id="active-view-host"
|
||||
tabindex="-1"
|
||||
data-testid="active-view-host"
|
||||
>
|
||||
{#if effectiveTool === "calc"}
|
||||
<Calculator />
|
||||
{:else if effectiveTool === "order"}
|
||||
|
||||
@@ -265,7 +265,8 @@
|
||||
});
|
||||
</script>
|
||||
|
||||
<main>
|
||||
<a class="skip-link" href="#main-content">{i18n.t("common.skip_to_content")}</a>
|
||||
<main id="main-content" tabindex="-1">
|
||||
<header>
|
||||
<h1>{i18n.t("lobby.title")}</h1>
|
||||
<p>
|
||||
@@ -297,7 +298,7 @@
|
||||
<section data-testid="lobby-my-games-section">
|
||||
<h2>{i18n.t("lobby.section.my_games")}</h2>
|
||||
{#if listsLoading}
|
||||
<p>{i18n.t("lobby.list_loading")}</p>
|
||||
<p role="status">{i18n.t("lobby.list_loading")}</p>
|
||||
{:else if myGames.length === 0}
|
||||
<p data-testid="lobby-my-games-empty">{i18n.t("lobby.my_games.empty")}</p>
|
||||
{:else}
|
||||
@@ -323,7 +324,7 @@
|
||||
<section data-testid="lobby-invitations-section">
|
||||
<h2>{i18n.t("lobby.section.invitations")}</h2>
|
||||
{#if listsLoading}
|
||||
<p>{i18n.t("lobby.list_loading")}</p>
|
||||
<p role="status">{i18n.t("lobby.list_loading")}</p>
|
||||
{:else if invitations.length === 0}
|
||||
<p data-testid="lobby-invitations-empty">{i18n.t("lobby.invitations.empty")}</p>
|
||||
{:else}
|
||||
@@ -357,7 +358,7 @@
|
||||
<section data-testid="lobby-applications-section">
|
||||
<h2>{i18n.t("lobby.section.applications")}</h2>
|
||||
{#if listsLoading}
|
||||
<p>{i18n.t("lobby.list_loading")}</p>
|
||||
<p role="status">{i18n.t("lobby.list_loading")}</p>
|
||||
{:else if applications.length === 0}
|
||||
<p data-testid="lobby-applications-empty">{i18n.t("lobby.applications.empty")}</p>
|
||||
{:else}
|
||||
@@ -416,7 +417,7 @@
|
||||
<section data-testid="lobby-public-games-section">
|
||||
<h2>{i18n.t("lobby.section.public_games")}</h2>
|
||||
{#if listsLoading}
|
||||
<p>{i18n.t("lobby.list_loading")}</p>
|
||||
<p role="status">{i18n.t("lobby.list_loading")}</p>
|
||||
{:else if publicGames.length === 0}
|
||||
<p data-testid="lobby-public-games-empty">{i18n.t("lobby.public_games.empty")}</p>
|
||||
{:else}
|
||||
|
||||
@@ -125,7 +125,8 @@
|
||||
});
|
||||
</script>
|
||||
|
||||
<main>
|
||||
<a class="skip-link" href="#main-content">{i18n.t("common.skip_to_content")}</a>
|
||||
<main id="main-content" tabindex="-1">
|
||||
<h1>{i18n.t("lobby.create.title")}</h1>
|
||||
{#if configError !== null}
|
||||
<p role="alert" data-testid="lobby-create-config-error">{configError}</p>
|
||||
|
||||
@@ -133,7 +133,8 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<main>
|
||||
<a class="skip-link" href="#main-content">{i18n.t("common.skip_to_content")}</a>
|
||||
<main id="main-content" tabindex="-1">
|
||||
<header>
|
||||
<h1>{i18n.t("login.title")}</h1>
|
||||
<div class="language-picker">
|
||||
@@ -166,7 +167,7 @@
|
||||
stroke-width="1.5"
|
||||
/>
|
||||
</svg>
|
||||
<label class="visually-hidden" for="login-language-select">
|
||||
<label class="sr-only" for="login-language-select">
|
||||
{i18n.t("common.language")}
|
||||
</label>
|
||||
<select
|
||||
@@ -303,18 +304,6 @@
|
||||
padding: 0.25rem 0.5rem;
|
||||
}
|
||||
|
||||
.visually-hidden {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
padding: 0;
|
||||
margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
// F2 — automated WCAG 2.2 AA scans with axe-core across every
|
||||
// top-level view. Runs only on chromium-desktop (axe's colour-contrast
|
||||
// and computed-role checks need one real engine; repeating across the
|
||||
// webkit/mobile projects adds cost without new signal).
|
||||
//
|
||||
// Auth is bootstrapped through `/__debug/store` exactly as the
|
||||
// game-shell specs do; the in-game layout tolerates a missing gateway
|
||||
// (ECONNREFUSED) and still renders the chrome + view shells, which is
|
||||
// what the structural a11y scan needs.
|
||||
|
||||
import AxeBuilder from "@axe-core/playwright";
|
||||
import { expect, test, type Page } from "@playwright/test";
|
||||
|
||||
const SESSION_ID = "f2-a11y-axe-session";
|
||||
// A real UUID — the layout's auto-sync calls `uuidToHiLo` on it.
|
||||
const GAME_ID = "10101010-1010-1010-1010-101010101010";
|
||||
|
||||
const WCAG_TAGS = ["wcag2a", "wcag2aa", "wcag21a", "wcag21aa", "wcag22aa"];
|
||||
|
||||
async function authenticate(page: Page): Promise<void> {
|
||||
await page.goto("/__debug/store");
|
||||
await expect(page.getByTestId("debug-store-ready")).toBeVisible();
|
||||
await page.waitForFunction(() => window.__galaxyDebug?.ready === true);
|
||||
await page.evaluate(() => window.__galaxyDebug!.clearSession());
|
||||
await page.evaluate(
|
||||
(id) => window.__galaxyDebug!.setDeviceSessionId(id),
|
||||
SESSION_ID,
|
||||
);
|
||||
}
|
||||
|
||||
async function expectNoViolations(page: Page): Promise<void> {
|
||||
const results = await new AxeBuilder({ page }).withTags(WCAG_TAGS).analyze();
|
||||
// Surface the rule ids in the assertion message for a fast triage.
|
||||
expect(
|
||||
results.violations,
|
||||
results.violations.map((v) => `${v.id} (${v.nodes.length})`).join(", "),
|
||||
).toEqual([]);
|
||||
}
|
||||
|
||||
test.describe("axe WCAG 2.2 AA", () => {
|
||||
test.beforeEach(({}, testInfo) => {
|
||||
test.skip(
|
||||
testInfo.project.name !== "chromium-desktop",
|
||||
"axe scan runs once, on chromium-desktop",
|
||||
);
|
||||
});
|
||||
|
||||
test("login", async ({ page }) => {
|
||||
await page.goto("/login");
|
||||
await expect(page.locator("#main-content")).toBeVisible();
|
||||
await expectNoViolations(page);
|
||||
});
|
||||
|
||||
test("lobby", async ({ page }) => {
|
||||
await authenticate(page);
|
||||
await page.goto("/lobby");
|
||||
await expect(page.locator("#main-content")).toBeVisible();
|
||||
await expectNoViolations(page);
|
||||
});
|
||||
|
||||
test("lobby create", async ({ page }) => {
|
||||
await authenticate(page);
|
||||
await page.goto("/lobby/create");
|
||||
await expect(page.locator("#main-content")).toBeVisible();
|
||||
await expectNoViolations(page);
|
||||
});
|
||||
|
||||
const inGameViews: Array<[string, string]> = [
|
||||
["map", "active-view-map"],
|
||||
["report", "active-view-report"],
|
||||
["mail", "active-view-mail"],
|
||||
["battle", "active-view-battle"],
|
||||
["designer/science", "active-view-designer-science"],
|
||||
["table/planets", "active-view-table"],
|
||||
];
|
||||
|
||||
for (const [path, testId] of inGameViews) {
|
||||
test(`in-game: ${path}`, async ({ page }) => {
|
||||
await authenticate(page);
|
||||
await page.goto(`/games/${GAME_ID}/${path}`);
|
||||
await expect(page.getByTestId("game-shell")).toBeVisible();
|
||||
await expect(page.getByTestId(testId)).toBeVisible();
|
||||
await expectNoViolations(page);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,66 @@
|
||||
// F2 — keyboard-only navigation coverage for the in-game shell.
|
||||
// Runs on chromium-desktop (a stable ≥1024px viewport where the sidebar
|
||||
// is visible); the behaviours under test are engine-independent.
|
||||
|
||||
import { expect, test, type Page } from "@playwright/test";
|
||||
|
||||
const SESSION_ID = "f2-a11y-keyboard-session";
|
||||
const GAME_ID = "10101010-1010-1010-1010-101010101010";
|
||||
|
||||
async function bootShell(page: Page): Promise<void> {
|
||||
await page.goto("/__debug/store");
|
||||
await expect(page.getByTestId("debug-store-ready")).toBeVisible();
|
||||
await page.waitForFunction(() => window.__galaxyDebug?.ready === true);
|
||||
await page.evaluate(() => window.__galaxyDebug!.clearSession());
|
||||
await page.evaluate(
|
||||
(id) => window.__galaxyDebug!.setDeviceSessionId(id),
|
||||
SESSION_ID,
|
||||
);
|
||||
await page.goto(`/games/${GAME_ID}/map`);
|
||||
await expect(page.getByTestId("game-shell")).toBeVisible();
|
||||
await expect(page.getByTestId("active-view-map")).toBeVisible();
|
||||
}
|
||||
|
||||
test.describe("keyboard navigation", () => {
|
||||
test.beforeEach(({}, testInfo) => {
|
||||
test.skip(
|
||||
testInfo.project.name !== "chromium-desktop",
|
||||
"keyboard specs run on chromium-desktop",
|
||||
);
|
||||
});
|
||||
|
||||
test("skip link is the first focusable and jumps to main content", async ({
|
||||
page,
|
||||
}) => {
|
||||
await bootShell(page);
|
||||
await page.keyboard.press("Tab");
|
||||
await expect(page.locator(".skip-link")).toBeFocused();
|
||||
await page.keyboard.press("Enter");
|
||||
await expect(page.locator("#active-view-host")).toBeFocused();
|
||||
});
|
||||
|
||||
test("Escape closes the account menu and returns focus to its trigger", async ({
|
||||
page,
|
||||
}) => {
|
||||
await bootShell(page);
|
||||
await page.getByTestId("account-menu-trigger").click();
|
||||
await expect(page.getByTestId("account-menu-list")).toBeVisible();
|
||||
// Move focus into the menu, then dismiss with Escape.
|
||||
await page.getByTestId("account-menu-theme-select").focus();
|
||||
await page.keyboard.press("Escape");
|
||||
await expect(page.getByTestId("account-menu-list")).toBeHidden();
|
||||
await expect(page.getByTestId("account-menu-trigger")).toBeFocused();
|
||||
});
|
||||
|
||||
test("sidebar tabs move with the arrow keys (roving)", async ({ page }) => {
|
||||
await bootShell(page);
|
||||
const calculator = page.getByTestId("sidebar-tab-calculator");
|
||||
const inspector = page.getByTestId("sidebar-tab-inspector");
|
||||
await calculator.click();
|
||||
await expect(calculator).toHaveAttribute("aria-selected", "true");
|
||||
await calculator.focus();
|
||||
await page.keyboard.press("ArrowRight");
|
||||
await expect(inspector).toBeFocused();
|
||||
await expect(inspector).toHaveAttribute("aria-selected", "true");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user