"use strict";

var _react = _interopRequireDefault(require("react"));
var _iconButton = _interopRequireDefault(require("./icon-button"));
var _reactNative = require("@testing-library/react-native");
var _themeContext = require("../../../theme/src/theme-context");
var _icon = _interopRequireDefault(require("../../atoms/icon/icon"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
jest.useFakeTimers();
describe("Molecules/IconButton", () => {
  it("passes the snapshot test for basic setup", async () => {
    const onPress = jest.fn();
    const tree = await (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_themeContext.ThemeProvider, null, /*#__PURE__*/_react.default.createElement(_iconButton.default, {
      icon: /*#__PURE__*/_react.default.createElement(_icon.default, {
        iconFamily: "AntDesign",
        iconName: "heart"
      }),
      onPress: onPress
    }))).toJSON();
    expect(tree).toMatchSnapshot();
  });
  it("passes the snapshot test for different sizes", async () => {
    const onPress = jest.fn();
    const tree = await (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_themeContext.ThemeProvider, null, /*#__PURE__*/_react.default.createElement(_iconButton.default, {
      icon: /*#__PURE__*/_react.default.createElement(_icon.default, {
        iconFamily: "AntDesign",
        iconName: "heart"
      }),
      onPress: onPress,
      size: "xs"
    }), /*#__PURE__*/_react.default.createElement(_iconButton.default, {
      icon: /*#__PURE__*/_react.default.createElement(_icon.default, {
        iconFamily: "AntDesign",
        iconName: "heart"
      }),
      onPress: onPress,
      size: "s"
    }), /*#__PURE__*/_react.default.createElement(_iconButton.default, {
      icon: /*#__PURE__*/_react.default.createElement(_icon.default, {
        iconFamily: "AntDesign",
        iconName: "heart"
      }),
      onPress: onPress,
      size: "m"
    }), /*#__PURE__*/_react.default.createElement(_iconButton.default, {
      icon: /*#__PURE__*/_react.default.createElement(_icon.default, {
        iconFamily: "AntDesign",
        iconName: "heart"
      }),
      onPress: onPress,
      size: "l"
    }))).toJSON();
    expect(tree).toMatchSnapshot();
  });
  it("passes the snapshot test for different variants", async () => {
    const onPress = jest.fn();
    const tree = await (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_themeContext.ThemeProvider, null, /*#__PURE__*/_react.default.createElement(_iconButton.default, {
      icon: /*#__PURE__*/_react.default.createElement(_icon.default, {
        iconFamily: "AntDesign",
        iconName: "heart"
      }),
      onPress: onPress,
      variant: "filled"
    }), /*#__PURE__*/_react.default.createElement(_iconButton.default, {
      icon: /*#__PURE__*/_react.default.createElement(_icon.default, {
        iconFamily: "AntDesign",
        iconName: "heart"
      }),
      onPress: onPress,
      variant: "outline"
    }), /*#__PURE__*/_react.default.createElement(_iconButton.default, {
      icon: /*#__PURE__*/_react.default.createElement(_icon.default, {
        iconFamily: "AntDesign",
        iconName: "heart"
      }),
      onPress: onPress,
      variant: "ghost"
    }))).toJSON();
    expect(tree).toMatchSnapshot();
  });
  it("passes the snapshot test for different icons", async () => {
    const tree = await (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_themeContext.ThemeProvider, null, /*#__PURE__*/_react.default.createElement(_iconButton.default, {
      icon: /*#__PURE__*/_react.default.createElement(_icon.default, {
        iconFamily: "AntDesign",
        iconName: "heart"
      })
    }), /*#__PURE__*/_react.default.createElement(_iconButton.default, {
      variant: "outline",
      icon: /*#__PURE__*/_react.default.createElement(_icon.default, {
        iconFamily: "AntDesign",
        iconName: "cloudupload"
      })
    }))).toJSON();
    expect(tree).toMatchSnapshot();
  });
  it("passes the snapshot test for loading state", async () => {
    const tree = await (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_themeContext.ThemeProvider, null, /*#__PURE__*/_react.default.createElement(_iconButton.default, {
      icon: /*#__PURE__*/_react.default.createElement(_icon.default, {
        iconFamily: "AntDesign",
        iconName: "heart"
      }),
      isLoading: true
    }, "Basic loading IconButton"))).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(_iconButton.default, {
      icon: /*#__PURE__*/_react.default.createElement(_icon.default, {
        iconFamily: "AntDesign",
        iconName: "heart"
      }),
      colorScheme: "primary"
    }), /*#__PURE__*/_react.default.createElement(_iconButton.default, {
      icon: /*#__PURE__*/_react.default.createElement(_icon.default, {
        iconFamily: "AntDesign",
        iconName: "heart"
      }),
      colorScheme: "secondary"
    }))).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(_iconButton.default, {
      onPress: onPress,
      icon: /*#__PURE__*/_react.default.createElement(_icon.default, {
        iconFamily: "AntDesign",
        iconName: "heart"
      }),
      backgroundColor: "primary.500",
      borderColor: "neutral.400",
      borderWidth: 2
    }))).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(_iconButton.default, {
      icon: /*#__PURE__*/_react.default.createElement(_icon.default, {
        iconFamily: "AntDesign",
        iconName: "heart"
      }),
      onPress: onPress,
      testID: "testOnPress"
    })));
    const tree = component.toJSON();
    if (tree.children[0].type !== "RNGestureHandlerButton") {
      const pressableInstance = component.getByTestId("testOnPress");
      _reactNative.fireEvent.press(pressableInstance);
      expect(onPress).toHaveBeenCalledTimes(1);
    }
  });
  it("doesn't capture the onPress event when the button is disabled ", async () => {
    const onPress = jest.fn();
    const component = await (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_themeContext.ThemeProvider, null, /*#__PURE__*/_react.default.createElement(_iconButton.default, {
      icon: /*#__PURE__*/_react.default.createElement(_icon.default, {
        iconFamily: "AntDesign",
        iconName: "heart"
      }),
      onPress: onPress,
      isDisabled: true,
      testID: "testOnPress"
    })));
    const tree = component.toJSON();
    if (tree.children[0].type !== "RNGestureHandlerButton") {
      const pressableInstance = component.getByTestId("testOnPress");
      _reactNative.fireEvent.press(pressableInstance);
      expect(onPress).toHaveBeenCalledTimes(0);
    }
  });
  it("doesn't capture the onPress event when the button is in loading state ", async () => {
    const onPress = jest.fn();
    const component = await (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_themeContext.ThemeProvider, null, /*#__PURE__*/_react.default.createElement(_iconButton.default, {
      icon: /*#__PURE__*/_react.default.createElement(_icon.default, {
        iconFamily: "AntDesign",
        iconName: "heart"
      }),
      onPress: onPress,
      isLoading: true,
      testID: "testOnPress"
    })));
    const tree = component.toJSON();
    if (tree.children[0].type !== "RNGestureHandlerButton") {
      const pressableInstance = component.getByTestId("testOnPress");
      _reactNative.fireEvent.press(pressableInstance);
      expect(onPress).toHaveBeenCalledTimes(0);
    }
  });
});
//# sourceMappingURL=icon-button.spec.js.map