mirror of
https://github.com/AmanTahiliani/box-box.git
synced 2026-08-08 12:07:23 -04:00
Rework Race Hub as weekend workspace
This commit is contained in:
@@ -1,55 +1,90 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import { render, screen, waitFor } from '@testing-library/react'
|
||||
import { RouterProvider, createRouter, createRootRoute, createRoute } from '@tanstack/react-router'
|
||||
import { DatasetStatusView } from '../components/DatasetStatusView'
|
||||
import type { DatasetInfo } from '../types'
|
||||
|
||||
const allAvailable: Record<string, DatasetInfo> = {
|
||||
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: 30 },
|
||||
pit_stops: { status: 'available', source: 'local', count: 18 },
|
||||
positions: { status: 'available', source: 'local', count: 120 },
|
||||
race_control: { status: 'available', source: 'local', count: 5 },
|
||||
weather: { status: 'available', source: 'local', count: 4 },
|
||||
laps: { status: 'available', source: 'local', count: 200 },
|
||||
}
|
||||
|
||||
const partial: Record<string, DatasetInfo> = {
|
||||
const coreOnly: Record<string, DatasetInfo> = {
|
||||
meeting: { status: 'available', source: 'local', count: 1 },
|
||||
session: { status: 'available', source: 'local', count: 1 },
|
||||
drivers: { status: 'missing', source: 'none' },
|
||||
results: { status: 'missing', source: 'none' },
|
||||
starting_grid: { status: 'missing', source: 'none' },
|
||||
drivers: { status: 'available', source: 'local', count: 20 },
|
||||
results: { status: 'available', source: 'local', count: 20 },
|
||||
starting_grid: { status: 'available', source: 'local', count: 20 },
|
||||
stints: { status: 'missing', source: 'none' },
|
||||
pit_stops: { status: 'missing', source: 'none' },
|
||||
positions: { status: 'missing', source: 'none' },
|
||||
race_control: { status: 'missing', source: 'none' },
|
||||
weather: { status: 'missing', source: 'none' },
|
||||
laps: { status: 'missing', source: 'none' },
|
||||
}
|
||||
|
||||
function renderView(datasets: Record<string, DatasetInfo>) {
|
||||
const rootRoute = createRootRoute({
|
||||
component: () => <DatasetStatusView datasets={datasets} />,
|
||||
})
|
||||
const indexRoute = createRoute({
|
||||
getParentRoute: () => rootRoute,
|
||||
path: '/',
|
||||
component: () => null,
|
||||
})
|
||||
const router = createRouter({ routeTree: rootRoute.addChildren([indexRoute]) })
|
||||
return render(<RouterProvider router={router} />)
|
||||
}
|
||||
|
||||
describe('DatasetStatusView', () => {
|
||||
it('shows 5/5 when all available', () => {
|
||||
render(<DatasetStatusView datasets={allAvailable} />)
|
||||
expect(screen.getByText(/5\/5/)).toBeInTheDocument()
|
||||
it('shows 11/11 when all datasets are available', async () => {
|
||||
renderView(fullDatasets)
|
||||
await waitFor(() =>
|
||||
expect(screen.getByText(/11\/11 datasets local/)).toBeInTheDocument(),
|
||||
)
|
||||
})
|
||||
|
||||
it('shows local badges for available datasets', () => {
|
||||
render(<DatasetStatusView datasets={allAvailable} />)
|
||||
const localBadges = screen.getAllByText('Local')
|
||||
expect(localBadges).toHaveLength(5)
|
||||
it('shows a Local badge for every available dataset', async () => {
|
||||
renderView(fullDatasets)
|
||||
await waitFor(() => expect(screen.getAllByText('Local')).toHaveLength(11))
|
||||
})
|
||||
|
||||
it('shows missing badges for missing datasets', () => {
|
||||
render(<DatasetStatusView datasets={partial} />)
|
||||
const missingBadges = screen.getAllByText('Missing')
|
||||
expect(missingBadges).toHaveLength(3)
|
||||
it('shows Missing badges for missing datasets', async () => {
|
||||
renderView(coreOnly)
|
||||
await waitFor(() => expect(screen.getAllByText('Missing')).toHaveLength(6))
|
||||
})
|
||||
|
||||
it('shows the ingest command when data is missing', () => {
|
||||
render(<DatasetStatusView datasets={partial} />)
|
||||
expect(screen.getByText(/ingest-session/i)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('does not show ingest command when all available', () => {
|
||||
render(<DatasetStatusView datasets={allAvailable} />)
|
||||
it('links to admin when datasets are missing instead of inlining CLI commands', async () => {
|
||||
renderView(coreOnly)
|
||||
await waitFor(() => {
|
||||
expect(screen.getByRole('link', { name: /manage ingestion/i })).toHaveAttribute(
|
||||
'href',
|
||||
'/admin',
|
||||
)
|
||||
})
|
||||
expect(screen.queryByText(/ingest-session/i)).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows record counts', () => {
|
||||
render(<DatasetStatusView datasets={allAvailable} />)
|
||||
const twenties = screen.getAllByText('20')
|
||||
expect(twenties.length).toBeGreaterThan(0)
|
||||
it('does not surface ingest hints when fully covered', async () => {
|
||||
renderView(fullDatasets)
|
||||
await waitFor(() => expect(screen.getByText(/11\/11/)).toBeInTheDocument())
|
||||
expect(screen.queryByText(/manage ingestion/i)).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders record counts from the dataset payload', async () => {
|
||||
renderView(fullDatasets)
|
||||
await waitFor(() => {
|
||||
const twenties = screen.getAllByText('20')
|
||||
expect(twenties.length).toBeGreaterThan(0)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user