@kadconsulting/dry
Version:
KAD Reusable Component Library
38 lines • 1.99 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { render, fireEvent } from '@testing-library/react';
import RadioButton from './RadioButton';
describe('RadioButton component', () => {
it('renders without crashing', () => {
const { getByText } = render(_jsx(RadioButton, { text: 'Sample Text' }));
expect(getByText('Sample Text')).toBeInTheDocument();
});
it('displays subtext when provided', () => {
const { getByText } = render(_jsx(RadioButton, { text: 'Sample Text', subText: 'Sample Subtext' }));
expect(getByText('Sample Subtext')).toBeInTheDocument();
});
it('displays extraText when provided', () => {
const { getByText } = render(_jsx(RadioButton, { text: 'Sample Text', extraText: 'Extra Text' }));
expect(getByText('Extra Text')).toBeInTheDocument();
});
it('is disabled when the disabled prop is true', () => {
const { getByRole } = render(_jsx(RadioButton, { text: 'Sample Text', disabled: true }));
expect(getByRole('radio')).toBeDisabled();
});
it('is not disabled when the disabled prop is false', () => {
const { getByRole } = render(_jsx(RadioButton, { text: 'Sample Text', disabled: false }));
expect(getByRole('radio')).not.toBeDisabled();
});
it('calls the onChange handler when clicked', () => {
const mockOnChange = jest.fn();
const { getByRole } = render(_jsx(RadioButton, { text: 'Sample Text', onChange: mockOnChange }));
fireEvent.click(getByRole('radio'));
expect(mockOnChange).toHaveBeenCalledTimes(1);
});
it('does not call the onChange handler when disabled', () => {
const mockOnChange = jest.fn();
const { getByRole } = render(_jsx(RadioButton, { text: 'Sample Text', disabled: true, onChange: mockOnChange }));
fireEvent.click(getByRole('radio'));
expect(mockOnChange).toHaveBeenCalledTimes(0);
});
});
//# sourceMappingURL=RadioButton.test.js.map