"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 __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());
  });
};
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("<Snackbar />", () => {
  jest.useRealTimers();
  it("should match snapshot", () => {
    const { container } = (0, import_react2.render)(
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Snackbar, { open: true, message: "Make wellbeing universal", onClose: jest.fn() }) })
    );
    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__.Snackbar,
        {
          open: true,
          message: "Make wellbeing universal",
          onClose: jest.fn(),
          dataTestId: "custom-snackbar"
        }
      ) })
    );
    expect(import_react2.screen.getByTestId("custom-snackbar")).toBeInTheDocument();
  });
  it("should render a minimal snackbar", () => {
    (0, import_react2.render)(
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.Snackbar, { open: true, message: "Make wellbeing universal", onClose: jest.fn() }) })
    );
    import_react2.screen.getByRole("alert");
    import_react2.screen.getByTestId("img");
    import_react2.screen.getByLabelText("success");
    import_react2.screen.getByText("Make wellbeing universal");
  });
  it("should not render an icon", () => {
    (0, import_react2.render)(
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
        import__.Snackbar,
        {
          open: true,
          message: "Make wellbeing universal",
          onClose: jest.fn(),
          hideIcon: true
        }
      ) })
    );
    expect(import_react2.screen.queryByRole("img")).toBeNull();
  });
  it("should render a custom action button", () => {
    const onActionMock = jest.fn();
    (0, import_react2.render)(
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
        import__.Snackbar,
        {
          open: true,
          message: "Make wellbeing universal",
          onAction: onActionMock,
          onClose: jest.fn(),
          actionLabel: "Let's go"
        }
      ) })
    );
    const button = import_react2.screen.getByRole("button", { name: /let's go/i });
    import_react2.fireEvent.click(button);
    expect(onActionMock).toHaveBeenCalledTimes(1);
  });
  it("should render a close button", () => {
    const onCloseMock = jest.fn();
    (0, import_react2.render)(
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
        import__.Snackbar,
        {
          open: true,
          message: "Make wellbeing universal",
          onClose: onCloseMock
        }
      ) })
    );
    const button = import_react2.screen.getByRole("button");
    import_react2.fireEvent.click(button);
    expect(onCloseMock).toHaveBeenCalledTimes(1);
  });
  it("should close after timeout", () => __async(exports, null, function* () {
    jest.useFakeTimers();
    const onCloseMock = jest.fn();
    (0, import_react2.render)(
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
        import__.Snackbar,
        {
          open: true,
          duration: 1e3,
          message: "Make wellbeing universal",
          onClose: onCloseMock,
          hideCloseButton: true
        }
      ) })
    );
    expect(import_react2.screen.queryByRole("button")).toBeNull();
    jest.runAllTimers();
    expect(onCloseMock).toHaveBeenCalledTimes(1);
  }));
  it("should close with timeout set up", () => __async(exports, null, function* () {
    const onCloseMock = jest.fn();
    (0, import_react2.render)(
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
        import__.Snackbar,
        {
          open: true,
          duration: 1e3,
          message: "Make wellbeing universal",
          onClose: onCloseMock
        }
      ) })
    );
    const button = import_react2.screen.getByRole("button");
    import_react2.fireEvent.click(button);
    expect(onCloseMock).toHaveBeenCalledTimes(1);
  }));
});
