Open History to see the last commit
1import { expect, test } from "@playwright/test"
2import { openGame } from "./helpers"
3
4test.describe(`Game Flow`, () => {
5 test.beforeEach(async ({ page }) => {
6 await openGame(page)
7 })
8
9 test(`displays all main UI elements`, async ({ page }) => {
10 // Header elements
11 await expect(page.getByTestId(`team-badge`).filter({ visible: true })).toBeVisible()
12 await expect(page.getByTestId(`quota-meter`)).toBeVisible()
13
14 // Main game area - world view
15 const worldView = page.getByTestId(`world-view`)
16 await expect(worldView).toBeVisible()
17
18 // Zoom controls
19 await expect(page.getByRole(`button`, { name: /zoom in/i })).toBeVisible()
20 await expect(page.getByRole(`button`, { name: /zoom out/i })).toBeVisible()
21
22 // Score board
23 await expect(page.getByTestId(`scoreboard`).filter({ visible: true })).toBeVisible()
24 })
25
26 test(`team badge shows valid team`, async ({ page }) => {
27 const teamName = page.getByTestId(`team-name`).filter({ visible: true })
28 await expect(teamName).toBeVisible()
29
30 const text = await teamName.textContent()
31 expect([`Red Team`, `Blue Team`, `Green Team`, `Yellow Team`]).toContain(text)
32
33 // Team color dot should be visible
34 const colorDot = page.getByTestId(`team-color-dot`).filter({ visible: true })
35 await expect(colorDot).toBeVisible()
36 })
37
38 test(`quota meter shows 8 max`, async ({ page }) => {
39 const quotaText = page.getByTestId(`quota-meter-count`)
40 await expect(quotaText).toBeVisible()
41
42 const text = await quotaText.textContent()
43 // The shared dial shows the available move count.
44 expect(text).toMatch(/^[0-8]$/)
45
46 // Should have 8 segments
47 const segments = page.getByTestId(`quota-meter-segments`)
48 await expect(segments).toBeVisible()
49
50 const segmentCount = await segments.locator(`.move-dial-segment`).count()
51 expect(segmentCount).toBe(8)
52 })
53
54 test(`zoom controls work`, async ({ page }) => {
55 const zoomIn = page.getByRole(`button`, { name: /zoom in/i })
56 const zoomOut = page.getByRole(`button`, { name: /zoom out/i })
57
58 await expect(zoomIn).toBeVisible()
59 await expect(zoomOut).toBeVisible()
60
61 // Click zoom in multiple times
62 await zoomIn.click()
63 await zoomIn.click()
64
65 // Click zoom out
66 await zoomOut.click()
67
68 // Controls should still be visible and functional
69 await expect(zoomIn).toBeVisible()
70 await expect(zoomOut).toBeVisible()
71 })
72
73 test(`world view is clickable`, async ({ page }) => {
74 const worldView = page.getByTestId(`world-view`)
75 await expect(worldView).toBeVisible()
76
77 // Get the bounding box
78 const box = await worldView.boundingBox()
79 expect(box).toBeTruthy()
80
81 if (box) {
82 // Click in the center of the world view
83 await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2)
84
85 // The click should be handled (we just verify no errors occur)
86 // The actual behavior depends on game state
87 }
88 })
89
90 test(`page loads without console errors`, async ({ page }) => {
91 const errors: Array<string> = []
92
93 page.on(`console`, (msg) => {
94 if (msg.type() === `error`) {
95 errors.push(msg.text())
96 }
97 })
98
99 await openGame(page)
100 await page.waitForTimeout(1000)
101
102 // Filter out expected errors (like network errors in test env)
103 const unexpectedErrors = errors.filter(
104 (error) => !error.includes(`net::ERR_`) && !error.includes(`Failed to load`),
105 )
106
107 expect(unexpectedErrors).toHaveLength(0)
108 })
109
110 test(`connection status indicator is present`, async ({ page }) => {
111 // Connection status should show some form of status
112 const connectionStatus = page.locator(`.connection-status`)
113
114 // It might not be visible initially, but if present should have valid content
115 const count = await connectionStatus.count()
116 if (count > 0) {
117 await expect(connectionStatus).toBeVisible()
118 }
119 })
120
121 test(`score board shows all teams`, async ({ page }) => {
122 const scoreBoard = page.getByTestId(`scoreboard`).filter({ visible: true })
123 await expect(scoreBoard).toBeVisible()
124
125 // Should show 4 team scores
126 const teamScores = scoreBoard.locator(
127 `[data-testid^="score-"]:not([data-testid="score-local"])`,
128 )
129 const count = await teamScores.count()
130 expect(count).toBe(4)
131 })
132})