"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
/**
 * Tests for the AccessibleRadio component
 */
const react_1 = __importDefault(require("react"));
const react_2 = require("@testing-library/react");
const AccessibleRadio_1 = require("../AccessibleRadio");
// Mock the accessibility system
jest.mock('../accessibility/AccessibilitySystem', () => ({
    useAccessibility: () => ({
        analyzeComponent: jest.fn().mockResolvedValue({
            issues: [],
            score: 100,
        }),
    }),
}));
describe('AccessibleRadio', () => {
    const defaultProps = {
        label: 'Test Radio Group',
        name: 'test-radio',
        options: [
            { label: 'Option 1', value: '1' },
            { label: 'Option 2', value: '2' },
            { label: 'Option 3', value: '3', description: 'Description for option 3' },
        ],
    };
    it('renders with basic props', () => {
        (0, react_2.render)((0, jsx_runtime_1.jsx)(AccessibleRadio_1.AccessibleRadio, { ...defaultProps }));
        // Check label
        expect(react_2.screen.getByText('Test Radio Group')).toBeInTheDocument();
        // Check options
        expect(react_2.screen.getByLabelText('Option 1')).toBeInTheDocument();
        expect(react_2.screen.getByLabelText('Option 2')).toBeInTheDocument();
        expect(react_2.screen.getByLabelText('Option 3')).toBeInTheDocument();
        // Check description
        expect(react_2.screen.getByText('Description for option 3')).toBeInTheDocument();
    });
    it('handles controlled value', () => {
        const onChange = jest.fn();
        (0, react_2.render)((0, jsx_runtime_1.jsx)(AccessibleRadio_1.AccessibleRadio, { ...defaultProps, value: "2", onChange: onChange }));
        // Check if second option is selected
        expect(react_2.screen.getByLabelText('Option 2')).toBeChecked();
        // Change selection
        react_2.fireEvent.click(react_2.screen.getByLabelText('Option 1'));
        expect(onChange).toHaveBeenCalledWith('1');
    });
    it('handles uncontrolled value with defaultValue', () => {
        (0, react_2.render)((0, jsx_runtime_1.jsx)(AccessibleRadio_1.AccessibleRadio, { ...defaultProps, defaultValue: "3" }));
        expect(react_2.screen.getByLabelText('Option 3')).toBeChecked();
    });
    it('displays helper text', () => {
        (0, react_2.render)((0, jsx_runtime_1.jsx)(AccessibleRadio_1.AccessibleRadio, { ...defaultProps, helperText: "Helper text" }));
        expect(react_2.screen.getByText('Helper text')).toBeInTheDocument();
    });
    it('displays error message', () => {
        (0, react_2.render)((0, jsx_runtime_1.jsx)(AccessibleRadio_1.AccessibleRadio, { ...defaultProps, error: "Error message" }));
        expect(react_2.screen.getByText('Error message')).toBeInTheDocument();
        expect(react_2.screen.getByRole('radiogroup')).toHaveAttribute('aria-invalid', 'true');
    });
    it('handles required state', () => {
        (0, react_2.render)((0, jsx_runtime_1.jsx)(AccessibleRadio_1.AccessibleRadio, { ...defaultProps, isRequired: true }));
        // Check required indicator
        expect(react_2.screen.getByText('*')).toBeInTheDocument();
        expect(react_2.screen.getByRole('radiogroup')).toHaveAttribute('aria-required', 'true');
    });
    it('handles disabled state', () => {
        (0, react_2.render)((0, jsx_runtime_1.jsx)(AccessibleRadio_1.AccessibleRadio, { ...defaultProps, isDisabled: true }));
        // Check if all options are disabled
        const options = react_2.screen.getAllByRole('radio');
        options.forEach(option => {
            expect(option).toBeDisabled();
        });
    });
    it('handles individual disabled options', () => {
        const options = [
            { label: 'Option 1', value: '1' },
            { label: 'Option 2', value: '2', isDisabled: true },
            { label: 'Option 3', value: '3' },
        ];
        (0, react_2.render)((0, jsx_runtime_1.jsx)(AccessibleRadio_1.AccessibleRadio, { ...defaultProps, options: options }));
        // Check if only Option 2 is disabled
        expect(react_2.screen.getByLabelText('Option 1')).not.toBeDisabled();
        expect(react_2.screen.getByLabelText('Option 2')).toBeDisabled();
        expect(react_2.screen.getByLabelText('Option 3')).not.toBeDisabled();
    });
    it('handles horizontal layout', () => {
        (0, react_2.render)((0, jsx_runtime_1.jsx)(AccessibleRadio_1.AccessibleRadio, { ...defaultProps, isHorizontal: true }));
        // Check if options container has horizontal layout class
        const optionsContainer = react_2.screen.getByRole('radiogroup').querySelector('.bfui-radio-options');
        expect(optionsContainer).toHaveClass('flex-row');
    });
    it('handles custom class names', () => {
        (0, react_2.render)((0, jsx_runtime_1.jsx)(AccessibleRadio_1.AccessibleRadio, { ...defaultProps, className: "custom-group", optionsClassName: "custom-options", optionClassName: "custom-option" }));
        // Check if custom classes are applied
        expect(react_2.screen.getByRole('radiogroup')).toHaveClass('custom-group');
        expect(react_2.screen.getByRole('radiogroup').querySelector('.bfui-radio-options')).toHaveClass('custom-options');
        expect(react_2.screen.getByLabelText('Option 1').closest('.bfui-radio-option')).toHaveClass('custom-option');
    });
    it('forwards ref', () => {
        const ref = react_1.default.createRef();
        (0, react_2.render)((0, jsx_runtime_1.jsx)(AccessibleRadio_1.AccessibleRadio, { ...defaultProps, ref: ref }));
        expect(ref.current).toBeInstanceOf(HTMLDivElement);
    });
    it('maintains focus styles', () => {
        (0, react_2.render)((0, jsx_runtime_1.jsx)(AccessibleRadio_1.AccessibleRadio, { ...defaultProps }));
        // Focus first option
        const firstOption = react_2.screen.getByLabelText('Option 1');
        firstOption.focus();
        // Check if focus styles are applied
        expect(firstOption).toHaveFocus();
    });
    it('handles dark mode styles', () => {
        // Add dark mode class to document
        document.documentElement.classList.add('dark');
        (0, react_2.render)((0, jsx_runtime_1.jsx)(AccessibleRadio_1.AccessibleRadio, { ...defaultProps }));
        // Check if dark mode classes are applied
        expect(react_2.screen.getByText('Test Radio Group')).toHaveClass('dark:text-gray-200');
        expect(react_2.screen.getByLabelText('Option 1').closest('.bfui-radio-option')).toHaveClass('dark:text-gray-200');
        // Clean up
        document.documentElement.classList.remove('dark');
    });
    it('provides proper ARIA attributes', () => {
        (0, react_2.render)((0, jsx_runtime_1.jsx)(AccessibleRadio_1.AccessibleRadio, { ...defaultProps, helperText: "Helper text", error: "Error message", isRequired: true, ariaDescribedby: "custom-desc" }));
        const radioGroup = react_2.screen.getByRole('radiogroup');
        // Check ARIA attributes
        expect(radioGroup).toHaveAttribute('aria-labelledby');
        expect(radioGroup).toHaveAttribute('aria-describedby');
        expect(radioGroup).toHaveAttribute('aria-invalid', 'true');
        expect(radioGroup).toHaveAttribute('aria-required', 'true');
        // Check if custom describedby is included
        const describedby = radioGroup.getAttribute('aria-describedby');
        expect(describedby).toContain('custom-desc');
    });
    it('handles keyboard navigation', () => {
        (0, react_2.render)((0, jsx_runtime_1.jsx)(AccessibleRadio_1.AccessibleRadio, { ...defaultProps }));
        // Focus first option
        const firstOption = react_2.screen.getByLabelText('Option 1');
        firstOption.focus();
        // Navigate to next option with arrow down
        react_2.fireEvent.keyDown(firstOption, { key: 'ArrowDown' });
        expect(react_2.screen.getByLabelText('Option 2')).toHaveFocus();
        // Navigate to previous option with arrow up
        react_2.fireEvent.keyDown(react_2.screen.getByLabelText('Option 2'), { key: 'ArrowUp' });
        expect(firstOption).toHaveFocus();
    });
    it('displays accessibility issues', async () => {
        // Mock accessibility analysis to return issues
        jest.spyOn(require('../accessibility/AccessibilitySystem').useAccessibility(), 'analyzeComponent')
            .mockResolvedValueOnce({
            issues: ['Issue 1', 'Issue 2'],
            score: 80,
        });
        (0, react_2.render)((0, jsx_runtime_1.jsx)(AccessibleRadio_1.AccessibleRadio, { ...defaultProps }));
        // Wait for accessibility issues to be displayed
        const issues = await react_2.screen.findByText('Accessibility Issues:');
        expect(issues).toBeInTheDocument();
        expect(react_2.screen.getByText('Issue 1')).toBeInTheDocument();
        expect(react_2.screen.getByText('Issue 2')).toBeInTheDocument();
    });
    it('handles value changes', () => {
        const onChange = jest.fn();
        (0, react_2.render)((0, jsx_runtime_1.jsx)(AccessibleRadio_1.AccessibleRadio, { ...defaultProps, onChange: onChange }));
        // Select first option
        react_2.fireEvent.click(react_2.screen.getByLabelText('Option 1'));
        expect(onChange).toHaveBeenCalledWith('1');
        // Select second option
        react_2.fireEvent.click(react_2.screen.getByLabelText('Option 2'));
        expect(onChange).toHaveBeenCalledWith('2');
    });
    it('handles blur events', () => {
        const onBlur = jest.fn();
        (0, react_2.render)((0, jsx_runtime_1.jsx)(AccessibleRadio_1.AccessibleRadio, { ...defaultProps, onBlur: onBlur }));
        // Focus and blur first option
        const firstOption = react_2.screen.getByLabelText('Option 1');
        firstOption.focus();
        firstOption.blur();
        expect(onBlur).toHaveBeenCalled();
    });
    it('maintains component state during prop changes', () => {
        const { rerender } = (0, react_2.render)((0, jsx_runtime_1.jsx)(AccessibleRadio_1.AccessibleRadio, { ...defaultProps, value: "1" }));
        // Check initial value
        expect(react_2.screen.getByLabelText('Option 1')).toBeChecked();
        // Change value prop
        rerender((0, jsx_runtime_1.jsx)(AccessibleRadio_1.AccessibleRadio, { ...defaultProps, value: "2" }));
        expect(react_2.screen.getByLabelText('Option 2')).toBeChecked();
        // Change back to initial value
        rerender((0, jsx_runtime_1.jsx)(AccessibleRadio_1.AccessibleRadio, { ...defaultProps, value: "1" }));
        expect(react_2.screen.getByLabelText('Option 1')).toBeChecked();
    });
});
//# sourceMappingURL=AccessibleRadio.test.js.map