105 lines
3.7 KiB
TypeScript
105 lines
3.7 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|||
|
|
import { router } from './router'
|
||
|
|
|
||
|
|
const routes = router.getRoutes()
|
||
|
|
|
||
|
|
describe('router configuration', () => {
|
||
|
|
const expectedRoutes = [
|
||
|
|
{ name: 'home', path: '/' },
|
||
|
|
{ name: 'arena', path: '/arena' },
|
||
|
|
{ name: 'fight-card', path: '/fight-card' },
|
||
|
|
{ name: 'fight', path: '/arena/:fightId' },
|
||
|
|
{ name: 'leaderboard', path: '/leaderboard' },
|
||
|
|
{ name: 'bot-profile', path: '/bot/:name' },
|
||
|
|
{ name: 'human-fight', path: '/play/:fightId' },
|
||
|
|
{ name: 'register', path: '/register' },
|
||
|
|
{ name: 'join-bout', path: '/join' },
|
||
|
|
{ name: 'schedule', path: '/schedule' },
|
||
|
|
{ name: 'sprites', path: '/sprites' },
|
||
|
|
{ name: 'docs', path: '/docs' },
|
||
|
|
{ name: 'soundboard', path: '/soundboard' },
|
||
|
|
{ name: 'feed', path: '/feed' },
|
||
|
|
{ name: 'tournaments', path: '/tournaments' },
|
||
|
|
{ name: 'tournament', path: '/tournament/:id' },
|
||
|
|
{ name: 'training', path: '/training' },
|
||
|
|
{ name: 'admin', path: '/admin' },
|
||
|
|
]
|
||
|
|
|
||
|
|
it('all expected named routes exist', () => {
|
||
|
|
const routeNames = routes
|
||
|
|
.map((r) => r.name)
|
||
|
|
.filter((n): n is string => typeof n === 'string')
|
||
|
|
|
||
|
|
for (const expected of expectedRoutes) {
|
||
|
|
expect(routeNames).toContain(expected.name)
|
||
|
|
}
|
||
|
|
})
|
||
|
|
|
||
|
|
it('all expected paths are registered', () => {
|
||
|
|
const routePaths = routes.map((r) => r.path)
|
||
|
|
|
||
|
|
for (const expected of expectedRoutes) {
|
||
|
|
expect(routePaths).toContain(expected.path)
|
||
|
|
}
|
||
|
|
})
|
||
|
|
|
||
|
|
it('route names are unique', () => {
|
||
|
|
const namedRoutes = routes
|
||
|
|
.map((r) => r.name)
|
||
|
|
.filter((n): n is string => typeof n === 'string')
|
||
|
|
const unique = new Set(namedRoutes)
|
||
|
|
expect(unique.size).toBe(namedRoutes.length)
|
||
|
|
})
|
||
|
|
|
||
|
|
it('/practice redirect route exists in config', () => {
|
||
|
|
// Verify the redirect route is defined in the raw route config
|
||
|
|
// router.resolve doesn't follow redirects statically, so we check the
|
||
|
|
// route record directly
|
||
|
|
const practiceRoute = router.getRoutes().find((r) => r.path === '/practice')
|
||
|
|
expect(practiceRoute).toBeDefined()
|
||
|
|
expect(practiceRoute!.redirect).toBeDefined()
|
||
|
|
})
|
||
|
|
|
||
|
|
it('route components are lazy-loaded (functions)', () => {
|
||
|
|
for (const route of routes) {
|
||
|
|
// Skip redirect-only routes (no component)
|
||
|
|
if (!route.components?.default) continue
|
||
|
|
// Lazy-loaded components are async functions or already resolved
|
||
|
|
// The raw route config uses () => import(...), vue-router wraps these
|
||
|
|
expect(route.components.default).toBeDefined()
|
||
|
|
}
|
||
|
|
})
|
||
|
|
|
||
|
|
it('dynamic routes have expected parameters', () => {
|
||
|
|
const fightRoute = routes.find((r) => r.name === 'fight')
|
||
|
|
expect(fightRoute).toBeDefined()
|
||
|
|
expect(fightRoute!.path).toContain(':fightId')
|
||
|
|
|
||
|
|
const botProfile = routes.find((r) => r.name === 'bot-profile')
|
||
|
|
expect(botProfile).toBeDefined()
|
||
|
|
expect(botProfile!.path).toContain(':name')
|
||
|
|
|
||
|
|
const humanFight = routes.find((r) => r.name === 'human-fight')
|
||
|
|
expect(humanFight).toBeDefined()
|
||
|
|
expect(humanFight!.path).toContain(':fightId')
|
||
|
|
|
||
|
|
const tournament = routes.find((r) => r.name === 'tournament')
|
||
|
|
expect(tournament).toBeDefined()
|
||
|
|
expect(tournament!.path).toContain(':id')
|
||
|
|
})
|
||
|
|
|
||
|
|
it('unknown paths do not match any named route', () => {
|
||
|
|
const resolved = router.resolve('/nonexistent-path')
|
||
|
|
// vue-router resolves unknown paths with matched length 0
|
||
|
|
expect(resolved.matched.length).toBe(0)
|
||
|
|
})
|
||
|
|
|
||
|
|
it('router has web history mode', () => {
|
||
|
|
// createWebHistory produces history with no base hash prefix
|
||
|
|
// We verify by checking the router instance exists and resolves properly
|
||
|
|
const resolved = router.resolve('/')
|
||
|
|
expect(resolved.path).toBe('/')
|
||
|
|
expect(resolved.name).toBe('home')
|
||
|
|
})
|
||
|
|
})
|