"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_react_native = require("@testing-library/react-native");
var import__ = require("../..");
describe("<Input />", () => {
  describe("Snapshots", () => {
    it("should match with default input", () => {
      const { toJSON } = (0, import_react_native.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input, {}) })
      );
      expect(toJSON()).toMatchSnapshot();
    });
    it("should match with label", () => {
      const { toJSON } = (0, import_react_native.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input, { label: "Input" }) })
      );
      expect(toJSON()).toMatchSnapshot();
    });
    it("should match when input is focused", () => {
      const { toJSON, getByTestId } = (0, import_react_native.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input, { label: "Input", testID: "input-test" }) })
      );
      (0, import_react_native.fireEvent)(getByTestId("input-test"), "focus");
      expect(toJSON()).toMatchSnapshot();
    });
    it("should match with disabled input", () => {
      const { toJSON } = (0, import_react_native.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input, { disabled: true }) })
      );
      expect(toJSON()).toMatchSnapshot();
    });
    it("should match with error", () => {
      const { toJSON } = (0, import_react_native.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input, { error: "Error message" }) })
      );
      expect(toJSON()).toMatchSnapshot();
    });
    it("should match with helper text and max length", () => {
      const { toJSON } = (0, import_react_native.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input, { helper: "Helper text", maxLength: 20 }) })
      );
      expect(toJSON()).toMatchSnapshot();
    });
    it("should match with helper text, max length and hideMaxLength", () => {
      const { toJSON } = (0, import_react_native.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input, { helper: "Helper text", maxLength: 20, hideMaxLength: true }) })
      );
      expect(toJSON()).toMatchSnapshot();
    });
    it("should match with full width", () => {
      const { toJSON } = (0, import_react_native.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input, { label: "Label", full: true }) })
      );
      expect(toJSON()).toMatchSnapshot();
    });
  });
  describe("Events", () => {
    it("should call onChangeText", () => {
      const onChangeTextMock = jest.fn();
      const { getByTestId } = (0, import_react_native.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
          import__.Input,
          {
            label: "Input",
            testID: "input-test",
            onChangeText: onChangeTextMock
          }
        ) })
      );
      import_react_native.fireEvent.changeText(getByTestId("input-test"), "foo");
      expect(onChangeTextMock).toHaveBeenCalled();
    });
    it("should not call onChangeText when input is disabled", () => {
      const onChangeTextMock = jest.fn();
      const { getByTestId } = (0, import_react_native.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
          import__.Input,
          {
            label: "Input",
            testID: "input-test",
            onChangeText: onChangeTextMock,
            disabled: true
          }
        ) })
      );
      (0, import_react_native.fireEvent)(getByTestId("input-test"), "focus");
      expect(onChangeTextMock).not.toHaveBeenCalled();
    });
    it("should call onFocus", () => {
      const onFocusMock = jest.fn();
      const { getByTestId } = (0, import_react_native.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input, { label: "Input", testID: "input-test", onFocus: onFocusMock }) })
      );
      (0, import_react_native.fireEvent)(getByTestId("input-test"), "focus");
      expect(onFocusMock).toHaveBeenCalled();
    });
    it("should call onBlur", () => {
      const onBlurMock = jest.fn();
      const { getByTestId } = (0, import_react_native.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input, { label: "Input", testID: "input-test", onBlur: onBlurMock }) })
      );
      (0, import_react_native.fireEvent)(getByTestId("input-test"), "focus");
      (0, import_react_native.fireEvent)(getByTestId("input-test"), "blur");
      expect(onBlurMock).toHaveBeenCalled();
    });
  });
  describe("maxLength", () => {
    it("should update maxLength counter when add character", () => {
      const { getByText, rerender } = (0, import_react_native.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input, { label: "Input", maxLength: 10 }) })
      );
      expect(getByText("0/10")).toBeTruthy();
      rerender(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input, { label: "Input", value: "foo", maxLength: 10 }) })
      );
      expect(getByText("3/10")).toBeTruthy();
    });
  });
  describe("clean button", () => {
    it("should call onClean when press clean button", () => {
      const onCleanMock = jest.fn();
      const { getByRole } = (0, import_react_native.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input, { label: "Input", value: "foo", onClean: onCleanMock }) })
      );
      import_react_native.fireEvent.press(getByRole("button"));
      expect(onCleanMock).toHaveBeenCalledWith("");
    });
    it("should test if clean button is present", () => {
      const { rerender, queryByRole } = (0, import_react_native.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input, { label: "Input" }) })
      );
      expect(queryByRole("button")).toBeNull();
      rerender(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input, { label: "Input", value: "foo" }) })
      );
      expect(queryByRole("button")).not.toBeNull();
    });
  });
});
