mirror of
https://github.com/AmanTahiliani/box-box.git
synced 2026-08-08 04:06:18 -04:00
feat(frontend): annotate key numbers with meaning (#18)
Add shared Meaning primitive and pure interpretation helpers for interval, tyre age, and championship gap columns on the live tower, tyre deg panel, and championship hub. Thresholds are exported consts (undercut window tied to PIT_LOSS_SECONDS from #13). Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -112,6 +112,7 @@ describe('ChampionshipPage', () => {
|
||||
expect(screen.getAllByText('VER').length).toBeGreaterThan(0)
|
||||
expect(screen.getByText('Monaco GP', { exact: false })).toBeInTheDocument()
|
||||
expect(screen.getByTestId('champ-titlemath')).toHaveTextContent('mathematically win the title')
|
||||
expect(screen.getAllByText('~10 pts/round').length).toBeGreaterThan(0)
|
||||
})
|
||||
|
||||
it('switches to constructors and progression views', async () => {
|
||||
|
||||
@@ -189,6 +189,26 @@ describe('TimingTower', () => {
|
||||
expect(screen.getByText(/no driver timing rows/i)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('annotates DRS-range intervals in race mode', () => {
|
||||
const raceRows = [
|
||||
makeRow('1', 1, 'VER'),
|
||||
makeRow('4', 2, 'NOR', { Interval: '+0.4', GapToLeader: '+0.4' }),
|
||||
]
|
||||
render(
|
||||
<TimingTower
|
||||
rows={raceRows}
|
||||
session={{
|
||||
MeetingName: 'Monaco Grand Prix',
|
||||
CircuitName: 'Monaco',
|
||||
SessionType: 'Race',
|
||||
SessionName: 'Race',
|
||||
Path: '',
|
||||
}}
|
||||
/>,
|
||||
)
|
||||
expect(screen.getByText('DRS range')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders the SQ1 cutoff after P17 and marks rows below as at risk', () => {
|
||||
const sprintRows = Array.from({ length: 22 }, (_, index) =>
|
||||
makeRow(String(index + 1), index + 1, `D${index + 1}`),
|
||||
|
||||
26
frontend/src/test/Meaning.test.tsx
Normal file
26
frontend/src/test/Meaning.test.tsx
Normal file
@@ -0,0 +1,26 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import { Meaning } from '../components/Meaning'
|
||||
|
||||
describe('Meaning', () => {
|
||||
it('renders bare value when meaning is null', () => {
|
||||
render(<Meaning value="+1.234" meaning={null} />)
|
||||
expect(screen.getByText('+1.234')).toBeInTheDocument()
|
||||
expect(screen.queryByText('DRS range')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders value with caption and tooltip title', () => {
|
||||
render(
|
||||
<Meaning
|
||||
value="+0.4"
|
||||
meaning="DRS range"
|
||||
title="Within 1.0s — DRS enabled next straight"
|
||||
tone="good"
|
||||
/>,
|
||||
)
|
||||
const value = screen.getByText('+0.4')
|
||||
expect(value).toBeInTheDocument()
|
||||
expect(screen.getByText('DRS range')).toHaveClass('meaning-caption--good')
|
||||
expect(value.closest('.meaning')).toHaveAttribute('title', 'Within 1.0s — DRS enabled next straight')
|
||||
})
|
||||
})
|
||||
@@ -52,9 +52,18 @@ describe('TyreDegPanel', () => {
|
||||
const panel = screen.getByTestId('tyredeg-panel')
|
||||
expect(panel).toHaveTextContent('VER')
|
||||
expect(panel).toHaveTextContent('M +5')
|
||||
expect(panel).toHaveTextContent('fresh')
|
||||
expect(panel).toHaveTextContent('warming up')
|
||||
})
|
||||
|
||||
it('annotates tyre age meaning on stint rows', () => {
|
||||
const rows = [
|
||||
makeRow('1', 1, 'VER', { NumberOfLaps: 10, LastLapTime: '1:30.000' }, { Compound: 'MEDIUM', Age: 12 }),
|
||||
]
|
||||
render(<TyreDegPanel rows={rows} sessionType="Race" pinned={[]} />)
|
||||
expect(screen.getByText('mid-life')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders slope and rejoin estimate once laps accumulate across snapshots', () => {
|
||||
const { rerender } = render(
|
||||
<TyreDegPanel rows={snapshotRows(1, '1:30.000')} sessionType="Race" pinned={[]} />,
|
||||
|
||||
71
frontend/src/test/meaning.test.ts
Normal file
71
frontend/src/test/meaning.test.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
INTERVAL_DRS_MAX_SECONDS,
|
||||
INTERVAL_UNDERCUT_MAX_SECONDS,
|
||||
INTERVAL_UNDERCUT_MIN_SECONDS,
|
||||
MAX_POINTS_PER_ROUND,
|
||||
TYRE_CLIFF_LAPS,
|
||||
intervalMeaning,
|
||||
pointsGapMeaning,
|
||||
tyreAgeMeaning,
|
||||
} from '../lib/meaning'
|
||||
|
||||
describe('intervalMeaning', () => {
|
||||
it('returns DRS range below the threshold', () => {
|
||||
expect(intervalMeaning(0.4)?.caption).toBe('DRS range')
|
||||
expect(intervalMeaning(INTERVAL_DRS_MAX_SECONDS - 0.01)?.caption).toBe('DRS range')
|
||||
})
|
||||
|
||||
it('returns undercut window in the middle band', () => {
|
||||
expect(intervalMeaning(INTERVAL_UNDERCUT_MIN_SECONDS)?.caption).toBe('undercut window')
|
||||
expect(intervalMeaning(2.0)?.caption).toBe('undercut window')
|
||||
expect(intervalMeaning(INTERVAL_UNDERCUT_MAX_SECONDS)?.caption).toBe('undercut window')
|
||||
})
|
||||
|
||||
it('returns null outside known bands', () => {
|
||||
expect(intervalMeaning(INTERVAL_UNDERCUT_MAX_SECONDS + 0.5)).toBeNull()
|
||||
expect(intervalMeaning(10)).toBeNull()
|
||||
expect(intervalMeaning(null)).toBeNull()
|
||||
expect(intervalMeaning(undefined)).toBeNull()
|
||||
expect(intervalMeaning(-1)).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('tyreAgeMeaning', () => {
|
||||
it('labels fresh, mid-life, and laps-to-cliff for SOFT', () => {
|
||||
const cliff = TYRE_CLIFF_LAPS.SOFT
|
||||
expect(tyreAgeMeaning('SOFT', 2)?.caption).toBe('fresh')
|
||||
expect(tyreAgeMeaning('SOFT', Math.ceil(cliff * 0.5))?.caption).toBe('mid-life')
|
||||
expect(tyreAgeMeaning('SOFT', cliff - 2)?.caption).toBe('~2 laps to cliff')
|
||||
expect(tyreAgeMeaning('SOFT', cliff + 5)?.caption).toBe('past cliff')
|
||||
})
|
||||
|
||||
it('handles unknown compounds with defaults', () => {
|
||||
expect(tyreAgeMeaning('UNKNOWN', 3)?.caption).toBe('fresh')
|
||||
expect(tyreAgeMeaning(undefined, 3)?.caption).toBe('fresh')
|
||||
})
|
||||
|
||||
it('returns null for invalid age', () => {
|
||||
expect(tyreAgeMeaning('MEDIUM', null)).toBeNull()
|
||||
expect(tyreAgeMeaning('MEDIUM', -1)).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('pointsGapMeaning', () => {
|
||||
it('computes catchable pts/round', () => {
|
||||
const result = pointsGapMeaning(40, 4, 'VER')
|
||||
expect(result?.caption).toBe('~10 pts/round')
|
||||
expect(result?.title).toContain('VER')
|
||||
})
|
||||
|
||||
it('marks uncatchable gaps', () => {
|
||||
const max = 3 * MAX_POINTS_PER_ROUND
|
||||
expect(pointsGapMeaning(max + 1, 3, 'VER')?.caption).toBe('out of reach')
|
||||
})
|
||||
|
||||
it('returns null for leader or invalid input', () => {
|
||||
expect(pointsGapMeaning(0, 4)).toBeNull()
|
||||
expect(pointsGapMeaning(10, 0)).toBeNull()
|
||||
expect(pointsGapMeaning(null, 4)).toBeNull()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user