mirror of
https://github.com/AmanTahiliani/box-box.git
synced 2026-08-07 11:54:59 -04:00
fix(#98): expose weekend switcher before sessions
This commit is contained in:
@@ -47,7 +47,7 @@ export function WeekendSwitcher({ currentMeetingKey, currentSessionKey, onClose
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="rh-switcher" data-testid="rh-switcher">
|
||||
<div id="rh-weekend-switcher" className="rh-switcher" data-testid="rh-switcher">
|
||||
<div className="rh-switcher-head">
|
||||
<span className="sec-title">Switch Weekend</span>
|
||||
<div className="rh-switcher-years">
|
||||
|
||||
@@ -102,7 +102,16 @@ export function RaceHubPage({ sessionKey }: Props) {
|
||||
)
|
||||
}
|
||||
if (preSession && preSessionRef) {
|
||||
return <RaceHubPreSession session={preSessionRef} weekend={preSessionWeekendQuery.data} now={now} />
|
||||
return (
|
||||
<RaceHubPreSession
|
||||
session={preSessionRef}
|
||||
weekend={preSessionWeekendQuery.data}
|
||||
now={now}
|
||||
switcherOpen={switcherOpen}
|
||||
onToggleSwitcher={() => setSwitcherOpen((open) => !open)}
|
||||
onCloseSwitcher={() => setSwitcherOpen(false)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
if (!selectedSessionKey) {
|
||||
return (
|
||||
@@ -350,7 +359,21 @@ export function RaceHubPage({ sessionKey }: Props) {
|
||||
)
|
||||
}
|
||||
|
||||
function RaceHubPreSession({ session, weekend, now }: { session: ContextSession; weekend?: Weekend; now: number }) {
|
||||
function RaceHubPreSession({
|
||||
session,
|
||||
weekend,
|
||||
now,
|
||||
switcherOpen,
|
||||
onToggleSwitcher,
|
||||
onCloseSwitcher,
|
||||
}: {
|
||||
session: ContextSession
|
||||
weekend?: Weekend
|
||||
now: number
|
||||
switcherOpen: boolean
|
||||
onToggleSwitcher: () => void
|
||||
onCloseSwitcher: () => void
|
||||
}) {
|
||||
const meeting = session.meeting
|
||||
const sessions = sortSessionsByStart((weekend?.sessions ?? []).map((entry) => entry.session))
|
||||
const target = new Date(session.session.date_start)
|
||||
@@ -359,6 +382,29 @@ function RaceHubPreSession({ session, weekend, now }: { session: ContextSession;
|
||||
|
||||
return (
|
||||
<div className="rh-page rh-empty" data-testid="race-hub-pre-session" style={{ '--gp-accent': accent } as React.CSSProperties}>
|
||||
<div className="rh-topbar">
|
||||
<span className="rh-topbar-label mono">box-box · race hub</span>
|
||||
<span className="rh-topbar-spacer" />
|
||||
<button
|
||||
type="button"
|
||||
className={`rh-switcher-toggle${switcherOpen ? ' active' : ''}`}
|
||||
onClick={onToggleSwitcher}
|
||||
aria-expanded={switcherOpen}
|
||||
aria-controls="rh-weekend-switcher"
|
||||
data-testid="rh-switch-weekend"
|
||||
>
|
||||
{switcherOpen ? 'Close' : 'Switch Weekend'}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{switcherOpen && (
|
||||
<WeekendSwitcher
|
||||
currentMeetingKey={meeting?.meeting_key}
|
||||
currentSessionKey={session.session.session_key}
|
||||
onClose={onCloseSwitcher}
|
||||
/>
|
||||
)}
|
||||
|
||||
<section className="rh-empty-band">
|
||||
<span className="rh-empty-eyebrow mono">box-box · race hub</span>
|
||||
<h1 className="rh-empty-title">{meeting?.meeting_name ?? 'Next race weekend'}</h1>
|
||||
|
||||
@@ -311,6 +311,30 @@ describe('RaceHubPage', () => {
|
||||
expect(mockFetchRaceHub).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('opens the weekend switcher from pre-session and navigates to the selected explicit session', async () => {
|
||||
mockFetchWeekendContext.mockResolvedValue({
|
||||
...analysisContext,
|
||||
race_hub_default_session: {
|
||||
session: { ...raceSession, session_key: 9473, session_name: 'Practice 1', session_type: 'Practice', date_start: '2099-05-23T13:00:00Z' },
|
||||
meeting,
|
||||
availability,
|
||||
},
|
||||
race_hub_pre_session: true,
|
||||
race_hub_refresh_at: '2099-05-23T13:00:00Z',
|
||||
})
|
||||
|
||||
renderRaceHub(0)
|
||||
|
||||
const switchWeekend = await screen.findByTestId('rh-switch-weekend')
|
||||
expect(switchWeekend).toHaveAttribute('aria-expanded', 'false')
|
||||
fireEvent.click(switchWeekend)
|
||||
expect(await screen.findByTestId('rh-switcher')).toBeInTheDocument()
|
||||
expect(switchWeekend).toHaveAttribute('aria-expanded', 'true')
|
||||
|
||||
fireEvent.click(await screen.findByTestId('rh-switcher-session-9471'))
|
||||
await waitFor(() => expect(window.location.search).toBe('?session_key=9471'))
|
||||
})
|
||||
|
||||
it('shows recovery instead of selecting an empty future session', async () => {
|
||||
mockFetchWeekendContext.mockResolvedValue({
|
||||
...analysisContext,
|
||||
|
||||
Reference in New Issue
Block a user