Files
box-box/tests/visual/helpers.ts
AmanTahiliani 3c6115e815 Make Playwright runs hermetic and fix stale race-hub specs
Six suite failures had rotted in: three race-hub specs targeted the
sub-tabbed Race Story UI deleted in the Phase 22 redesign, and the
command-center specs depended on the real OpenF1 calendar, whose focus
weekend drifted away from the seeded Monaco session as time passed.

The e2e/visual configs now point BOXBOX_OPENF1_BASE_URL (new override)
at an unreachable address so runs are hermetic and date-stable; the
race-hub specs were rewritten against the current RaceStoryCanvas UI,
and the one drifted mobile snapshot regenerated.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-03 00:48:07 -04:00

66 lines
2.4 KiB
TypeScript

import { expect, type Locator, type Page } from '@playwright/test'
export const VIEWPORTS = {
desktop: { width: 1280, height: 800 },
tablet: { width: 768, height: 1024 },
mobile: { width: 390, height: 844 },
} as const
export const FULL_SESSION = 9472
/** Wait for web fonts and layout to settle before screenshots. */
export async function waitForScreenshotReady(page: Page): Promise<void> {
await page.evaluate(() => document.fonts.ready)
await page.waitForTimeout(150)
}
export async function gotoCommandCenterReady(page: Page): Promise<void> {
await page.goto('/')
await expect(page.getByTestId('command-center')).toBeVisible()
await expect(page.getByTestId('cc-focus')).toBeVisible()
await expect(page.getByTestId('cc-session-9472')).toBeVisible()
// The e2e stack runs with an unreachable OpenF1 base URL, so wait for the
// season-calendar query to settle on its local fallback before screenshotting.
await expect(
page.getByText('Using local meetings because the full calendar could not load.'),
).toBeVisible()
await waitForScreenshotReady(page)
}
export async function gotoRaceHubReady(page: Page, sessionKey = FULL_SESSION): Promise<void> {
await page.goto(`/race-hub?session_key=${sessionKey}`)
await expect(page.getByTestId('race-hub')).toBeVisible()
await expect(page.getByTestId('rh-identity')).toBeVisible()
await expect(page.getByTestId(`rh-session-${sessionKey}`)).toBeVisible()
await expect(page.getByTestId('rh-overview')).toBeVisible()
await waitForScreenshotReady(page)
}
export async function gotoDataLibraryReady(page: Page): Promise<void> {
await page.goto('/admin')
await expect(page.getByTestId('data-library')).toBeVisible()
await expect(page.getByTestId('dl-meeting-1229')).toBeVisible()
await expect(page.getByTestId('meeting-detail')).toBeVisible()
await waitForScreenshotReady(page)
}
export async function gotoLiveEmptyReady(page: Page): Promise<void> {
await page.goto('/live')
await expect(page.locator('.loading-state')).toHaveCount(0)
await expect(page.getByTestId('live-empty')).toBeVisible()
await waitForScreenshotReady(page)
}
export async function screenshotPage(
page: Page,
name: string,
options?: { mask?: Locator[] },
): Promise<void> {
await expect(page).toHaveScreenshot(`${name}.png`, {
fullPage: true,
animations: 'disabled',
caret: 'hide',
mask: options?.mask,
})
}