"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_react2 = require("@testing-library/react");
var import__ = require("../..");
describe("<Input />", () => {
  describe("Snapshots", () => {
    it("should match with default input", () => {
      const { container } = (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input, {}) })
      );
      expect(container).toMatchSnapshot();
    });
    it("should match with label", () => {
      const { container } = (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input, { label: "Input" }) })
      );
      expect(container).toMatchSnapshot();
    });
    it("should match with disabled input", () => {
      const { container } = (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input, { disabled: true }) })
      );
      expect(container).toMatchSnapshot();
    });
    it("should match with error", () => {
      const { container } = (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input, { error: "Error message" }) })
      );
      expect(container).toMatchSnapshot();
    });
    it("should match with helper text and max length", () => {
      const { container } = (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input, { helper: "Helper text", maxLength: 20 }) })
      );
      expect(container).toMatchSnapshot();
    });
    it("should match with helper text, max length and hideMaxLength", () => {
      const { container } = (0, import_react2.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(container).toMatchSnapshot();
    });
    it("should match with full width", () => {
      const { container } = (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input, { label: "Label", full: true }) })
      );
      expect(container).toMatchSnapshot();
    });
    it("should match with a11yId", () => {
      const { container } = (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input, { label: "Label", a11yId: "id" }) })
      );
      expect(container).toMatchSnapshot();
    });
    it("should match with a11yId and error", () => {
      const { container } = (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input, { label: "Label", a11yId: "id", error: "Error message" }) })
      );
      expect(container).toMatchSnapshot();
    });
    it("should match with includeAriaAttributes set to false", () => {
      const { container } = (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input, { label: "Label", includeAriaAttributes: false }) })
      );
      expect(container).toMatchSnapshot();
    });
    it("should render with custom dataTestId", () => {
      (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input, { label: "Input", "data-testid": "custom-input" }) })
      );
      expect(import_react2.screen.getByTestId("custom-input")).toBeInTheDocument();
    });
  });
  describe("Events", () => {
    it("should call onChange", () => {
      const onChangeMock = jest.fn();
      (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
          import__.Input,
          {
            label: "Input",
            onChange: onChangeMock,
            "data-testid": "input-test"
          }
        ) })
      );
      import_react2.fireEvent.change(import_react2.screen.getByTestId("input-test"), {
        target: { value: "foo" }
      });
      expect(onChangeMock).toHaveBeenCalled();
    });
    it("should call onFocus", () => {
      const onFocusMock = jest.fn();
      (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input, { label: "Input", "data-testid": "input", onFocus: onFocusMock }) })
      );
      import_react2.fireEvent.focus(import_react2.screen.getByTestId("input"));
      expect(onFocusMock).toHaveBeenCalled();
    });
    it("should call onBlur", () => {
      const onBlurMock = jest.fn();
      (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input, { label: "Input", "data-testid": "input-test", onBlur: onBlurMock }) })
      );
      import_react2.fireEvent.focus(import_react2.screen.getByTestId("input-test"));
      import_react2.fireEvent.blur(import_react2.screen.getByTestId("input-test"));
      expect(onBlurMock).toHaveBeenCalled();
    });
  });
  describe("maxLength", () => {
    it("should update maxLength counter when add character", () => {
      const { rerender } = (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input, { label: "Input", maxLength: 10 }) })
      );
      expect(import_react2.screen.getByText("0/10").textContent).toBe("0/10");
      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(import_react2.screen.getByText("3/10").textContent).toBe("3/10");
    });
  });
  describe("clean button", () => {
    it("should call onClean when press clean button", () => {
      const onClean = jest.fn();
      (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input, { label: "Input", value: "foo", onClean }) })
      );
      import_react2.fireEvent.click(import_react2.screen.queryByRole("button"));
      expect(onClean).toHaveBeenCalled();
    });
    it("should test if clean button is present", () => {
      const { rerender } = (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input, { label: "Input", ariaLabel: "valor aria label" }) })
      );
      expect(import_react2.screen.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(import_react2.screen.queryByRole("button")).not.toBeNull();
    });
    it("should have aria-label", () => {
      const value = "aria label value";
      const { getByTestId } = (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
          import__.Input,
          {
            label: "Input",
            value: "foo",
            ariaLabel: value,
            "data-testid": "input-test"
          }
        ) })
      );
      const inputElement = getByTestId("input-test");
      expect(inputElement).toBeInTheDocument();
      expect(inputElement).toHaveAttribute("aria-label", value);
    });
    it("should have label value", () => {
      const value = "label value";
      const { getByTestId } = (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input, { label: value, value: "foo", "data-testid": "input-test" }) })
      );
      const inputElement = getByTestId("input-test");
      expect(inputElement).toBeInTheDocument();
      expect(inputElement).toHaveAttribute("aria-label", value);
    });
    it("should have close aria label", () => {
      const value = "test label clear";
      const { getByTestId } = (0, import_react2.render)(
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Input, { label: "abc123", value: "foo", clearButtonAriaLabel: value }) })
      );
      const inputElement = getByTestId("clearButtonAriaLabel");
      expect(inputElement).toBeInTheDocument();
      expect(inputElement).toHaveAttribute("aria-label", value);
    });
  });
});
