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.Button />", () => {
    describe("Snapshots", () => {
      it("should match snapshot with default radio button", () => {
        const { root, toJSON } = render(
          /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(RadioGroup.Button, { children: "Radio 1" }) })
        );
        expect(toJSON(root)).toMatchSnapshot();
      });
      it("should match snapshot with small radio button", () => {
        const { root, toJSON } = render(
          /* @__PURE__ */ jsx(RadioGroupContext.Provider, { value: { small: true }, children: /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(RadioGroup.Button, { children: "Radio 1" }) }) })
        );
        expect(toJSON(root)).toMatchSnapshot();
      });
    });
    describe("Props", () => {
      it("checked should be the selectedValue provided from Context", () => {
        const { getAllByText } = render(
          /* @__PURE__ */ jsx(RadioGroupContext.Provider, { value: { selectedValue: "Radio 2" }, children: /* @__PURE__ */ jsxs(ThemeProvider, { children: [
            /* @__PURE__ */ jsx(RadioGroup.Button, { children: "Radio 1" }),
            /* @__PURE__ */ jsx(RadioGroup.Button, { children: "Radio 2" })
          ] }) })
        );
        const [radio, radio2] = getAllByText(/^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 { getByText } = render(
          /* @__PURE__ */ jsx(RadioGroupContext.Provider, { value: { onChange: onChangeMock }, children: /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(RadioGroup.Button, { children: "Radio 1" }) }) })
        );
        const radio = getByText(/^Radio/);
        fireEvent.press(radio);
        expect(onChangeMock).toHaveBeenCalled();
      });
      it("value should be as prop value", () => {
        const onChangeMock = jest.fn();
        const { getByText } = render(
          /* @__PURE__ */ jsx(RadioGroupContext.Provider, { value: { onChange: onChangeMock }, children: /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(RadioGroup.Button, { value: "radio1", children: "Radio 1" }) }) })
        );
        const radio = getByText(/^Radio/);
        fireEvent.press(radio);
        expect(onChangeMock).toHaveBeenCalledWith({
          value: "radio1"
        });
      });
      it("value should be children if prop value is ommited", () => {
        const onChangeMock = jest.fn();
        const { getByText } = render(
          /* @__PURE__ */ jsx(RadioGroupContext.Provider, { value: { onChange: onChangeMock }, children: /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(RadioGroup.Button, { children: "Radio 1" }) }) })
        );
        const radio = getByText(/^Radio/);
        fireEvent.press(radio);
        expect(onChangeMock).toHaveBeenCalledWith({
          value: "Radio 1"
        });
      });
    });
  });
});
