2026-05-25 01:20:04 -04:00
|
|
|
import { describe, it, expect, vi } from 'vitest'
|
|
|
|
|
import { render, screen, fireEvent } from '@testing-library/react'
|
|
|
|
|
import { TabBar } from '../components/TabBar'
|
|
|
|
|
|
|
|
|
|
describe('TabBar', () => {
|
2026-05-25 12:35:08 -04:00
|
|
|
it('renders all Race Hub workspace tabs', () => {
|
|
|
|
|
render(<TabBar active="overview" onChange={() => {}} />)
|
|
|
|
|
expect(screen.getByRole('tab', { name: 'Overview' })).toBeInTheDocument()
|
|
|
|
|
expect(screen.getByRole('tab', { name: 'Race Story' })).toBeInTheDocument()
|
2026-05-25 01:20:04 -04:00
|
|
|
expect(screen.getByRole('tab', { name: 'Strategy' })).toBeInTheDocument()
|
2026-05-25 12:35:08 -04:00
|
|
|
expect(screen.getByRole('tab', { name: 'Lap Data' })).toBeInTheDocument()
|
|
|
|
|
expect(screen.getByRole('tab', { name: 'Conditions' })).toBeInTheDocument()
|
2026-05-25 02:56:06 -04:00
|
|
|
expect(screen.getByRole('tab', { name: 'Race Control' })).toBeInTheDocument()
|
2026-05-25 12:35:08 -04:00
|
|
|
expect(screen.getByRole('tab', { name: 'Data Status' })).toBeInTheDocument()
|
2026-05-25 01:20:04 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('marks the active tab with aria-selected', () => {
|
2026-05-25 12:35:08 -04:00
|
|
|
render(<TabBar active="strategy" onChange={() => {}} />)
|
|
|
|
|
expect(screen.getByRole('tab', { name: 'Strategy' })).toHaveAttribute('aria-selected', 'true')
|
|
|
|
|
expect(screen.getByRole('tab', { name: 'Overview' })).toHaveAttribute('aria-selected', 'false')
|
2026-05-25 01:20:04 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('applies active class only to the active tab', () => {
|
2026-05-25 12:35:08 -04:00
|
|
|
render(<TabBar active="conditions" onChange={() => {}} />)
|
|
|
|
|
const active = screen.getByRole('tab', { name: 'Conditions' })
|
|
|
|
|
const inactive = screen.getByRole('tab', { name: 'Overview' })
|
|
|
|
|
expect(active.className).toContain('active')
|
|
|
|
|
expect(inactive.className).not.toContain('active')
|
2026-05-25 01:20:04 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('calls onChange with the correct tab id when clicked', () => {
|
|
|
|
|
const onChange = vi.fn()
|
2026-05-25 12:35:08 -04:00
|
|
|
render(<TabBar active="overview" onChange={onChange} />)
|
2026-05-25 02:56:06 -04:00
|
|
|
fireEvent.click(screen.getByRole('tab', { name: 'Race Control' }))
|
|
|
|
|
expect(onChange).toHaveBeenCalledWith('race_control')
|
2026-05-25 01:20:04 -04:00
|
|
|
})
|
|
|
|
|
})
|