|
| 1 | +import { test, expect, type Page } from '@playwright/test'; |
| 2 | + |
| 3 | +async function waitForBoard(page: Page) { |
| 4 | + await page.goto('/'); |
| 5 | + await page.locator('#board').waitFor({ state: 'visible' }); |
| 6 | +} |
| 7 | + |
| 8 | +test.describe('Game board', () => { |
| 9 | + test.beforeEach(async ({ page }) => { |
| 10 | + await waitForBoard(page); |
| 11 | + }); |
| 12 | + |
| 13 | + test('renders the board with toolbar and dice', async ({ page }) => { |
| 14 | + await expect(page.locator('#board')).toBeVisible(); |
| 15 | + await expect(page.locator('#toolbar')).toBeVisible(); |
| 16 | + await expect(page.locator('.dice')).toBeVisible(); |
| 17 | + }); |
| 18 | + |
| 19 | + test('displays 24 points, 2 bar areas, and 2 home areas', async ({ page }) => { |
| 20 | + await expect(page.locator('.point')).toHaveCount(24); |
| 21 | + await expect(page.locator('.bar')).toHaveCount(2); |
| 22 | + await expect(page.locator('.home')).toHaveCount(2); |
| 23 | + }); |
| 24 | + |
| 25 | + test('toolbar shows offline game label when no opponent is loaded', async ({ page }) => { |
| 26 | + await expect(page.locator('#toolbar h2')).toHaveText('Offline Game'); |
| 27 | + }); |
| 28 | + |
| 29 | + test('pieces are present on the starting board', async ({ page }) => { |
| 30 | + const pieces = page.locator('.piece:not(.ghost)'); |
| 31 | + await expect(pieces).toHaveCount(30); |
| 32 | + }); |
| 33 | +}); |
| 34 | + |
| 35 | +test.describe('Dice', () => { |
| 36 | + test.beforeEach(async ({ page }) => { |
| 37 | + await waitForBoard(page); |
| 38 | + }); |
| 39 | + |
| 40 | + test('dice start in pulsating rolling state', async ({ page }) => { |
| 41 | + await expect(page.locator('.dice.pulsate')).toBeVisible(); |
| 42 | + }); |
| 43 | + |
| 44 | + test('rolling dice transitions from rolling to moving state', async ({ page }) => { |
| 45 | + await expect(page.locator('.dice.pulsate')).toBeVisible(); |
| 46 | + await page.locator('.dice').click(); |
| 47 | + await expect(page.locator('.dice')).not.toHaveClass(/pulsate/); |
| 48 | + }); |
| 49 | + |
| 50 | + test('rolling dice shows two die images', async ({ page }) => { |
| 51 | + await page.locator('.dice').click(); |
| 52 | + await expect(page.locator('.dice img')).toHaveCount(2); |
| 53 | + }); |
| 54 | +}); |
| 55 | + |
| 56 | +test.describe('Piece selection', () => { |
| 57 | + test.beforeEach(async ({ page }) => { |
| 58 | + await waitForBoard(page); |
| 59 | + }); |
| 60 | + |
| 61 | + test('clicking a point selects it in local mode', async ({ page }) => { |
| 62 | + const point = page.locator('.point').first(); |
| 63 | + await point.click(); |
| 64 | + await expect(point).toHaveClass(/selected/); |
| 65 | + }); |
| 66 | + |
| 67 | + test('clicking a selected point deselects it', async ({ page }) => { |
| 68 | + const point = page.locator('.point').first(); |
| 69 | + await point.click(); |
| 70 | + await expect(point).toHaveClass(/selected/); |
| 71 | + await point.click(); |
| 72 | + await expect(point).not.toHaveClass(/selected/); |
| 73 | + }); |
| 74 | + |
| 75 | + test('selecting a different point moves the selection', async ({ page }) => { |
| 76 | + const firstPoint = page.locator('.point').nth(0); |
| 77 | + const secondPoint = page.locator('.point').nth(11); |
| 78 | + await firstPoint.click(); |
| 79 | + await expect(firstPoint).toHaveClass(/selected/); |
| 80 | + await secondPoint.click(); |
| 81 | + await expect(firstPoint).not.toHaveClass(/selected/); |
| 82 | + await expect(secondPoint).toHaveClass(/selected/); |
| 83 | + }); |
| 84 | +}); |
| 85 | + |
| 86 | +test.describe('Login dialog', () => { |
| 87 | + test.beforeEach(async ({ page }) => { |
| 88 | + await waitForBoard(page); |
| 89 | + }); |
| 90 | + |
| 91 | + test('dialog is initially closed', async ({ page }) => { |
| 92 | + await expect(page.locator('dialog')).not.toBeVisible(); |
| 93 | + }); |
| 94 | + |
| 95 | + test('toolbar click opens the login dialog', async ({ page }) => { |
| 96 | + await page.locator('#toolbar').click(); |
| 97 | + await expect(page.locator('dialog[open]')).toBeVisible(); |
| 98 | + await expect(page.locator('#login')).toBeVisible(); |
| 99 | + }); |
| 100 | + |
| 101 | + test('login dialog contains a menu button and title', async ({ page }) => { |
| 102 | + await page.locator('#toolbar').click(); |
| 103 | + await expect(page.locator('#login button[aria-haspopup="menu"]')).toBeVisible(); |
| 104 | + await expect(page.locator('#login h1')).toBeVisible(); |
| 105 | + }); |
| 106 | + |
| 107 | + test('clicking outside the dialog closes it', async ({ page }) => { |
| 108 | + await page.locator('#toolbar').click(); |
| 109 | + await expect(page.locator('dialog[open]')).toBeVisible(); |
| 110 | + await page.locator('#board').click({ position: { x: 5, y: 5 }, force: true }); |
| 111 | + await expect(page.locator('dialog')).not.toBeVisible(); |
| 112 | + }); |
| 113 | +}); |
0 commit comments