2026-05-25 10:29:31 -04:00
|
|
|
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
|
|
|
import { render, screen, waitFor } from '@testing-library/react'
|
|
|
|
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
|
|
|
import { RouterProvider, createRouter, createRootRoute, createRoute } from '@tanstack/react-router'
|
|
|
|
|
import { CommandCenterPage } from '../pages/CommandCenterPage'
|
|
|
|
|
import type { DatasetInfo, Meeting, Weekend } from '../types'
|
|
|
|
|
|
|
|
|
|
vi.mock('../api', () => ({
|
|
|
|
|
fetchSeasons: vi.fn(),
|
|
|
|
|
fetchLocalMeetings: vi.fn(),
|
|
|
|
|
fetchWeekend: vi.fn(),
|
|
|
|
|
fetchLiveState: vi.fn(),
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
import { fetchSeasons, fetchLocalMeetings, fetchWeekend, fetchLiveState } from '../api'
|
|
|
|
|
|
|
|
|
|
const mockFetchSeasons = vi.mocked(fetchSeasons)
|
|
|
|
|
const mockFetchLocalMeetings = vi.mocked(fetchLocalMeetings)
|
|
|
|
|
const mockFetchWeekend = vi.mocked(fetchWeekend)
|
|
|
|
|
const mockFetchLiveState = vi.mocked(fetchLiveState)
|
|
|
|
|
|
|
|
|
|
const meeting: Meeting = {
|
|
|
|
|
meeting_key: 1229,
|
|
|
|
|
meeting_name: 'Monaco',
|
|
|
|
|
meeting_official_name: 'FORMULA 1 GRAND PRIX DE MONACO 2025',
|
|
|
|
|
location: 'Monaco',
|
|
|
|
|
country_name: 'Monaco',
|
|
|
|
|
country_code: 'MON',
|
|
|
|
|
country_flag: '',
|
|
|
|
|
circuit_short_name: 'Monaco',
|
|
|
|
|
date_start: '2025-05-23T00:00:00+00:00',
|
|
|
|
|
date_end: '2025-05-25T00:00:00+00:00',
|
|
|
|
|
year: 2025,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const fullDatasets: Record<string, DatasetInfo> = {
|
|
|
|
|
meeting: { status: 'available', source: 'local', count: 1 },
|
|
|
|
|
session: { status: 'available', source: 'local', count: 1 },
|
|
|
|
|
drivers: { status: 'available', source: 'local', count: 20 },
|
|
|
|
|
results: { status: 'available', source: 'local', count: 20 },
|
|
|
|
|
starting_grid: { status: 'available', source: 'local', count: 20 },
|
|
|
|
|
stints: { status: 'available', source: 'local', count: 2 },
|
|
|
|
|
pit_stops: { status: 'available', source: 'local', count: 1 },
|
|
|
|
|
positions: { status: 'available', source: 'local', count: 3 },
|
|
|
|
|
race_control: { status: 'available', source: 'local', count: 1 },
|
|
|
|
|
weather: { status: 'available', source: 'local', count: 1 },
|
|
|
|
|
laps: { status: 'available', source: 'local', count: 1 },
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const weekend: Weekend = {
|
|
|
|
|
source: 'local',
|
|
|
|
|
meeting_key: 1229,
|
|
|
|
|
meeting,
|
|
|
|
|
default_session_key: 9472,
|
|
|
|
|
sessions: [
|
|
|
|
|
{
|
|
|
|
|
session: {
|
|
|
|
|
session_key: 9472,
|
|
|
|
|
session_name: 'Race',
|
|
|
|
|
session_type: 'Race',
|
|
|
|
|
meeting_key: 1229,
|
|
|
|
|
date_start: '2025-05-25T13:00:00+00:00',
|
|
|
|
|
date_end: '2025-05-25T15:00:00+00:00',
|
|
|
|
|
gmt_offset: '02:00:00',
|
|
|
|
|
},
|
|
|
|
|
source: 'local',
|
|
|
|
|
datasets: fullDatasets,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderPage() {
|
|
|
|
|
const queryClient = new QueryClient({
|
|
|
|
|
defaultOptions: { queries: { retry: false } },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const rootRoute = createRootRoute({
|
|
|
|
|
component: () => (
|
|
|
|
|
<QueryClientProvider client={queryClient}>
|
|
|
|
|
<CommandCenterPage />
|
|
|
|
|
</QueryClientProvider>
|
|
|
|
|
),
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const indexRoute = createRoute({
|
|
|
|
|
getParentRoute: () => rootRoute,
|
|
|
|
|
path: '/',
|
|
|
|
|
component: CommandCenterPage,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const router = createRouter({ routeTree: rootRoute.addChildren([indexRoute]) })
|
|
|
|
|
|
|
|
|
|
return render(<RouterProvider router={router} />)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
describe('CommandCenterPage', () => {
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
vi.clearAllMocks()
|
|
|
|
|
mockFetchLiveState.mockResolvedValue({ is_live: false, data: null })
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('shows empty state when no seasons are ingested', async () => {
|
|
|
|
|
mockFetchSeasons.mockResolvedValue([])
|
|
|
|
|
|
|
|
|
|
renderPage()
|
|
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
|
expect(screen.getByTestId('command-center-empty')).toBeInTheDocument()
|
|
|
|
|
})
|
2026-05-25 11:51:16 -04:00
|
|
|
expect(screen.getByText('No local data yet')).toBeInTheDocument()
|
2026-05-25 10:29:31 -04:00
|
|
|
})
|
|
|
|
|
|
2026-05-25 11:51:16 -04:00
|
|
|
it('shows weekend identity band and schedule when data exists', async () => {
|
2026-05-25 10:29:31 -04:00
|
|
|
mockFetchSeasons.mockResolvedValue([2025])
|
|
|
|
|
mockFetchLocalMeetings.mockResolvedValue([meeting])
|
|
|
|
|
mockFetchWeekend.mockResolvedValue(weekend)
|
|
|
|
|
|
|
|
|
|
renderPage()
|
|
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
|
expect(screen.getByTestId('command-center')).toBeInTheDocument()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
|
expect(screen.getByTestId('cc-session-9472')).toBeInTheDocument()
|
|
|
|
|
})
|
|
|
|
|
expect(screen.getByTestId('cc-focus')).toHaveTextContent('Monaco')
|
2026-05-25 11:51:16 -04:00
|
|
|
expect(screen.getByTestId('cc-focus')).toHaveTextContent('MON')
|
2026-05-25 10:29:31 -04:00
|
|
|
expect(screen.getByText('No live session')).toBeInTheDocument()
|
2026-05-25 11:51:16 -04:00
|
|
|
expect(screen.getByTestId('cc-action-race-hub')).toHaveTextContent('Race')
|
2026-05-25 10:29:31 -04:00
|
|
|
})
|
|
|
|
|
})
|