"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 _index = _interopRequireDefault(require("../index"));

if (global.document) {
  document.createRange = function () {
    return {
      setStart: function setStart() {},
      setEnd: function setEnd() {},
      // @ts-ignore
      commonAncestorContainer: {
        nodeName: 'BODY',
        ownerDocument: document
      }
    };
  };
}

window.ResizeObserver = window.ResizeObserver || jest.fn().mockImplementation(function () {
  return {
    disconnect: jest.fn(),
    observe: jest.fn(),
    unobserve: jest.fn()
  };
});
describe('Popper', function () {
  it('renders correctly', function () {
    var onVisibleChange = jest.fn();

    var _render = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_index.default, {
      content: "\u6807\u9898",
      onVisibleChange: onVisibleChange
    }, /*#__PURE__*/_react2.default.createElement("p", null, "\u70B9\u6211"))),
        container = _render.container;

    expect(container).toMatchSnapshot();
  });
  it('renders menu-slide', function () {
    var onVisibleChange = jest.fn();

    var _render2 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_index.default, {
      content: "\u6807\u9898",
      onVisibleChange: onVisibleChange,
      animationType: "menu-slide"
    }, /*#__PURE__*/_react2.default.createElement("p", null, "\u70B9\u6211"))),
        container = _render2.container;

    expect(container).toMatchSnapshot();
  });
  it('renders menu-slide bottom', function () {
    var onVisibleChange = jest.fn();

    var _render3 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_index.default, {
      content: "\u6807\u9898",
      onVisibleChange: onVisibleChange,
      animationType: "menu-slide",
      direction: "bottom"
    }, /*#__PURE__*/_react2.default.createElement("p", null, "\u70B9\u6211"))),
        container = _render3.container;

    expect(container).toMatchSnapshot();
  });
  it('check hasArrow prop', function () {
    var _render4 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement("div", {
      "data-testid": "za-popper-hasArrow"
    }, /*#__PURE__*/_react2.default.createElement(_index.default, {
      trigger: "click",
      hasArrow: false,
      content: "fdsfsd",
      mouseEnterDelay: 0,
      mouseLeaveDelay: 0
    }, /*#__PURE__*/_react2.default.createElement("div", {
      className: "hello"
    }, "Hello world!")), ",")),
        getByTestId = _render4.getByTestId;

    var wrapper = getByTestId('za-popper-hasArrow');
    var elments = [].slice.call(wrapper.getElementsByClassName('hello'));

    _react.fireEvent.click(elments === null || elments === void 0 ? void 0 : elments[0]);

    expect(wrapper.getElementsByClassName('.za-popper__arrow')).not.toHaveLength(1);
  });
  it('check onVisibleChange func prop', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
    var onVisibleChange, _render5, getByTestId, wrapper, elments;

    return _regenerator.default.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            onVisibleChange = jest.fn();
            _render5 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement("div", {
              "data-testid": "za-popper-onVisibleChange"
            }, /*#__PURE__*/_react2.default.createElement(_index.default, {
              trigger: "click",
              content: "fsdfds",
              mouseEnterDelay: 0,
              mouseLeaveDelay: 0,
              onVisibleChange: onVisibleChange
            }, /*#__PURE__*/_react2.default.createElement("div", {
              className: "hello"
            }, "Hello world!")))), getByTestId = _render5.getByTestId;
            wrapper = getByTestId('za-popper-onVisibleChange');
            elments = [].slice.call(wrapper.getElementsByClassName('hello'));

            _react.fireEvent.click(elments === null || elments === void 0 ? void 0 : elments[0]);

            _context.next = 7;
            return (0, _react.waitFor)(function () {
              expect(onVisibleChange).toBeCalled();
            });

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