Files
mahjong-web/tests/e2e/chengdu-flow.spec.ts
wsy182 84ce67b9be ```
feat(game): update websocket URL configuration and improve game room logic

- Change VITE_GAME_WS_URL from /api/v1/ws to /ws in .env.development
- Update proxy configuration in vite.config.ts to match new websocket path
- Refactor leave room functionality to properly disconnect websocket
and destroy room state
- Add e2e testing script to package.json
```
2026-03-24 14:38:47 +08:00

54 lines
1.9 KiB
TypeScript

import { expect, test } from '@playwright/test'
function uniqueUser() {
const stamp = Date.now().toString()
return {
username: `pw${stamp.slice(-8)}`,
phone: `13${stamp.slice(-9)}`,
email: `pw${stamp}@example.com`,
password: 'playwright123',
roomName: `pw-room-${stamp.slice(-6)}`,
}
}
test('register, login, create room, enter game, and back to hall', async ({ page }) => {
const user = uniqueUser()
await page.goto('/register')
const registerInputs = page.locator('.auth-card .form input')
await registerInputs.nth(0).fill(user.username)
await registerInputs.nth(1).fill(user.phone)
await registerInputs.nth(2).fill(user.email)
await registerInputs.nth(3).fill(user.password)
await registerInputs.nth(4).fill(user.password)
await page.locator('.auth-card .primary-btn[type="submit"]').click()
await page.waitForURL(/\/login/)
const loginInputs = page.locator('.auth-card .form input')
await expect(loginInputs.nth(0)).toHaveValue(user.phone)
await loginInputs.nth(1).fill(user.password)
await page.locator('.auth-card .primary-btn[type="submit"]').click()
await page.waitForURL(/\/hall/)
await expect(page.locator('.hall-page')).toBeVisible()
await page.locator('.room-actions-footer .primary-btn').click()
await expect(page.locator('.modal-card')).toBeVisible()
await page.locator('.modal-card .field input').first().fill(user.roomName)
await page.locator('.modal-card .modal-actions .primary-btn').click()
await expect(page.locator('.copy-line')).toHaveCount(2)
await page.locator('.modal-card .modal-actions .primary-btn').click()
await page.waitForURL(/\/game\/chengdu\//)
await expect(page.locator('.game-page')).toBeVisible()
await expect(page.locator('.table-felt')).toBeVisible()
await page.locator('.topbar-back-btn').click()
await page.waitForURL(/\/hall/)
await expect(page.locator('.hall-page')).toBeVisible()
})