"use strict";

require("@testing-library/jest-dom");
var _react = require("@testing-library/react");
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
var _Button = _interopRequireWildcard(require("../Button"));
var _jsxRuntime = require("react/jsx-runtime");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
describe('Button Specs', function () {
  test('should have `disabled` HTML attribute when `disabled` prop is provided', function () {
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button["default"], {
      disabled: true,
      children: "I am a disabled Button"
    }));
    var button = _react.screen.getByRole('button');
    expect(button).toHaveAttribute('disabled');
  });
  test('should have default `minWidth`', function () {
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.ButtonBase, {}));
    var button = _react.screen.getByRole('button');
    var expected = 'minWidth';
    expect(button).toHaveClass(expected);
  });
  test('should have default `size` `large`', function () {
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.ButtonBase, {}));
    var button = _react.screen.getByRole('button');
    var expected = 'large';
    expect(button).toHaveClass(expected);
  });
  test('should have `joinedCenter` class', function () {
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.ButtonBase, {
      joinedPosition: "center"
    }));
    var button = _react.screen.getByRole('button');
    var expected = 'joinedCenter';
    expect(button).toHaveClass(expected);
  });
  test('should have `grid` class', function () {
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.ButtonBase, {
      type: "grid"
    }));
    var button = _react.screen.getByRole('button');
    var expected = 'grid';
    expect(button).toHaveClass(expected);
  });
  describe('with no `minWidth`', function () {
    test('should not have `minWidth` class', function () {
      (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.ButtonBase, {
        minWidth: false
      }));
      var button = _react.screen.getByRole('button');
      var expected = 'minWidth';
      expect(button).not.toHaveClass(expected);
    });
  });
  describe('with `transparent` `backgroundOpacity`', function () {
    test('should have `transparent` class', function () {
      (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.ButtonBase, {
        backgroundOpacity: "transparent"
      }));
      var button = _react.screen.getByRole('button');
      var expected = 'transparent';
      expect(button).toHaveClass(expected);
    });
  });
  describe('with icon', function () {
    test('should have `check` icon when specified', function () {
      (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button["default"], {
        icon: "check",
        children: "abc"
      }));
      var icon = _react.screen.getByText('✓');
      expect(icon).toBeInTheDocument();
      expect(icon).toHaveClass('icon');
    });
    test('should have `iconOnly` class', function () {
      (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button["default"], {
        icon: "check"
      }));
      var button = _react.screen.getByRole('button');
      expect(button).toHaveClass('iconOnly');
    });
    test('should have `iconAfter` class with text and icon', function () {
      (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button["default"], {
        icon: "check",
        iconPosition: "after",
        children: "text"
      }));
      var button = _react.screen.getByRole('button');
      var expected = 'iconAfter';
      expect(button).toHaveClass(expected);
    });
    test('should have `iconBefore` class with text and icon', function () {
      (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button["default"], {
        icon: "check",
        iconPosition: "before",
        children: "text"
      }));
      var button = _react.screen.getByRole('button');
      var expected = 'iconBefore';
      expect(button).toHaveClass(expected);
    });
  });
  describe('with badge', function () {
    test('should have `badge` with text="1"', function () {
      (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button["default"], {
        badge: "1",
        badgeColor: "#986AAD",
        children: "text"
      }));
      var badge = _react.screen.getByRole('button').children[0].children[0];
      var badgeText = _react.screen.getByText('1');
      var expected = 'badge';
      expect(badge).toHaveClass(expected);
      expect(badgeText).toBeInTheDocument();
    });
  });
  describe('events', function () {
    test('should call onClick when not disabled', /*#__PURE__*/_asyncToGenerator(function* () {
      var handleClick = jest.fn();
      var user = _userEvent["default"].setup();
      (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button["default"], {
        onClick: handleClick,
        children: "I am not a disabled Button"
      }));
      var button = _react.screen.getByText('I am not a disabled Button');
      yield user.click(button);
      expect(handleClick).toBeCalled();
    }));
    test('should not call onClick when disabled', /*#__PURE__*/_asyncToGenerator(function* () {
      var handleClick = jest.fn();
      var user = _userEvent["default"].setup();
      (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button["default"], {
        disabled: true,
        onClick: handleClick,
        children: "I am a disabled Button"
      }));
      var button = _react.screen.getByText('I am a disabled Button');
      yield user.click(button);
      expect(handleClick).not.toBeCalled();
    }));
  });
});