summaryrefslogtreecommitdiff
path: root/e2e/tests/full-round.spec.ts
blob: 6e3c7e7217e1d9e6e118c9d2ddd27a52042f5e16 (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
83
84
85
86
87
88
89
90
91
/**
 * E2E: two players + one spectator play a full round in real browser tabs
 * (PLAN.md Phase 7).
 *
 * Covers: the onboarding flow (a fresh spectator becomes a player by adding
 * a character), secret initiative (server-masked per connection), the draw
 * (reveal on every screen), turns, and the next round.
 */
import { test, expect } from '../helpers/table.js';

test('full round: setup, secret initiative, draw, turns, next round', async ({
	table
}) => {
	// --- Player 1 joins the empty table and becomes a player ---------------
	const p1 = (await table.newTab()).tab;
	await p1.open(table.server.url);
	// A fresh session is a spectator: the draw button is disabled and the
	// scenario menu is gated. Adding a character is the onboarding path.
	expect(await p1.drawEnabled()).toBe(false);
	await p1.addCharacter('Hatchet');
	expect(await p1.drawEnabled()).toBe(true);

	// Set the scenario now that p1 is a player.
	await p1.selectScenario('#1 Roadside Ambush');

	// --- Player 2 and a spectator join -------------------------------------
	const p2 = (await table.newTab()).tab;
	await p2.open(table.server.url);
	await p2.addCharacter('Voidwarden');

	const spec = (await table.newTab()).tab;
	await spec.open(table.server.url);
	await spec.row('Hatchet').waitFor({ timeout: 15_000 });
	await spec.row('Voidwarden').waitFor({ timeout: 15_000 });
	// The spectator sees both rows read-only: no inputs, no claim chips
	// (both characters are claimed), and a disabled draw button.
	expect(await spec.drawEnabled()).toBe(false);
	expect(await spec.claimChip('Hatchet').count()).toBe(0);
	expect(await spec.claimChip('Voidwarden').count()).toBe(0);
	expect(await spec.hasInitiativeInput('Hatchet')).toBe(false);

	// --- Secret initiative ---------------------------------------------------
	// Player 1 enters 4. Player 1 sees an editable input with the value;
	// player 2 and the spectator receive `null` from the server and see `??`.
	await p1.setInitiative('Hatchet', 4);
	expect(await p1.hasInitiativeInput('Hatchet')).toBe(true);
	await expect(p2.initDisplay('Hatchet')).toHaveText('??');
	await expect(p2.initDisplay('Hatchet')).toHaveClass(/init__secret/);
	await expect(spec.initDisplay('Hatchet')).toHaveText('??');

	// Player 2 enters 2; player 1 sees `??` for Voidwarden in turn.
	await p2.setInitiative('Voidwarden', 2);
	await expect(p1.initDisplay('Voidwarden')).toHaveText('??');
	await expect(spec.initDisplay('Voidwarden')).toHaveText('??');

	// --- Draw: every screen flips to playTurns at once -----------------------
	await p1.clickDraw();
	await p1.waitForDrawn();
	await p2.waitForDrawn();
	await spec.waitForDrawn();

	// Initiative is now public on every screen.
	await expect(p1.initDisplay('Hatchet')).toHaveText('4');
	await expect(p1.initDisplay('Voidwarden')).toHaveText('2');
	await expect(p2.initDisplay('Hatchet')).toHaveText('4');
	await expect(p2.initDisplay('Voidwarden')).toHaveText('2');
	await expect(spec.initDisplay('Hatchet')).toHaveText('4');
	await expect(spec.initDisplay('Voidwarden')).toHaveText('2');
	// … and no initiative inputs remain anywhere.
	expect(await p1.hasInitiativeInput('Hatchet')).toBe(false);
	expect(await p2.hasInitiativeInput('Voidwarden')).toBe(false);
	expect(await spec.hasInitiativeInput('Hatchet')).toBe(false);

	// --- Turns ---------------------------------------------------------------
	await p1.turnDone('Hatchet');
	await p2.turnDone('Voidwarden');

	// --- Next round: round 2, initiative secret again ------------------------
	await p1.clickDraw(); // "Next Round"
	await p1.waitForRoundChosen();
	await p2.waitForRoundChosen();
	await spec.waitForRoundChosen();
	await expect(p1.roundLabel()).toHaveText(/Round 2\//);
	await expect(p2.roundLabel()).toHaveText(/Round 2\//);
	await expect(spec.roundLabel()).toHaveText(/Round 2\//);
	// The round-2 values are secret again; only the owner's input is enabled.
	await expect(p2.initDisplay('Hatchet')).toHaveText('??');
	await expect(spec.initDisplay('Hatchet')).toHaveText('??');
	expect(await p1.hasInitiativeInput('Hatchet')).toBe(true);
	expect(await p2.hasInitiativeInput('Hatchet')).toBe(false);
});