import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import { fireEvent, render, waitFor } from '@testing-library/react';
import React from 'react';
import Popper from '../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 = render( /*#__PURE__*/React.createElement(Popper, {
      content: "\u6807\u9898",
      onVisibleChange: onVisibleChange
    }, /*#__PURE__*/React.createElement("p", null, "\u70B9\u6211"))),
        container = _render.container;

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

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

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

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

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

    var wrapper = getByTestId('za-popper-hasArrow');
    var elments = [].slice.call(wrapper.getElementsByClassName('hello'));
    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__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
    var onVisibleChange, _render5, getByTestId, wrapper, elments;

    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            onVisibleChange = jest.fn();
            _render5 = render( /*#__PURE__*/React.createElement("div", {
              "data-testid": "za-popper-onVisibleChange"
            }, /*#__PURE__*/React.createElement(Popper, {
              trigger: "click",
              content: "fsdfds",
              mouseEnterDelay: 0,
              mouseLeaveDelay: 0,
              onVisibleChange: onVisibleChange
            }, /*#__PURE__*/React.createElement("div", {
              className: "hello"
            }, "Hello world!")))), getByTestId = _render5.getByTestId;
            wrapper = getByTestId('za-popper-onVisibleChange');
            elments = [].slice.call(wrapper.getElementsByClassName('hello'));
            fireEvent.click(elments === null || elments === void 0 ? void 0 : elments[0]);
            _context.next = 7;
            return waitFor(function () {
              expect(onVisibleChange).toBeCalled();
            });

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