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

var _react2 = require("@testing-library/react");

var _index = _interopRequireDefault(require("../index"));

describe('Affix', function () {
  it('offsetTop', function () {
    var wrapper = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
      offsetTop: 20
    }, /*#__PURE__*/_react.default.createElement("div", null, "Affix Node")));
    expect(wrapper.asFragment()).toMatchSnapshot();
  });
  it('offsetBottom', function () {
    var wrapper = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
      offsetBottom: 20
    }, /*#__PURE__*/_react.default.createElement("div", null, "Affix Node")));
    expect(wrapper.asFragment()).toMatchSnapshot();
  });
  it('getAffixed is true test of offsetTop', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
    var wrapper;
    return _regenerator.default.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            wrapper = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
              offsetTop: 100000
            }, /*#__PURE__*/_react.default.createElement("div", null, "Affix Node")));
            expect(wrapper.asFragment()).toMatchSnapshot();

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  })));
  it('updatePosition when offsetTop changed', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
    var onChange;
    return _regenerator.default.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            onChange = jest.fn();
            jest.useFakeTimers();
            (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
              offsetTop: 0,
              onChange: onChange
            }));
            jest.runAllTimers();

            _react2.fireEvent.scroll(window, {
              target: {
                scrollY: -100
              }
            });

            expect(onChange).toBeCalled();

          case 6:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  })));
});