"use strict";

var _react = _interopRequireDefault(require("react"));
var _radio = _interopRequireDefault(require("./radio"));
var _reactNative = require("@testing-library/react-native");
var _themeContext = require("../../../theme/src/theme-context");
var _radioGroup = _interopRequireDefault(require("./radio-group"));
var _stack = _interopRequireDefault(require("../../atoms/stack/stack"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
jest.useFakeTimers();
describe("Molecules/Radio", () => {
  it("passes the snapshot test for basic setup", async () => {
    const tree = await (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_themeContext.ThemeProvider, null, /*#__PURE__*/_react.default.createElement(_radio.default, null, "Check me!"))).toJSON();
    expect(tree).toMatchSnapshot();
  });
  it("passes the snapshot test for different sizes", async () => {
    const tree = await (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_themeContext.ThemeProvider, null, /*#__PURE__*/_react.default.createElement(_radio.default, {
      size: "xs"
    }, "Small Radio"), /*#__PURE__*/_react.default.createElement(_radio.default, {
      size: "s"
    }, "Regular Radio"), /*#__PURE__*/_react.default.createElement(_radio.default, {
      size: "m"
    }, "Large Radio"), /*#__PURE__*/_react.default.createElement(_radio.default, {
      size: "l"
    }, "Extra Large Radio"))).toJSON();
    expect(tree).toMatchSnapshot();
  });
  it("passes the snapshot test for different variants", async () => {
    const tree = await (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_themeContext.ThemeProvider, null, /*#__PURE__*/_react.default.createElement(_radio.default, {
      variant: "filled"
    }, "Filled Radio"), /*#__PURE__*/_react.default.createElement(_radio.default, {
      variant: "outline"
    }, "Outline Radio"))).toJSON();
    expect(tree).toMatchSnapshot();
  });
  it("passes the snapshot test when in a checked state", async () => {
    const tree = await (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_themeContext.ThemeProvider, null, /*#__PURE__*/_react.default.createElement(_radio.default, {
      variant: "filled",
      isChecked: true
    }, "Checked Radio"), /*#__PURE__*/_react.default.createElement(_radio.default, {
      variant: "outline",
      isChecked: true
    }, "Checked Radio"))).toJSON();
    expect(tree).toMatchSnapshot();
  });
  it("passes the snapshot test when in an error state", async () => {
    const tree = await (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_themeContext.ThemeProvider, null, /*#__PURE__*/_react.default.createElement(_radio.default, {
      isInvalid: true
    }, "Error Radio"))).toJSON();
    expect(tree).toMatchSnapshot();
  });
  it("passes the snapshot test for different color schemes", async () => {
    const tree = await (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_themeContext.ThemeProvider, null, /*#__PURE__*/_react.default.createElement(_radio.default, {
      colorScheme: "primary"
    }, "Primary Radio"), /*#__PURE__*/_react.default.createElement(_radio.default, {
      colorScheme: "secondary"
    }, "Secondary Radio"))).toJSON();
    expect(tree).toMatchSnapshot();
  });
  it("passes the snapshot test when using style props", async () => {
    const onPress = jest.fn();
    const tree = await (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_themeContext.ThemeProvider, null, /*#__PURE__*/_react.default.createElement(_radio.default, {
      onPress: onPress,
      backgroundColor: "primary.500",
      borderColor: "neutral.400",
      borderWidth: 2
    }, "Button press"))).toJSON();
    expect(tree).toMatchSnapshot();
  });
  it("captures the onPress event", async () => {
    const onPress = jest.fn();
    const component = await (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_themeContext.ThemeProvider, null, /*#__PURE__*/_react.default.createElement(_radio.default, {
      onPress: onPress,
      testID: "radio"
    }, "Check me")));
    const tree = component.toJSON();
    if (tree.children[0].children[0].children[0].type !== "RNGestureHandlerButton") {
      const pressableInstance = component.getByTestId("radio");
      _reactNative.fireEvent.press(pressableInstance);
      expect(onPress).toHaveBeenCalledTimes(1);
    }
  });
  it("changes the active value successfully when used in a group", async () => {
    const onChange = jest.fn();
    const component = await (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_themeContext.ThemeProvider, null, /*#__PURE__*/_react.default.createElement(_radioGroup.default, {
      defaultValue: "1",
      value: "2",
      onChange: onChange
    }, /*#__PURE__*/_react.default.createElement(_stack.default, {
      direction: "horizontal",
      spacing: "s"
    }, /*#__PURE__*/_react.default.createElement(_radio.default, {
      value: "1",
      testID: "radio1"
    }, "Value 1"), /*#__PURE__*/_react.default.createElement(_radio.default, {
      value: "2",
      testID: "radio2"
    }, "Value 2"), /*#__PURE__*/_react.default.createElement(_radio.default, {
      value: 3,
      testID: "radio3"
    }, "Value 3"), /*#__PURE__*/_react.default.createElement(_radio.default, {
      value: 4,
      testID: "radio4"
    }, "Value 4")))));
    const tree = component.toJSON();
    if (tree.children[0].children[0].children[0].children[0].children[0].children[0].type !== "RNGestureHandlerButton") {
      const radio1 = component.getByTestId("radio1");
      _reactNative.fireEvent.press(radio1);
      expect(onChange).toHaveBeenCalledTimes(1);
      expect(onChange).toBeCalledWith("1");
      const radio2 = component.getByTestId("radio2");
      _reactNative.fireEvent.press(radio2);
      expect(onChange).toHaveBeenCalledTimes(2);
      expect(onChange).toBeCalledWith("2");
      const radio3 = component.getByTestId("radio3");
      _reactNative.fireEvent.press(radio3);
      expect(onChange).toHaveBeenCalledTimes(3);
      expect(onChange).toBeCalledWith(3);
      const radio4 = component.getByTestId("radio4");
      _reactNative.fireEvent.press(radio4);
      expect(onChange).toHaveBeenCalledTimes(4);
      expect(onChange).toBeCalledWith(4);
    }
  });
  it("doesn't capture the onPress event when the radio is disabled ", async () => {
    const onPress = jest.fn();
    const component = await (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_themeContext.ThemeProvider, null, /*#__PURE__*/_react.default.createElement(_radio.default, {
      onPress: onPress,
      isDisabled: true,
      testID: "radio"
    }, "Check me")));
    const tree = component.toJSON();
    if (tree.children[0].children[0].children[0].type !== "RNGestureHandlerButton") {
      const pressableInstance = component.getByTestId("radio");
      _reactNative.fireEvent.press(pressableInstance);
      expect(onPress).toHaveBeenCalledTimes(0);
    }
  });
});
//# sourceMappingURL=radio.spec.js.map