import { jsx, jsxs } from "react/jsx-runtime";
import React from "react";
import { render, fireEvent } from "@testing-library/react-native";
import RadioGroup from "../..";
import ThemeProvider from "../../../Theme";
import RadioGroupContext from "../../RadioGroupContext";
describe("<RadioGroup />", () => {
  describe("<RadioGroup.Radio />", () => {
    describe("Snapshots", () => {
      it("should match snapshot with default radio", () => {
        const { root, toJSON } = render(
          /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(RadioGroup.Radio, {}) })
        );
        expect(toJSON(root)).toMatchSnapshot();
      });
      it("should match snapshot with disabled radio", () => {
        const { root, toJSON } = render(
          /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(RadioGroup.Radio, { disabled: true }) })
        );
        expect(toJSON(root)).toMatchSnapshot();
      });
      it("should match snapshot with default radio", () => {
        const { root, toJSON } = render(
          /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(RadioGroup.Radio, {}) })
        );
        expect(toJSON(root)).toMatchSnapshot();
      });
      it("should match snapshot with default radio pressed", () => {
        const onChangeMock = jest.fn();
        const { root, getByTestId, toJSON } = render(
          /* @__PURE__ */ jsx(RadioGroupContext.Provider, { value: { onChange: onChangeMock }, children: /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(RadioGroup.Radio, { testID: "radio" }) }) })
        );
        const radio = getByTestId(/^radio/);
        fireEvent.press(radio);
        expect(toJSON(root)).toMatchSnapshot();
      });
    });
    describe("Props", () => {
      it("checked should be the selectedValue provided from Context", () => {
        const { getAllByTestId } = render(
          /* @__PURE__ */ jsx(RadioGroupContext.Provider, { value: { selectedValue: "Radio 2" }, children: /* @__PURE__ */ jsxs(ThemeProvider, { children: [
            /* @__PURE__ */ jsx(RadioGroup.Radio, { testID: "radio", value: "Radio 1" }),
            /* @__PURE__ */ jsx(RadioGroup.Radio, { testID: "radio", value: "Radio 2" })
          ] }) })
        );
        const [radio, radio2] = getAllByTestId(/^radio/);
        expect(radio.props.checked).toBe(false);
        expect(radio2.props.checked).toBe(true);
      });
    });
    describe("Events", () => {
      it("should call onchange from Context", () => {
        const onChangeMock = jest.fn();
        const { getByTestId } = render(
          /* @__PURE__ */ jsx(RadioGroupContext.Provider, { value: { onChange: onChangeMock }, children: /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(RadioGroup.Radio, { testID: "radio" }) }) })
        );
        const radio = getByTestId(/^radio/);
        fireEvent.press(radio);
        expect(onChangeMock).toHaveBeenCalled();
      });
      it("value should be as prop value", () => {
        const onChangeMock = jest.fn();
        const { getByTestId } = render(
          /* @__PURE__ */ jsx(RadioGroupContext.Provider, { value: { onChange: onChangeMock }, children: /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(RadioGroup.Radio, { value: "radio1", testID: "radio" }) }) })
        );
        const radio = getByTestId(/^radio/);
        fireEvent.press(radio);
        expect(onChangeMock).toHaveBeenCalledWith({
          value: "radio1"
        });
      });
    });
  });
});
