import { describe, expect, it, vi } from 'vitest'
import { render, screen, fireEvent } from '@testing-library/react'
import { Switch } from './Switch'

describe('Switch', () => {
  it('exposes the switch role (not checkbox) with an accessible name', () => {
    render(<Switch aria-label="Dark mode" />)
    expect(screen.getByRole('switch', { name: 'Dark mode' })).toBeTruthy()
  })

  it('toggles on click and fires onCheckedChange', () => {
    const onCheckedChange = vi.fn()
    render(<Switch aria-label="Notifications" onCheckedChange={onCheckedChange} />)
    fireEvent.click(screen.getByRole('switch', { name: 'Notifications' }))
    expect(onCheckedChange).toHaveBeenCalledWith(true)
  })

  it('reflects controlled checked state via aria-checked (edge)', () => {
    render(<Switch aria-label="On" checked />)
    expect(screen.getByRole('switch', { name: 'On' }).getAttribute('aria-checked')).toBe('true')
  })
})
