import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import { fireEvent, render } from '@testing-library/react';
import * as React from 'react';
import { sleep } from '../../../tests/utils';
import BackTop from '../BackTop';
describe('BackTop', function () {
  it('renders correctly', function () {
    var wrapper = render( /*#__PURE__*/React.createElement(BackTop, null));
    expect(wrapper.asFragment()).toMatchSnapshot();
  });
  it('should scroll to top after click it', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
    var mockFn, scrollToSpy;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            mockFn = jest.fn();
            render( /*#__PURE__*/React.createElement(BackTop, {
              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);
            fireEvent.scroll(window, {
              target: {
                y: 500
              }
            });
            sleep(5000);
            fireEvent.click(document.body.querySelector('.za-back-top'));
            expect(mockFn).toBeCalled();
            scrollToSpy.mockRestore();

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