import { render, screen } from '@testing-library/react' import userEvent from '@testing-library/user-event' // radio-ui.spec.tsx import { describe, expect, it, vi } from 'vitest' import RadioUI from './ui' describe('RadioUI component', () => { it('renders with correct role and aria attributes', () => { render() const radio = screen.getByRole('radio') expect(radio).toBeInTheDocument() expect(radio).toHaveAttribute('aria-checked', 'true') expect(radio).toHaveAttribute('aria-disabled', 'false') }) it('applies checked + enabled styles', () => { render() const radio = screen.getByRole('radio') expect(radio.className).toContain('border-[5px]') expect(radio.className).toContain('border-components-radio-border-checked') }) it('applies unchecked + enabled styles', () => { render() const radio = screen.getByRole('radio') expect(radio.className).toContain('border-components-radio-border') }) it('applies checked + disabled styles', () => { render() const radio = screen.getByRole('radio') expect(radio).toHaveAttribute('aria-disabled', 'true') expect(radio.className).toContain( 'border-components-radio-border-checked-disabled', ) }) it('applies unchecked + disabled styles', () => { render() const radio = screen.getByRole('radio') expect(radio.className).toContain( 'border-components-radio-border-disabled', ) expect(radio.className).toContain( 'bg-components-radio-bg-disabled', ) }) it('calls onCheck when clicked if not disabled', async () => { const user = userEvent.setup() const handleCheck = vi.fn() render() const radio = screen.getByRole('radio') await user.click(radio) expect(handleCheck).toHaveBeenCalledTimes(1) }) it('does not call onCheck when disabled', async () => { const user = userEvent.setup() const handleCheck = vi.fn() render( , ) const radio = screen.getByRole('radio') await user.click(radio) expect(handleCheck).not.toHaveBeenCalled() }) it('merges custom className', () => { render( , ) const radio = screen.getByRole('radio') expect(radio.className).toContain('my-extra-class') }) it('memo export renders correctly', () => { render() expect(screen.getByRole('radio')).toBeInTheDocument() }) })