File size: 1,683 Bytes
0c591a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { describe, it, expect, vi } from 'vitest'
import { render, screen, fireEvent } from '@testing-library/react'
import { ViewModeToggle } from './ViewModeToggle'

describe('ViewModeToggle', () => {
  it('renders Executive and Full buttons', () => {
    const onChange = vi.fn()
    render(<ViewModeToggle value="executive" onChange={onChange} />)

    expect(screen.getByRole('button', { name: 'Executive' })).toBeInTheDocument()
    expect(screen.getByRole('button', { name: 'Full' })).toBeInTheDocument()
  })

  it('highlights the selected mode', () => {
    const onChange = vi.fn()
    const { rerender } = render(<ViewModeToggle value="executive" onChange={onChange} />)

    const executiveBtn = screen.getByRole('button', { name: 'Executive' })
    const fullBtn = screen.getByRole('button', { name: 'Full' })

    expect(executiveBtn).toHaveClass('bg-primary')
    expect(fullBtn).not.toHaveClass('bg-primary')

    rerender(<ViewModeToggle value="full" onChange={onChange} />)

    expect(executiveBtn).not.toHaveClass('bg-primary')
    expect(fullBtn).toHaveClass('bg-primary')
  })

  it('calls onChange when clicking a different mode', () => {
    const onChange = vi.fn()
    render(<ViewModeToggle value="executive" onChange={onChange} />)

    fireEvent.click(screen.getByRole('button', { name: 'Full' }))

    expect(onChange).toHaveBeenCalledWith('full')
  })

  it('calls onChange with executive when clicking Executive', () => {
    const onChange = vi.fn()
    render(<ViewModeToggle value="full" onChange={onChange} />)

    fireEvent.click(screen.getByRole('button', { name: 'Executive' }))

    expect(onChange).toHaveBeenCalledWith('executive')
  })
})