import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { render, screen } from "@testing-library/react";
import { userEvent } from "@testing-library/user-event";
import { RadioGroup } from "./radio-group.js";
import { Radio } from "./radio.js";
describe("RadioGroup Component", () => {
    it("should match snapshot", () => {
        const { asFragment } = render(_jsxs(RadioGroup, { name: "radio-group", children: [_jsx(Radio, { label: "Option 1", value: "1" }), _jsx(Radio, { label: "Option 2", value: "2" })] }));
        expect(asFragment()).toMatchSnapshot();
    });
    it("should render Radio options with label", () => {
        render(_jsxs(RadioGroup, { name: "radio-group", children: [_jsx(Radio, { label: "Option 1", value: "1" }), _jsx(Radio, { label: "Option 2", value: "2" })] }));
        expect(screen.getByRole("radiogroup")).toBeInTheDocument();
        expect(screen.getByText("Option 1")).toBeInTheDocument();
        expect(screen.getByText("Option 2")).toBeInTheDocument();
        expect(screen.getAllByRole("radio")).toHaveLength(2);
    });
    it("should call onValueChange when a Radio label is clicked", async () => {
        const onValueChangeMock = vi.fn();
        const user = userEvent.setup();
        render(_jsxs(RadioGroup, { name: "radio-group", onValueChange: onValueChangeMock, children: [_jsx(Radio, { label: "Option 1", value: "1" }), _jsx(Radio, { label: "Option 2", value: "2" })] }));
        await user.click(screen.getByLabelText("Option 1"));
        expect(onValueChangeMock).toHaveBeenCalledTimes(1);
        expect(onValueChangeMock).toHaveBeenCalledWith("1");
    });
    it("should change the value when a different Radio is selected", async () => {
        const user = userEvent.setup();
        render(_jsxs(RadioGroup, { name: "radio-group", defaultValue: "1", children: [_jsx(Radio, { label: "Option 1", value: "1" }), _jsx(Radio, { label: "Option 2", value: "2" })] }));
        const radio1 = screen.getByLabelText("Option 1");
        const radio2 = screen.getByLabelText("Option 2");
        expect(radio1).toBeChecked();
        expect(radio2).not.toBeChecked();
        await user.click(radio2);
        expect(radio1).not.toBeChecked();
        expect(radio2).toBeChecked();
    });
    it("should handle accessibility (aria-label)", () => {
        render(_jsx(RadioGroup, { name: "radio-group", "aria-label": "unlabeled group", children: _jsx(Radio, { label: "Option 1", value: "1" }) }));
        const radioGroup = screen.getByRole("radiogroup");
        expect(radioGroup).toHaveAttribute("aria-label", "unlabeled group");
    });
    it("should generate unique ids when not provided", () => {
        render(_jsx(RadioGroup, { name: "radio-group", children: _jsx(Radio, { label: "Option 1", value: "1" }) }));
        const radioGroup = screen.getByRole("radiogroup");
        expect(radioGroup.id).toMatch(/^.*-radio-group$/);
    });
    it("should use provided id when specified", () => {
        render(_jsx(RadioGroup, { name: "radio-group", id: "custom-id", children: _jsx(Radio, { label: "Option 1", value: "1" }) }));
        const radioGroup = screen.getByRole("radiogroup");
        expect(radioGroup).toHaveAttribute("id", "custom-id");
    });
    it("should handle required state", () => {
        render(_jsx(RadioGroup, { name: "radio-group", required: true, children: _jsx(Radio, { label: "Option 1", value: "1" }) }));
        const radioGroup = screen.getByRole("radiogroup");
        expect(radioGroup).toHaveAttribute("aria-required", "true");
    });
    it("should handle defaultValue", () => {
        render(_jsxs(RadioGroup, { name: "radio-group", defaultValue: "2", children: [_jsx(Radio, { label: "Option 1", value: "1" }), _jsx(Radio, { label: "Option 2", value: "2" })] }));
        const selectedRadio = screen.getByLabelText("Option 2");
        expect(selectedRadio).toBeChecked();
    });
    it("should handle value", () => {
        render(_jsxs(RadioGroup, { name: "radio-group", value: "1", children: [_jsx(Radio, { label: "Option 1", value: "1" }), _jsx(Radio, { label: "Option 2", value: "2" })] }));
        const selectedRadio = screen.getByLabelText("Option 1");
        expect(selectedRadio).toBeChecked();
    });
    it("should apply custom className", () => {
        render(
        // Custom className for testing purposes
        _jsx(RadioGroup, { name: "radio-group", className: "custom-class", children: _jsx(Radio, { label: "Option 1", value: "1" }) }));
        const radioGroup = screen.getByRole("radiogroup");
        expect(radioGroup).toHaveClass("custom-class");
    });
});
//# sourceMappingURL=radio-group.test.js.map