import { jsx } from "react/jsx-runtime";
import React from "react";
import { render, fireEvent } from "@testing-library/react";
import { ThemeProvider, Input } from "../..";
describe("<Input.Password />", () => {
  describe("Snapshots", () => {
    it("should match with default input", () => {
      const { container } = render(
        /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(Input.Password, {}) })
      );
      expect(container).toMatchSnapshot();
    });
    it("should match with disabled input", () => {
      const { container } = render(
        /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(Input.Password, { disabled: true }) })
      );
      expect(container).toMatchSnapshot();
    });
    it("should match with full width", () => {
      const { container } = render(
        /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(Input.Password, { label: "Label", full: true }) })
      );
      expect(container).toMatchSnapshot();
    });
  });
  describe("Events", () => {
    it("should call onChange", () => {
      const onChangeMock = jest.fn();
      const { getByTestId } = render(
        /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(
          Input.Password,
          {
            label: "Input",
            "data-testid": "input",
            onChange: onChangeMock
          }
        ) })
      );
      fireEvent.change(getByTestId("input"), { target: { value: "foo" } });
      expect(onChangeMock).toHaveBeenCalled();
    });
    it("should call onFocus", () => {
      const onFocusMock = jest.fn();
      const { getByTestId } = render(
        /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(
          Input.Password,
          {
            label: "Input",
            "data-testid": "input",
            onFocus: onFocusMock
          }
        ) })
      );
      fireEvent.focus(getByTestId("input"));
      expect(onFocusMock).toHaveBeenCalled();
    });
    it("should call onBlur", () => {
      const onBlurMock = jest.fn();
      const { getByTestId } = render(
        /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(
          Input.Password,
          {
            label: "Input",
            "data-testid": "input",
            onBlur: onBlurMock
          }
        ) })
      );
      fireEvent.focus(getByTestId("input"));
      fireEvent.blur(getByTestId("input"));
      expect(onBlurMock).toHaveBeenCalled();
    });
  });
  describe("visibility button", () => {
    it("should toggle password visibility when click visibility button", () => {
      const { getByRole, getByTestId } = render(
        /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(Input.Password, { label: "Input", "data-testid": "input" }) })
      );
      expect(getByTestId("input").type).toBe("password");
      fireEvent.click(getByRole("button"));
      expect(getByTestId("input").type).toBe("text");
    });
  });
});
