"use strict";

var _react = _interopRequireWildcard(require("react"));
var _checkbox = _interopRequireDefault(require("./checkbox"));
var _reactNative = require("@testing-library/react-native");
var _themeContext = require("../../../theme/src/theme-context");
var _checkboxGroup = _interopRequireDefault(require("./checkbox-group"));
var _stack = _interopRequireDefault(require("../../atoms/stack/stack"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
jest.useFakeTimers();
describe("Molecules/CheckBox", () => {
  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(_checkbox.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(_checkbox.default, {
      size: "xs"
    }, "Small Checkbox"), /*#__PURE__*/_react.default.createElement(_checkbox.default, {
      size: "s"
    }, "Regular Checkbox"), /*#__PURE__*/_react.default.createElement(_checkbox.default, {
      size: "m"
    }, "Large Checkbox"), /*#__PURE__*/_react.default.createElement(_checkbox.default, {
      size: "l"
    }, "Extra Large Checkbox"))).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(_checkbox.default, {
      variant: "filled"
    }, "Filled Checkbox"), /*#__PURE__*/_react.default.createElement(_checkbox.default, {
      variant: "outline"
    }, "Outline Checkbox"))).toJSON();
    expect(tree).toMatchSnapshot();
  });
  it("passes the snapshot test when in a checked/indeterminate state", async () => {
    const tree = await (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_themeContext.ThemeProvider, null, /*#__PURE__*/_react.default.createElement(_checkbox.default, {
      variant: "filled",
      isChecked: true,
      isIndeterminate: true
    }, "Indeterminate Checkbox"), /*#__PURE__*/_react.default.createElement(_checkbox.default, {
      variant: "filled",
      isChecked: true
    }, "Checked Checkbox"), /*#__PURE__*/_react.default.createElement(_checkbox.default, {
      variant: "outline",
      isChecked: true,
      isIndeterminate: true
    }, "Indeterminate Checkbox"), /*#__PURE__*/_react.default.createElement(_checkbox.default, {
      variant: "outline",
      isChecked: true
    }, "Checked Checkbox"))).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(_checkbox.default, {
      isInvalid: true
    }, "Error Checkbox"))).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(_checkbox.default, {
      colorScheme: "primary"
    }, "Primary CheckBox"), /*#__PURE__*/_react.default.createElement(_checkbox.default, {
      colorScheme: "secondary"
    }, "Secondary CheckBox"))).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(_checkbox.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(_checkbox.default, {
      onPress: onPress,
      testID: "checkBox"
    }, "Check me")));
    const tree = component.toJSON();
    if (tree.children[0].children[0].children[0].type !== "RNGestureHandlerButton") {
      const pressableInstance = component.getByTestId("checkBox");
      _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 Wrapper = () => {
      const [checkedGroup, setCheckedGroup] = (0, _react.useState)([]);
      const checkedHandler = value => {
        setCheckedGroup(value);
        onChange(value);
      };
      return /*#__PURE__*/_react.default.createElement(_checkboxGroup.default, {
        defaultValue: [],
        value: checkedGroup,
        onChange: checkedHandler
      }, /*#__PURE__*/_react.default.createElement(_stack.default, {
        direction: "horizontal",
        spacing: "s"
      }, /*#__PURE__*/_react.default.createElement(_checkbox.default, {
        value: "1",
        testID: "checkbox1"
      }, "Value 1"), /*#__PURE__*/_react.default.createElement(_checkbox.default, {
        value: "2",
        testID: "checkbox2"
      }, "Value 2"), /*#__PURE__*/_react.default.createElement(_checkbox.default, {
        value: 3,
        testID: "checkbox3"
      }, "Value 3"), /*#__PURE__*/_react.default.createElement(_checkbox.default, {
        value: 4,
        testID: "checkbox4"
      }, "Value 4")));
    };
    const component = await (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_themeContext.ThemeProvider, null, /*#__PURE__*/_react.default.createElement(Wrapper, null)));
    const tree = component.toJSON();
    if (tree.children[0].children[0].children[0].children[0].children[0].children[0].type !== "RNGestureHandlerButton") {
      const checkbox1 = component.getByTestId("checkbox1");
      _reactNative.fireEvent.press(checkbox1);
      expect(onChange).toHaveBeenCalledTimes(1);
      expect(onChange).toBeCalledWith(["1"]);
      const checkbox2 = component.getByTestId("checkbox2");
      _reactNative.fireEvent.press(checkbox2);
      expect(onChange).toHaveBeenCalledTimes(2);
      expect(onChange).toBeCalledWith(["1", "2"]);

      // Remove the value
      _reactNative.fireEvent.press(checkbox2);
      expect(onChange).toHaveBeenCalledTimes(3);
      expect(onChange).toBeCalledWith(["1"]);
      const checkbox3 = component.getByTestId("checkbox3");
      _reactNative.fireEvent.press(checkbox3);
      expect(onChange).toHaveBeenCalledTimes(4);
      expect(onChange).toBeCalledWith(["1", 3]);
      const checkbox4 = component.getByTestId("checkbox4");
      _reactNative.fireEvent.press(checkbox4);
      expect(onChange).toHaveBeenCalledTimes(5);
      expect(onChange).toBeCalledWith(["1", 3, 4]);
    }
  });
  it("doesn't capture the onPress event when the checkbox is disabled ", async () => {
    const onPress = jest.fn();
    const component = await (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_themeContext.ThemeProvider, null, /*#__PURE__*/_react.default.createElement(_checkbox.default, {
      onPress: onPress,
      isDisabled: true,
      testID: "checkBox"
    }, "Check me")));
    const tree = component.toJSON();
    if (tree.children[0].children[0].children[0].type !== "RNGestureHandlerButton") {
      const pressableInstance = component.getByTestId("checkBox");
      _reactNative.fireEvent.press(pressableInstance);
      expect(onPress).toHaveBeenCalledTimes(0);
    }
  });
});
//# sourceMappingURL=checkbox.spec.js.map