var __getOwnPropNames = Object.getOwnPropertyNames;
var __commonJS = (cb, mod) => function __require() {
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __async = (__this, __arguments, generator) => {
  return new Promise((resolve, reject) => {
    var fulfilled = (value) => {
      try {
        step(generator.next(value));
      } catch (e) {
        reject(e);
      }
    };
    var rejected = (value) => {
      try {
        step(generator.throw(value));
      } catch (e) {
        reject(e);
      }
    };
    var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
    step((generator = generator.apply(__this, __arguments)).next());
  });
};
import { jsx } from "react/jsx-runtime";
import React from "react";
import { render, fireEvent, waitFor } from "@testing-library/react";
import { ThemeProvider, Input } from "../..";
var require_Phone_test = __commonJS({
  "src/Input/web/Phone.test.jsx"(exports) {
    const numbersFormats = [
      {
        country: "BR",
        base: "+5511959112508",
        expected: "+55 (11) 959112508"
      },
      {
        country: "US",
        base: "+12025550134",
        expected: "+1 (202) 555-0134"
      },
      {
        country: "PT",
        base: "+351911803423",
        expected: "+351 911 803 423"
      }
    ];
    describe("<Input.Phone />", () => {
      describe("Snapshots", () => {
        it("should match with default input", () => {
          const { container } = render(
            /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(Input.Phone, {}) })
          );
          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 error", () => {
          const { container } = render(
            /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(Input, { error: "Error message" }) })
          );
          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("Behaviour", () => {
        numbersFormats.forEach((spec) => {
          it(`Should render number in ${spec.country} format according to phone value`, () => {
            const { getByDisplayValue } = render(
              /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(Input.Phone, { value: spec.base }) })
            );
            expect(getByDisplayValue(spec.expected)).toBeInTheDocument();
          });
        });
        it(`Should only format and show countries numbers when props is given`, () => {
          const USPhone = numbersFormats[1];
          const { queryByDisplayValue } = render(
            /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(Input.Phone, { countries: ["br", "pt"], value: USPhone.base }) })
          );
          expect(queryByDisplayValue(USPhone.expected)).not.toBeInTheDocument();
        });
        it(`Should return all countries validation if countries equals to empty array`, () => {
          const USPhone = numbersFormats[1];
          const { getAllByRole } = render(
            /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(Input.Phone, { countries: [], value: USPhone.base }) })
          );
          fireEvent.click(getAllByRole("button")[0]);
          expect(getAllByRole("option").length).toBe(13);
        });
        it(`Should call onblur event`, () => {
          const USPhone = numbersFormats[1];
          const onBlur = jest.fn();
          const { getAllByRole } = render(
            /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(Input.Phone, { onBlur, countries: [], value: USPhone.base }) })
          );
          const inputPhone = getAllByRole("textbox")[0];
          fireEvent.blur(inputPhone);
          expect(onBlur).toHaveBeenCalled();
        });
        it("should prefix the phone number with newly selected country dial code", () => __async(exports, null, function* () {
          const { getByRole, getByText, getByDisplayValue } = render(
            /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(Input.Phone, { defaultCountry: "us" }) })
          );
          yield waitFor(() => {
            fireEvent.click(getByRole("button"));
            fireEvent.click(getByText("Portugal"));
          });
          expect(getByDisplayValue("+351")).toBeInTheDocument();
        }));
      });
    });
  }
});
export default require_Phone_test();
