import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import '@testing-library/jest-dom';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import React from 'react';
import Modal from '..';
describe('Modal', function () {
  it('renders correctly', function () {
    var props = {
      onMaskClick: jest.fn(),
      onClose: jest.fn(),
      closable: true,
      title: '标题',
      visible: true
    };
    var wrapper = render( /*#__PURE__*/React.createElement(Modal, props, "foo"));
    expect(wrapper.asFragment()).toMatchSnapshot();
  });
  it('onClose', function () {
    var onClose = jest.fn();
    render( /*#__PURE__*/React.createElement(Modal, {
      visible: true,
      title: "\u6807\u9898",
      closable: true,
      onClose: onClose
    }, "\u6A21\u6001\u6846\u5185\u5BB9"));
    var close = document.body.querySelector('.za-modal__close');
    fireEvent.click(close);
    expect(onClose).toBeCalled();
  });
  it('click dialog', function () {
    var onClose = jest.fn();
    render( /*#__PURE__*/React.createElement(Modal, {
      visible: true,
      maskClosable: true,
      onClose: onClose
    }, "foo"));
    var mask = document.body.querySelector('.za-mask');
    fireEvent.click(mask);
    expect(onClose).toBeCalled();
  });
  it('alert', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
    var confirm, _render, getByText;

    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            confirm = jest.fn();
            _render = render( /*#__PURE__*/React.createElement("button", {
              onClick: function onClick() {
                Modal.alert({
                  title: '警告框标题',
                  content: '这里是警告框的内容部分',
                  onConfirm: confirm
                });
              }
            }, "alert")), getByText = _render.getByText;
            fireEvent.click(getByText('alert'));
            _context.next = 5;
            return waitFor(function () {
              screen.getByText('警告框标题');
            });

          case 5:
            expect(getByText('警告框标题')).toBeInTheDocument();
            fireEvent.click(getByText('确定'));
            _context.next = 9;
            return waitFor(function () {
              expect(confirm).toBeCalled();
            });

          case 9:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  })));
  it('alert confirm mock return false', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
    var confirm, _render2, getByText;

    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            confirm = jest.fn().mockReturnValue(false);
            _render2 = render( /*#__PURE__*/React.createElement("button", {
              onClick: function onClick() {
                Modal.alert({
                  title: '警告框标题1',
                  content: '这里是警告框的内容部分',
                  onConfirm: confirm,
                  confirmText: '确定1'
                });
              }
            }, "alert confirm false")), getByText = _render2.getByText;
            fireEvent.click(getByText('alert confirm false'));
            _context2.next = 5;
            return waitFor(function () {
              screen.getByText('警告框标题1');
            });

          case 5:
            fireEvent.click(getByText('确定1'));
            _context2.next = 8;
            return waitFor(function () {
              expect(getByText('警告框标题1')).toBeInTheDocument();
            });

          case 8:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  })));
  it('confirm', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
    var confirm, cancel, _render3, getByText;

    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            confirm = jest.fn();
            cancel = jest.fn();
            _render3 = render( /*#__PURE__*/React.createElement("button", {
              onClick: function onClick() {
                Modal.confirm({
                  title: '确认信息',
                  content: '这里是确认框的内容部分',
                  onConfirm: confirm,
                  onCancel: cancel,
                  confirmText: 'confirm',
                  cancelText: 'cancel'
                });
              }
            }, "modal confirm")), getByText = _render3.getByText;
            fireEvent.click(getByText('modal confirm'));
            _context3.next = 6;
            return waitFor(function () {
              screen.getByText('确认信息');
            });

          case 6:
            fireEvent.click(getByText('confirm'));
            _context3.next = 9;
            return waitFor(function () {
              expect(confirm).toBeCalled();
            });

          case 9:
            fireEvent.click(getByText('cancel'));
            _context3.next = 12;
            return waitFor(function () {
              expect(cancel).toBeCalled();
            });

          case 12:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  })));
  it('confirm onConfirm onCancel return false', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
    var confirm, cancel, fn, _render4, getByText;

    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            confirm = jest.fn().mockReturnValue(false);
            cancel = jest.fn().mockReturnValue(false);
            fn = jest.fn();
            _render4 = render( /*#__PURE__*/React.createElement("button", {
              onClick: /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
                return _regeneratorRuntime.wrap(function _callee4$(_context4) {
                  while (1) {
                    switch (_context4.prev = _context4.next) {
                      case 0:
                        _context4.next = 2;
                        return Modal.confirm({
                          title: '确认信息1',
                          content: '这里是确认框的内容部分1',
                          onConfirm: confirm,
                          onCancel: cancel,
                          confirmText: 'confirm false',
                          cancelText: 'cancel false'
                        });

                      case 2:
                        fn();

                      case 3:
                      case "end":
                        return _context4.stop();
                    }
                  }
                }, _callee4);
              }))
            }, "modal confirm false")), getByText = _render4.getByText;
            fireEvent.click(getByText('modal confirm false'));
            _context5.next = 7;
            return waitFor(function () {
              screen.getByText('确认信息1');
            });

          case 7:
            fireEvent.click(getByText('confirm false'));
            fireEvent.click(getByText('cancel false'));
            _context5.next = 11;
            return waitFor(function () {
              expect(fn).toBeCalledTimes(0);
            });

          case 11:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  })));
});