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

describe('RadioGroup', () => {
  it('exposes radiogroup + radio roles with accessible names', () => {
    render(
      <RadioGroup aria-label="Plan">
        <Radio value="free" aria-label="Free" />
        <Radio value="pro" aria-label="Pro" />
      </RadioGroup>,
    )
    expect(screen.getByRole('radiogroup', { name: 'Plan' })).toBeTruthy()
    expect(screen.getAllByRole('radio')).toHaveLength(2)
  })

  it('selects a radio on click and fires onValueChange', () => {
    const onValueChange = vi.fn()
    render(
      <RadioGroup aria-label="Plan" onValueChange={onValueChange}>
        <Radio value="free" aria-label="Free" />
        <Radio value="pro" aria-label="Pro" />
      </RadioGroup>,
    )
    fireEvent.click(screen.getByRole('radio', { name: 'Pro' }))
    expect(onValueChange).toHaveBeenCalledWith('pro')
  })

  it('disables a single radio (edge)', () => {
    render(
      <RadioGroup aria-label="Plan">
        <Radio value="free" aria-label="Free" disabled />
      </RadioGroup>,
    )
    expect(screen.getByRole('radio', { name: 'Free' })).toBeDisabled()
  })
})
