blob: 432069a720a8955afae78443ac63dcd845332232 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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);
});
});
|