summaryrefslogtreecommitdiff
path: root/e2e/helpers/tab.ts
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2026-11-23 00:51:32 +0100
committerJoel Klinghed <the_jk@spawned.biz>2026-11-23 00:51:32 +0100
commit93970f361b831f17d48ff2a345fc78488ac71fba (patch)
treef3844cc343c95dcc19a1444bdb6666e807bc59ef /e2e/helpers/tab.ts
parentb884441ba0d10bdd3559748507a0991888f66194 (diff)
Phase 7: hardening and shipping (M7)
E2E (Playwright, e2e/): - table fixture: one real compiled server per test (temp saves dir, free port, workers: 1); a Tab helper drives the real UI (menus, rows, initiative, draw, seats) over one WS per fresh browser context - full round: onboarding, secret initiative masked to ?? per connection, draw revealing on every screen, turns, next round, round-2 secrecy - seats: claim/re-claim on owner-leave, reload keeps the session and re-claims, two sessions can't own one character - resilience: a dropped tab resyncs on reconnect (no drift); a SIGKILL'd server restarts with state + seats surviving (incl. the owner's secret initiative and the enabled draw); a throttled tab converges on the same state as the fast tabs; a double-tapped draw runs once, error sent to the sender only - figure edit: set a character level + rename from the status menu Cross-check vs the reference (feature parity): - status menu: level pills (setCharacterLevel) + a name field (changeName), mirroring SetCharacterLevelMenu - ability-card removal: draw-pile-only "send to bottom" (reorderAbilityList -> index 0) + "shuffle undrawn cards" (shuffleDrawnAbilityCard), mirroring RemoveCardMenu - Add Character: already-added classes disabled (Objective/Escort may be added repeatedly), matching _characterAlreadyAdded - every remaining registry command verified reachable from the UI Session persistence (found by the restart test): - the client never learned its session id before the first welcome, so a reconnect minted a new id and orphaned the restored seat; fixed with establishSessionCookie() (a GET /session before the WS upgrade, plus a vite /session proxy) so the x-haven-session cookie survives restarts - the initiative input now prefills from re-synced state (CharacterRow effect, guarded against clobbering a live edit) so a reload/reconnect doesn't blank an entry Performance + deployment: - immutable asset caching (Cache-Control: 1yr, immutable) for the game data / images / in-game translations; no-cache for the SPA index.html so rebuilt apps reach open tabs - server tool/perf_measure.dart: the performance probe (state payload size at full-table scale, WS fan-out bytes per action, traffic per connection) - Dockerfile (server + built web); docs/DEPLOYMENT.md (Docker, persistence, reverse proxy, measured performance, smoke-test list) - README quickstart + production/Docker/testing sections Server: - --saves-dir and --data-dir CLI options (Docker / multi-game hosts), threaded through the stores and data loading Misc: - app.css: height 100% on .row so the turn-done tap zone resolves to a clickable height; fake-socket.ts readyState constants corrected to the real WebSocket values (0 CONNECTING, 1 OPEN) - scripts/ci.sh: the Playwright E2E gate (runs when PLAYWRIGHT is set) - PLAN.md: Phase 7 boxes checked, M7 progress-log entry Verification: svelte-check 0 errors; web 196/196 tests; vite build OK; dart analyze 0 errors / 0 warnings; dart test 604/604; Playwright 9/9; scripts/ci.sh green end-to-end.
Diffstat (limited to 'e2e/helpers/tab.ts')
-rw-r--r--e2e/helpers/tab.ts188
1 files changed, 188 insertions, 0 deletions
diff --git a/e2e/helpers/tab.ts b/e2e/helpers/tab.ts
new file mode 100644
index 0000000..616f783
--- /dev/null
+++ b/e2e/helpers/tab.ts
@@ -0,0 +1,188 @@
+/**
+ * One browser tab on the table (PLAN.md Phase 7): drives the real UI —
+ * menus, character rows, the initiative widget, the draw button — and
+ * asserts on the DOM each connection actually receives (the per-connection
+ * masked state, PLAN.md section 3.4).
+ */
+import type { Locator, Page } from '@playwright/test';
+
+export class Tab {
+ constructor(public readonly page: Page) {}
+
+ /** Loads the game page and waits for the WS handshake to complete. */
+ async open(url: string): Promise<void> {
+ await this.page.goto(url, { waitUntil: 'domcontentloaded' });
+ await this.waitForConnected();
+ }
+
+ /** The "Connecting…" banner is visible until the first `welcome` lands. */
+ async waitForConnected(): Promise<void> {
+ await this.page.waitForSelector('.topbar');
+ await this.page
+ .locator('.banner[role="status"]')
+ .waitFor({ state: 'detached', timeout: 30_000 });
+ }
+
+ // --- main list -----------------------------------------------------------
+
+ /** The character row whose display name is [name]. */
+ row(name: string): Locator {
+ return this.page
+ .locator('.row--character')
+ .filter({ has: this.page.locator('.row__name', { hasText: name }) });
+ }
+
+ /** The monster row whose name is [name]. */
+ monsterRow(name: string): Locator {
+ return this.page
+ .locator('.row--monster')
+ .filter({ has: this.page.locator('.row__name', { hasText: name }) });
+ }
+
+ // --- menus ---------------------------------------------------------------
+
+ /** Opens the main drawer and picks the [label] entry (a menu dialog). */
+ async openMenu(label: string): Promise<void> {
+ await this.page.locator('.topbar__menu').click();
+ await this.page
+ .locator('nav[aria-label="Main menu"]')
+ .getByRole('button', { name: label, exact: true })
+ .click();
+ await this.page.locator('.dialog__overlay').first().waitFor();
+ }
+
+ /** The open dialog titled [title]. */
+ dialog(title: string): Locator {
+ return this.page
+ .locator('.dialog__overlay')
+ .filter({
+ has: this.page.locator('.dialog__title', { hasText: title })
+ });
+ }
+
+ /**
+ * Adds a character via the Add Character menu (level defaults to 1).
+ * Resolves once the row appears — i.e. the server's update arrived.
+ */
+ async addCharacter(name: string, level = 1): Promise<void> {
+ await this.openMenu('Add Character');
+ const dlg = this.dialog('Add Character');
+ const up = dlg.locator('.stepbtn').nth(1);
+ for (let i = 1; i < level; i++) await up.click();
+ await dlg.locator('.menulist__item').filter({ hasText: name }).click();
+ await this.row(name).waitFor({ timeout: 15_000 });
+ }
+
+ /** Picks [scenarioName] (optionally switching to [campaign] first). */
+ async selectScenario(scenarioName: string, campaign?: string): Promise<void> {
+ await this.openMenu('Set Scenario');
+ const dlg = this.dialog('Set Scenario');
+ if (campaign) {
+ await dlg.locator('.campaignbtns button').filter({ hasText: campaign }).click();
+ }
+ await dlg
+ .locator('.menulist__item')
+ .filter({ hasText: scenarioName })
+ .first()
+ .click();
+ await this.page.locator('.dialog__overlay').waitFor({ state: 'detached' });
+ }
+
+ /** Adds a monster via the Add Monsters menu. */
+ async addMonster(name: string, level = 1): Promise<void> {
+ await this.openMenu('Add Monsters');
+ const dlg = this.dialog('Add Monsters');
+ const up = dlg.locator('.stepbtn').nth(1);
+ for (let i = 1; i < level; i++) await up.click();
+ await dlg.locator('.menulist__item').filter({ hasText: name }).first().click();
+ await this.monsterRow(name).waitFor({ timeout: 15_000 });
+ }
+
+ // --- initiative (the server-gated secret) --------------------------------
+
+ /** Enters [value] in this tab's initiative input for [rowName]. */
+ async setInitiative(rowName: string, value: number): Promise<void> {
+ const input = this.row(rowName).locator('input.init__input');
+ await input.waitFor({ timeout: 15_000 });
+ await input.fill(String(value));
+ }
+
+ /** The initiative value shown on [rowName] in this tab (the `.init` cell). */
+ initDisplay(rowName: string): Locator {
+ return this.row(rowName).locator('.init');
+ }
+
+ /** True when [rowName] shows an editable initiative input on this tab. */
+ async hasInitiativeInput(rowName: string): Promise<boolean> {
+ return (await this.row(rowName).locator('input.init__input').count()) > 0;
+ }
+
+ // --- draw / turns ---------------------------------------------------------
+
+ /** Taps Draw (chooseInitiative) or Next Round (playTurns). */
+ async clickDraw(): Promise<void> {
+ await this.page.locator('button.drawbtn').click();
+ }
+
+ /** Waits until the round has been drawn (the button reads Next Round). */
+ async waitForDrawn(): Promise<void> {
+ await this.page
+ .getByRole('button', { name: /Next Round/ })
+ .waitFor({ timeout: 15_000 });
+ }
+
+ /** Waits until a new round is being chosen (the button reads Draw). */
+ async waitForRoundChosen(): Promise<void> {
+ await this.page.getByRole('button', { name: /Draw/ }).waitFor({ timeout: 15_000 });
+ }
+
+ /** Taps the right-hand turn-done zone of [rowName] (playTurns). */
+ async turnDone(rowName: string): Promise<void> {
+ await this.row(rowName).locator('div[aria-label="Turn done"]').click();
+ }
+
+ /** The round counter under the draw button (e.g. "Round 1/1"). */
+ roundLabel(): Locator {
+ return this.page.locator('.drawbtn__round');
+ }
+
+ /** The draw/next-round button's enabled state (players only). */
+ async drawEnabled(): Promise<boolean> {
+ return this.page.locator('button.drawbtn').isEnabled();
+ }
+
+ // --- seats (claim / re-claim) --------------------------------------------
+
+ /**
+ * Opens the figure's status (stat) menu by tapping the row's name, and
+ * returns the open dialog (titled with the figure's display name).
+ */
+ async openStatusMenu(rowName: string): Promise<Locator> {
+ await this.row(rowName).locator('.row__name').click();
+ const dlg = this.dialog(rowName);
+ await dlg.waitFor({ timeout: 15_000 });
+ return dlg;
+ }
+
+ /** The "Claim" chip on [rowName] (visible while the character is unclaimed). */
+ claimChip(rowName: string): Locator {
+ return this.row(rowName).locator('button.chip--claim');
+ }
+
+ /** Clicks the Claim chip on [rowName]. */
+ async claim(rowName: string): Promise<void> {
+ await this.claimChip(rowName).click();
+ }
+
+ // --- misc -----------------------------------------------------------------
+
+ /** The current toast text (server errors / scenario events), if any. */
+ toast(): Locator {
+ return this.page.locator('.toast[role="status"]');
+ }
+
+ /** Closes this tab's page (the server sees the connection drop). */
+ async closePage(): Promise<void> {
+ await this.page.close();
+ }
+}