"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var import_jsx_runtime = require("react/jsx-runtime");
var import_react = __toESM(require("react"));
var import_react2 = require("@testing-library/react");
var import__ = __toESM(require("../.."));
var import_Theme = __toESM(require("../../../Theme"));
var import_RadioGroupContext = __toESM(require("../../RadioGroupContext"));
const originalError = console.error;
beforeEach(() => {
  console.error = jest.fn();
});
afterEach(() => {
  console.error = originalError;
});
describe("<RadioGroup />", () => {
  describe("<RadioGroup.Radio />", () => {
    describe("Snapshots", () => {
      it("should match snapshot with default radio", () => {
        const { container } = (0, import_react2.render)(
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Theme.default, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.default.Radio, {}) })
        );
        expect(container).toMatchSnapshot();
      });
    });
    describe("Props", () => {
      it("should contains input type radio", () => {
        const { getByTestId } = (0, import_react2.render)(
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Theme.default, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.default.Radio, { "data-testid": "radio" }) })
        );
        expect(getByTestId("radio").type).toBe("radio");
      });
      it("value should be as prop value", () => {
        const { getByTestId } = (0, import_react2.render)(
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Theme.default, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.default.Radio, { "data-testid": "radio", value: "radio1" }) })
        );
        expect(getByTestId("radio").value).toBe("radio1");
      });
      it("checked should be the selectedValue provided from Context", () => {
        const { getAllByTestId } = (0, import_react2.render)(
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_RadioGroupContext.default.Provider, { value: { selectedValue: "Radio 2" }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_Theme.default, { children: [
            /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.default.Radio, { "data-testid": "radio", value: "Radio 1" }),
            /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.default.Radio, { "data-testid": "radio", value: "Radio 2" })
          ] }) })
        );
        const [radio, radio2] = getAllByTestId("radio");
        expect(radio.checked).toBe(false);
        expect(radio2.checked).toBe(true);
      });
      it("name should be the one provided by context", () => {
        const name = "test";
        const { getAllByTestId } = (0, import_react2.render)(
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_RadioGroupContext.default.Provider, { value: { name }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_Theme.default, { children: [
            /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.default.Radio, { "data-testid": "radio", value: "Radio 1" }),
            /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.default.Radio, { "data-testid": "radio", value: "Radio 2" }),
            /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.default.Radio, { "data-testid": "radio", value: "Radio 3" })
          ] }) })
        );
        const radios = getAllByTestId("radio");
        radios.map((radio) => expect(radio.name).toBe(name));
      });
    });
    describe("Events", () => {
      it("should call onchange from Context", () => {
        const onChangeMock = jest.fn();
        const { getByTestId } = (0, import_react2.render)(
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_RadioGroupContext.default.Provider, { value: { onChange: onChangeMock }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Theme.default, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.default.Radio, { "data-testid": "radio", value: "Radio 1" }) }) })
        );
        const radio = getByTestId("radio");
        import_react2.fireEvent.click(radio);
        expect(onChangeMock).toHaveBeenCalled();
      });
    });
  });
});
