mirror of
https://github.com/AmanTahiliani/box-box.git
synced 2026-08-07 19:56:18 -04:00
Expand React race hub analytics
This commit is contained in:
35
frontend/src/test/TabBar.test.tsx
Normal file
35
frontend/src/test/TabBar.test.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
import { render, screen, fireEvent } from '@testing-library/react'
|
||||
import { TabBar } from '../components/TabBar'
|
||||
|
||||
describe('TabBar', () => {
|
||||
it('renders all 5 tabs', () => {
|
||||
render(<TabBar active="results" onChange={() => {}} />)
|
||||
expect(screen.getByRole('tab', { name: 'Results' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('tab', { name: 'Grid' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('tab', { name: 'Strategy' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('tab', { name: 'Positions' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('tab', { name: 'Datasets' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('marks the active tab with aria-selected', () => {
|
||||
render(<TabBar active="grid" onChange={() => {}} />)
|
||||
expect(screen.getByRole('tab', { name: 'Grid' })).toHaveAttribute('aria-selected', 'true')
|
||||
expect(screen.getByRole('tab', { name: 'Results' })).toHaveAttribute('aria-selected', 'false')
|
||||
})
|
||||
|
||||
it('applies active class only to the active tab', () => {
|
||||
render(<TabBar active="strategy" onChange={() => {}} />)
|
||||
const strategy = screen.getByRole('tab', { name: 'Strategy' })
|
||||
const results = screen.getByRole('tab', { name: 'Results' })
|
||||
expect(strategy.className).toContain('active')
|
||||
expect(results.className).not.toContain('active')
|
||||
})
|
||||
|
||||
it('calls onChange with the correct tab id when clicked', () => {
|
||||
const onChange = vi.fn()
|
||||
render(<TabBar active="results" onChange={onChange} />)
|
||||
fireEvent.click(screen.getByRole('tab', { name: 'Datasets' }))
|
||||
expect(onChange).toHaveBeenCalledWith('datasets')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user