Files
botfights/e2e/navigation.spec.ts
T
2026-04-11 19:46:37 +01:00

94 lines
3.0 KiB
TypeScript

import { test, expect } from '@playwright/test'
test.describe('page navigation — all routes load without crashes', () => {
const routes = [
{ path: '/', name: 'homepage' },
{ path: '/arena', name: 'arena' },
{ path: '/fight-card', name: 'fight card' },
{ path: '/leaderboard', name: 'leaderboard' },
{ path: '/training', name: 'practice/training' },
{ path: '/feed', name: 'feed' },
{ path: '/sprites', name: 'sprite preview' },
{ path: '/docs', name: 'docs' },
{ path: '/tournaments', name: 'tournaments' },
{ path: '/join', name: 'join bout' },
{ path: '/register', name: 'register' },
{ path: '/schedule', name: 'schedule' },
]
for (const route of routes) {
test(`${route.name} (${route.path}) loads without JS crashes`, async ({ page }) => {
const criticalErrors: string[] = []
page.on('pageerror', err => {
const msg = err.message
if (msg.includes('TypeError') || msg.includes('ReferenceError') || msg.includes('SyntaxError')) {
criticalErrors.push(msg)
}
})
await page.goto(route.path)
await page.waitForTimeout(1500)
expect(criticalErrors).toHaveLength(0)
})
}
})
test.describe('navigation flow', () => {
test('can navigate from homepage to leaderboard via nav', async ({ page }) => {
await page.goto('/')
await page.waitForTimeout(500)
// Click leaderboard link in nav or body
const leaderboardLink = page.getByRole('link', { name: /leaderboard|rankings/i }).first()
if (await leaderboardLink.isVisible()) {
await leaderboardLink.click()
await expect(page).toHaveURL(/leaderboard/)
}
})
test('can navigate from homepage to arena', async ({ page }) => {
await page.goto('/')
await page.waitForTimeout(500)
const arenaLink = page.getByRole('link', { name: /arena|watch|fights/i }).first()
if (await arenaLink.isVisible()) {
await arenaLink.click()
await expect(page).toHaveURL(/arena/)
}
})
test('/practice redirects to /training', async ({ page }) => {
await page.goto('/practice')
await expect(page).toHaveURL(/training/)
})
})
test.describe('error handling', () => {
test('bot profile with unknown name shows error state', async ({ page }) => {
const criticalErrors: string[] = []
page.on('pageerror', err => {
if (err.message.includes('ReferenceError') || err.message.includes('SyntaxError')) {
criticalErrors.push(err.message)
}
})
await page.goto('/bot/nonexistent-bot-name-12345')
await page.waitForTimeout(2000)
expect(criticalErrors).toHaveLength(0)
})
test('tournament with unknown ID shows error state', async ({ page }) => {
const criticalErrors: string[] = []
page.on('pageerror', err => {
if (err.message.includes('ReferenceError') || err.message.includes('SyntaxError')) {
criticalErrors.push(err.message)
}
})
await page.goto('/tournament/nonexistent-id')
await page.waitForTimeout(2000)
expect(criticalErrors).toHaveLength(0)
})
})