import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import React from 'react';
import { sleep } from '../../../tests/utils';
import Toast from '../index';

var waitForContentShow = /*#__PURE__*/function () {
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(content) {
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            _context.next = 2;
            return waitFor(function () {
              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__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
    var _render, getByText;

    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            _render = render( /*#__PURE__*/React.createElement("button", {
              onClick: function onClick() {
                Toast.show('content');
              }
            }, "open")), getByText = _render.getByText;
            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__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
    var _render2, getByText;

    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            _render2 = render( /*#__PURE__*/React.createElement("button", {
              onClick: function onClick() {
                Toast.show({
                  icon: 'success',
                  content: 'success'
                });
              }
            }, "open")), getByText = _render2.getByText;
            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__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
    var _render3, getByText;

    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            _render3 = render( /*#__PURE__*/React.createElement("button", {
              onClick: function onClick() {
                Toast.show({
                  icon: 'fail',
                  content: 'fail'
                });
              }
            }, "open")), getByText = _render3.getByText;
            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__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
    var _render4, getByText;

    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            _render4 = render( /*#__PURE__*/React.createElement("button", {
              onClick: function onClick() {
                Toast.show({
                  icon: 'loading',
                  content: 'loading'
                });
              }
            }, "open")), getByText = _render4.getByText;
            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__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
    var _render5, getByText;

    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            _render5 = render( /*#__PURE__*/React.createElement("button", {
              onClick: function onClick() {
                Toast.show({
                  icon: /*#__PURE__*/React.createElement("div", null, "custom icon")
                });
              }
            }, "open")), getByText = _render5.getByText;
            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__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
    var _render6, getByText;

    return _regeneratorRuntime.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            Toast.config({
              duration: 6000
            });
            _render6 = render( /*#__PURE__*/React.createElement("button", {
              onClick: function onClick() {
                Toast.show({
                  icon: 'loading',
                  content: 'loading'
                });
              }
            }, "open")), getByText = _render6.getByText;
            fireEvent.click(getByText('open'));
            _context7.next = 5;
            return sleep(5000);

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

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

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

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

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