"use strict";

var _react = _interopRequireDefault(require("react"));
var _input = _interopRequireDefault(require("./input"));
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/Input", () => {
  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(_input.default, {
      placeholder: "This is a placeholder"
    }))).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(_input.default, {
      size: "xs"
    }), /*#__PURE__*/_react.default.createElement(_input.default, {
      size: "s"
    }), /*#__PURE__*/_react.default.createElement(_input.default, {
      size: "m"
    }), /*#__PURE__*/_react.default.createElement(_input.default, {
      size: "l"
    }))).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(_input.default, {
      variant: "filled"
    }), /*#__PURE__*/_react.default.createElement(_input.default, {
      variant: "outline"
    }))).toJSON();
    expect(tree).toMatchSnapshot();
  });

  // it("updates styles correctly when in an error state ", async () => {
  //   const errorBackgroundColor = "neutral.50";
  //   const errorBorderColor = "danger.800";

  //   const { getByTestId } = render(
  //     <ThemeProvider>
  //       <Input
  //         testID="inputField"
  //         isInvalid
  //         errorBackgroundColor={errorBackgroundColor}
  //         errorBorderColor={errorBorderColor}
  //       />
  //     </ThemeProvider>
  //   );

  //   const inputContainer = getByTestId("inputFieldContainer");
  //   expect(inputContainer.props.style.borderColor).toEqual(
  //     (baseTheme.palette.danger as any)["800"]
  //   );
  //   expect(inputContainer.props.style.backgroundColor).toEqual(
  //     (baseTheme.palette.neutral as any)["50"]
  //   );
  // });

  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(_input.default, {
      leftIcon: /*#__PURE__*/_react.default.createElement(_icon.default, {
        iconFamily: "AntDesign",
        iconName: "heart"
      })
    }), /*#__PURE__*/_react.default.createElement(_input.default, {
      variant: "outline",
      rightIcon: /*#__PURE__*/_react.default.createElement(_icon.default, {
        iconFamily: "AntDesign",
        iconName: "cloudupload"
      })
    }))).toJSON();
    expect(tree).toMatchSnapshot();
  });
  it("passes the snapshot test when using style props", async () => {
    const tree = await (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_themeContext.ThemeProvider, null, /*#__PURE__*/_react.default.createElement(_input.default, {
      backgroundColor: "primary.500",
      borderColor: "neutral.400",
      borderWidth: 2,
      isFullWidth: true,
      placeholderTextColor: undefined
    }))).toJSON();
    expect(tree).toMatchSnapshot();
  });
  it("captures onChangeText event correctly", () => {
    const value = "start value";
    const onChangeText = jest.fn();
    const {
      getByTestId
    } = (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_themeContext.ThemeProvider, null, /*#__PURE__*/_react.default.createElement(_input.default, {
      placeholder: "Enter value",
      onChangeText: onChangeText,
      value: value,
      testID: "inputField"
    })));
    const input = getByTestId("inputField");
    _reactNative.fireEvent.changeText(input, "new value");
    expect(onChangeText).toBeCalledWith("new value");
  });
  it("doesn't update value when the input is disabled ", async () => {
    const onChangeText = jest.fn();
    const {
      getByTestId,
      queryByText
    } = await (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_themeContext.ThemeProvider, null, /*#__PURE__*/_react.default.createElement(_input.default, {
      onChangeText: onChangeText,
      isDisabled: true,
      testID: "inputField"
    })));
    const input = getByTestId("inputField");
    _reactNative.fireEvent.changeText(input, "new value");
    expect(queryByText("new value")).toBeNull();
  });
});
//# sourceMappingURL=input.spec.js.map