import { beforeEach, afterEach, expect, it, vi } from 'vitest'; import { render } from 'svelte/server'; import { writable, type Writable } from 'svelte/store'; import { page } from '$app/stores'; import MatchHistory from '../../src/lib/ui/components/MatchHistory.svelte'; import MatchHistoryPage from '../../src/routes/matches/+page.svelte'; import { matchStartedLabel, matchInstanceLabel } from '../../src/lib/ui/match-history.js'; import type { MatchHistoryResponse, ServerMatch } from '../../src/lib/match-history.js'; vi.mock('$app/stores', () => ({ page: writable({ url: new URL('http://localhost/matches') }) })); vi.mock('$app/navigation', () => ({ goto: vi.fn() })); const match: ServerMatch = { id: 1, server: 't6_zombie_town_1', game: 't6', map: 'Town Survival', observedRound: 20, finalRound: 20, status: 'completed', startedAt: '2026-10-06T17:26:00Z', endedAt: '2026-10-06T18:04:00Z', durationMs: 2280000, startPlayers: 2, uniquePlayers: 4, endPlayers: 2 }; const report = (): MatchHistoryResponse => ({ matches: [match], total: 40, page: 1, limit: 25, maps: [{ key: 't6:town', game: 't6', name: 'Town Survival' }] }); function scope(search = '') { (page as unknown as Writable<{ url: URL }>).set({ url: new URL(`http://localhost/matches${search}`) }); } beforeEach(() => { scope(); vi.useFakeTimers(); vi.setSystemTime(new Date('2026-10-06T20:00:00Z')); }); afterEach(() => vi.useRealTimers()); it('renders one page heading, six columns, a combined identity, and compact dates', () => { const body = render(MatchHistoryPage, { props: { data: { history: report(), user: null, setupRequired: false } } }).body; expect(body.match(/