diff options
Diffstat (limited to 'e2e/tests/seats.spec.ts')
| -rw-r--r-- | e2e/tests/seats.spec.ts | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/e2e/tests/seats.spec.ts b/e2e/tests/seats.spec.ts new file mode 100644 index 0000000..432069a --- /dev/null +++ b/e2e/tests/seats.spec.ts @@ -0,0 +1,82 @@ +/** + * E2E: seat claiming (PLAN.md Phase 7 / section 3.3). + * + * * a disconnected owner's character becomes claimable (the Claim chip) + * * claiming grants ownership on every screen (inputs enable) + * * a page reload keeps the session (cookie) but the seat must be re-claimed + * (the server releases seats on disconnect — the Phase 2 behaviour) + */ +import { test, expect } from '../helpers/table.js'; + +test.describe('Seats: claim / re-claim / reload', () => { + test('owner leaves → seat released → another session claims', async ({ + table + }) => { + const p1 = (await table.newTab()).tab; + await p1.open(table.server.url); + await p1.addCharacter('Hatchet'); + expect(await p1.hasInitiativeInput('Hatchet')).toBe(true); + + const p2 = (await table.newTab()).tab; + await p2.open(table.server.url); + await p2.row('Hatchet').waitFor({ timeout: 15_000 }); + // While p1 is connected the seat is taken: no claim chip. + expect(await p2.claimChip('Hatchet').count()).toBe(0); + + // p1 leaves the table (tab closed → the connection drops). + await p1.closePage(); + // The seat is released and broadcast: p2 now sees the claim chip. + await p2.claimChip('Hatchet').waitFor({ timeout: 15_000 }); + + await p2.claim('Hatchet'); + // p2 is the owner now: the chip is gone, inputs enable, and the draw + // button unlocks (a claimed seat makes p2 a player). The claim is a + // server round-trip (seats broadcast → re-render), so these auto-wait. + await expect(p2.claimChip('Hatchet')).toHaveCount(0); + await expect(p2.row('Hatchet').locator('input.init__input')).toHaveCount(1); + await expect(p2.page.locator('button.drawbtn')).toBeEnabled(); + }); + + test('a page reload keeps the session, and the seat is re-claimed', async ({ + table + }) => { + const p1 = (await table.newTab()).tab; + await p1.open(table.server.url); + await p1.addCharacter('Hatchet'); + expect(await p1.hasInitiativeInput('Hatchet')).toBe(true); + + // Reload the same tab (same context → the session cookie survives). + await p1.page.reload(); + await p1.waitForConnected(); + await p1.row('Hatchet').waitFor({ timeout: 15_000 }); + + // The disconnect released the seat: the character is claimable again, + // and the (reconnected) session claims it with one tap. + await p1.claimChip('Hatchet').waitFor({ timeout: 15_000 }); + await p1.claim('Hatchet'); + // The claim round-trip (seats broadcast → re-render) is async. + await expect(p1.row('Hatchet').locator('input.init__input')).toHaveCount(1); + await expect(p1.claimChip('Hatchet')).toHaveCount(0); + }); + + test('two sessions cannot own one character at once', async ({ table }) => { + const p1 = (await table.newTab()).tab; + await p1.open(table.server.url); + await p1.addCharacter('Hatchet'); + + // p1 leaves, p2 claims, p1 comes back and tries to re-claim the same + // character — the server rejects it (it is claimed by p2). + const p2 = (await table.newTab()).tab; + await p2.open(table.server.url); + await p2.row('Hatchet').waitFor({ timeout: 15_000 }); + await p1.closePage(); + await p2.claimChip('Hatchet').waitFor({ timeout: 15_000 }); + await p2.claim('Hatchet'); + + const p1Again = (await table.newTab()).tab; + await p1Again.open(table.server.url); + await p1Again.row('Hatchet').waitFor({ timeout: 15_000 }); + // p2 holds the seat: no claim chip for p1Again. + expect(await p1Again.claimChip('Hatchet').count()).toBe(0); + }); +}); |
