"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

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 React = _interopRequireWildcard(require("react"));

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

var _BackTop = _interopRequireDefault(require("../BackTop"));

describe('BackTop', function () {
  it('renders correctly', function () {
    var wrapper = (0, _react.render)( /*#__PURE__*/React.createElement(_BackTop.default, null));
    expect(wrapper.asFragment()).toMatchSnapshot();
  });
  it('should scroll to top after click it', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
    var mockFn, scrollToSpy;
    return _regenerator.default.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            mockFn = jest.fn();
            (0, _react.render)( /*#__PURE__*/React.createElement(_BackTop.default, {
              mountContainer: document.body,
              onClick: mockFn
            }));
            scrollToSpy = jest.spyOn(window, 'scrollTo').mockImplementation(function (_, y) {
              window.scrollY = y;
              window.pageYOffset = y;
              document.documentElement.scrollTop = y;
            }); // jest.spyOn(window, 'requestAnimationFrame').mockImplementation(cb => setTimeout(cb, 0));

            window.scrollTo(0, 500);

            _react.fireEvent.scroll(window, {
              target: {
                y: 500
              }
            });

            (0, _utils.sleep)(5000);

            _react.fireEvent.click(document.body.querySelector('.za-back-top'));

            expect(mockFn).toBeCalled();
            scrollToSpy.mockRestore();

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