Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/core/primitives/Radio/tests/Radio.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import RadioPrimitive from '../index';

describe('RadioPrimitive', () => {
const baseProps = {
name: 'test-radio',
value: 'option1',
id: 'radio1',
};

it('renders with required props', () => {
render(<RadioPrimitive {...baseProps} />);
const radio = screen.getByRole('radio');
expect(radio).toBeInTheDocument();
expect(radio).toHaveAttribute('name', 'test-radio');
expect(radio).toHaveAttribute('value', 'option1');
expect(radio).toHaveAttribute('id', 'option1');
});

it('applies checked, required, and disabled props', () => {
render(
<RadioPrimitive {...baseProps} checked required disabled />
);
const radio = screen.getByRole('radio');
expect(radio).toBeChecked();
expect(radio).toBeRequired();
expect(radio).toBeDisabled();
expect(radio).toHaveAttribute('aria-disabled', 'true');
expect(radio).toHaveAttribute('aria-required', 'true');
});

it('calls onChange when clicked', () => {
const handleChange = jest.fn();
render(
<RadioPrimitive {...baseProps} onChange={handleChange} />
);
const radio = screen.getByRole('radio');
fireEvent.click(radio);
expect(handleChange).toHaveBeenCalled();
});

it('supports asChild prop (renders without error)', () => {
render(<RadioPrimitive {...baseProps} asChild />);
const radio = screen.getByRole('radio');
expect(radio).toBeInTheDocument();
});
});
Loading