import { jsx } from "react/jsx-runtime";
import React from "react";
import { render, fireEvent } from "@testing-library/react-native";
import { ThemeProvider, Input } from "../..";
describe("<Input.Password />", () => {
  describe("Snapshots", () => {
    it("should match with default input", () => {
      const { toJSON } = render(
        /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(Input.Password, {}) })
      );
      expect(toJSON()).toMatchSnapshot();
    });
    it("should match when input is focused", () => {
      const { toJSON, getByTestId } = render(
        /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(Input.Password, { label: "Input", testID: "input" }) })
      );
      fireEvent(getByTestId("input"), "focus");
      expect(toJSON()).toMatchSnapshot();
    });
    it("should match with disabled input", () => {
      const { toJSON } = render(
        /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(Input.Password, { disabled: true }) })
      );
      expect(toJSON()).toMatchSnapshot();
    });
    it("should match with full width", () => {
      const { toJSON } = render(
        /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(Input.Password, { label: "Label", full: true }) })
      );
      expect(toJSON()).toMatchSnapshot();
    });
  });
  describe("Events", () => {
    it("should call onChangeText", () => {
      const onChangeTextMock = jest.fn();
      const { getByTestId } = render(
        /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(
          Input.Password,
          {
            label: "Input",
            testID: "input",
            onChangeText: onChangeTextMock
          }
        ) })
      );
      fireEvent.changeText(getByTestId("input"), "foo");
      expect(onChangeTextMock).toHaveBeenCalled();
    });
    it("should not call onChangeText when input is readOnly", () => {
      const onChangeTextMock = jest.fn();
      const { getByTestId } = render(
        /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(
          Input.Password,
          {
            label: "Input",
            testID: "input",
            onChangeText: onChangeTextMock,
            readOnly: true
          }
        ) })
      );
      fireEvent(getByTestId("input"), "focus");
      expect(onChangeTextMock).not.toHaveBeenCalled();
    });
    it("should not call onChangeText when input is disabled", () => {
      const onChangeTextMock = jest.fn();
      const { getByTestId } = render(
        /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(
          Input.Password,
          {
            label: "Input",
            testID: "input",
            onChangeText: onChangeTextMock,
            disabled: true
          }
        ) })
      );
      fireEvent(getByTestId("input"), "focus");
      expect(onChangeTextMock).not.toHaveBeenCalled();
    });
    it("should call onFocus", () => {
      const onFocusMock = jest.fn();
      const { getByTestId } = render(
        /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(Input.Password, { label: "Input", testID: "input", onFocus: onFocusMock }) })
      );
      fireEvent(getByTestId("input"), "focus");
      expect(onFocusMock).toHaveBeenCalled();
    });
    it("should call onBlur", () => {
      const onBlurMock = jest.fn();
      const { getByTestId } = render(
        /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(Input.Password, { label: "Input", testID: "input", onBlur: onBlurMock }) })
      );
      fireEvent(getByTestId("input"), "focus");
      fireEvent(getByTestId("input"), "blur");
      expect(onBlurMock).toHaveBeenCalled();
    });
  });
  describe("visibility button", () => {
    it("should toggle password visibility when press visibility button", () => {
      const { getByRole, getByTestId } = render(
        /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(Input.Password, { label: "Input", testID: "input" }) })
      );
      expect(getByTestId("input").props.secureTextEntry).toBe(true);
      fireEvent.press(getByRole("button"));
      expect(getByTestId("input").props.secureTextEntry).toBe(false);
    });
  });
});
