"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));

var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));

var _react = require("@testing-library/react");

var _react2 = _interopRequireDefault(require("react"));

var _utils = require("../../../tests/utils");

var _index = _interopRequireDefault(require("../index"));

var waitForContentShow = /*#__PURE__*/function () {
  var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(content) {
    return _regenerator.default.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            _context.next = 2;
            return (0, _react.waitFor)(function () {
              _react.screen.getByText(content);
            });

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));

  return function waitForContentShow(_x) {
    return _ref.apply(this, arguments);
  };
}();

describe('Toast', function () {
  test('string', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
    var _render, getByText;

    return _regenerator.default.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            _render = (0, _react.render)( /*#__PURE__*/_react2.default.createElement("button", {
              onClick: function onClick() {
                _index.default.show('content');
              }
            }, "open")), getByText = _render.getByText;

            _react.fireEvent.click(getByText('open'));

            _context2.next = 4;
            return waitForContentShow('content');

          case 4:
            expect(getByText('content')).toBeInTheDocument();

          case 5:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  })));
  test('with icon success', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
    var _render2, getByText;

    return _regenerator.default.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            _render2 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement("button", {
              onClick: function onClick() {
                _index.default.show({
                  icon: 'success',
                  content: 'success'
                });
              }
            }, "open")), getByText = _render2.getByText;

            _react.fireEvent.click(getByText('open'));

            _context3.next = 4;
            return waitForContentShow('success');

          case 4:
            expect(getByText('success')).toBeInTheDocument();

          case 5:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  })));
  test('with icon fail', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4() {
    var _render3, getByText;

    return _regenerator.default.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            _render3 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement("button", {
              onClick: function onClick() {
                _index.default.show({
                  icon: 'fail',
                  content: 'fail'
                });
              }
            }, "open")), getByText = _render3.getByText;

            _react.fireEvent.click(getByText('open'));

            _context4.next = 4;
            return waitForContentShow('fail');

          case 4:
            expect(getByText('fail')).toBeInTheDocument();

          case 5:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  })));
  test('with icon loading', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5() {
    var _render4, getByText;

    return _regenerator.default.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            _render4 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement("button", {
              onClick: function onClick() {
                _index.default.show({
                  icon: 'loading',
                  content: 'loading'
                });
              }
            }, "open")), getByText = _render4.getByText;

            _react.fireEvent.click(getByText('open'));

            _context5.next = 4;
            return waitForContentShow('loading');

          case 4:
            expect(getByText('loading')).toBeInTheDocument();

          case 5:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  })));
  test('custom icon', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6() {
    var _render5, getByText;

    return _regenerator.default.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            _render5 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement("button", {
              onClick: function onClick() {
                _index.default.show({
                  icon: /*#__PURE__*/_react2.default.createElement("div", null, "custom icon")
                });
              }
            }, "open")), getByText = _render5.getByText;

            _react.fireEvent.click(getByText('open'));

            _context6.next = 4;
            return waitForContentShow('custom icon');

          case 4:
            expect(getByText('custom icon')).toBeInTheDocument();

          case 5:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  })));
  test('config', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee7() {
    var _render6, getByText;

    return _regenerator.default.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            _index.default.config({
              duration: 6000
            });

            _render6 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement("button", {
              onClick: function onClick() {
                _index.default.show({
                  icon: 'loading',
                  content: 'loading'
                });
              }
            }, "open")), getByText = _render6.getByText;

            _react.fireEvent.click(getByText('open'));

            _context7.next = 5;
            return (0, _utils.sleep)(5000);

          case 5:
            expect(getByText('loading')).toBeInTheDocument();

          case 6:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7);
  })));
  test('clear', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee8() {
    var _render7, getByText;

    return _regenerator.default.wrap(function _callee8$(_context8) {
      while (1) {
        switch (_context8.prev = _context8.next) {
          case 0:
            _render7 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement("div", null, /*#__PURE__*/_react2.default.createElement("button", {
              onClick: function onClick() {
                // Toast.show({ icon: 'loading', content: 'loading-clear' });
                _index.default.show({
                  icon: 'success',
                  content: 'success-clear',
                  className: 'clear-test'
                });
              }
            }, "open-clear"), /*#__PURE__*/_react2.default.createElement("button", {
              onClick: function onClick() {
                // Toast.show({ icon: 'loading', content: 'loading-clear' });
                _index.default.clear();
              }
            }, "clear"))), getByText = _render7.getByText;

            _react.fireEvent.click(getByText('open-clear'));

            _context8.next = 4;
            return waitForContentShow('success-clear');

          case 4:
            _react.fireEvent.click(getByText('clear'));

          case 5:
          case "end":
            return _context8.stop();
        }
      }
    }, _callee8);
  })));
});