"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 _unit = require("../../../utils/test-utils/unit");
var _ScrollableContainerUni = require("../ScrollableContainer.uni.driver");
var _ScrollableContainer = _interopRequireDefault(require("../ScrollableContainer"));
var _scrollAreaLogic = require("../scrollAreaLogic");
var _index = require("../index");
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/common/ScrollableContainer/test/ScrollableContainer.spec.jsx",
  _this = void 0;
describe('ScrollableContainer', function () {
  var render = (0, _unit.createRendererWithUniDriver)(_ScrollableContainerUni.scrollableContainerDriverFactory);
  afterEach(_unit.cleanup);
  it('should render the provided children', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee() {
    var children, _render, driver;
    return _regenerator["default"].wrap(function _callee$(_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          children = /*#__PURE__*/_react["default"].createElement("div", {
            "data-hook": "children",
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 17,
              columnNumber: 22
            }
          });
          _render = render(/*#__PURE__*/_react["default"].createElement(_ScrollableContainer["default"], {
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 19,
              columnNumber: 7
            }
          }, children)), driver = _render.driver;
          _context.t0 = expect;
          _context.next = 5;
          return driver.childExists('children');
        case 5:
          _context.t1 = _context.sent;
          (0, _context.t0)(_context.t1).toBe(true);
        case 7:
        case "end":
          return _context.stop();
      }
    }, _callee);
  })));
  it('should call the `onScrollAreaChanged` method after container was mounted ', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2() {
    var onScrollAreaChangedSpy;
    return _regenerator["default"].wrap(function _callee2$(_context2) {
      while (1) switch (_context2.prev = _context2.next) {
        case 0:
          onScrollAreaChangedSpy = vi.fn();
          render(/*#__PURE__*/_react["default"].createElement(_ScrollableContainer["default"], {
            onScrollAreaChanged: onScrollAreaChangedSpy,
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 27,
              columnNumber: 7
            }
          }));
          expect(onScrollAreaChangedSpy).toHaveBeenCalledTimes(1);
          expect(onScrollAreaChangedSpy).toHaveBeenCalledWith(expect.objectContaining({
            area: {
              y: _index.AreaY.NONE
            }
          }));
        case 4:
        case "end":
          return _context2.stop();
      }
    }, _callee2);
  })));
  it('should use received forwarded ref when passed while internal registering to scroll events still works', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee3() {
    var testValue, testRef, onScrollAreaChangedSpy;
    return _regenerator["default"].wrap(function _callee3$(_context3) {
      while (1) switch (_context3.prev = _context3.next) {
        case 0:
          testValue = 'test';
          testRef = /*#__PURE__*/_react["default"].createRef();
          onScrollAreaChangedSpy = vi.fn();
          render(/*#__PURE__*/_react["default"].createElement(_ScrollableContainer["default"], {
            ref: testRef,
            onScrollAreaChanged: onScrollAreaChangedSpy,
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 40,
              columnNumber: 7
            }
          }, testValue));
          expect(onScrollAreaChangedSpy).toHaveBeenCalledTimes(1);
          expect(onScrollAreaChangedSpy).toHaveBeenCalledWith(expect.objectContaining({
            area: {
              y: _index.AreaY.NONE
            }
          }));
          expect(testRef.current.textContent).toEqual(testValue);
        case 7:
        case "end":
          return _context3.stop();
      }
    }, _callee3);
  })));
  describe('Scroll Logic', function () {
    it('should calculate the Y scroll area to `none` when clientHeight is equal to scrollHeight', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee4() {
      var area;
      return _regenerator["default"].wrap(function _callee4$(_context4) {
        while (1) switch (_context4.prev = _context4.next) {
          case 0:
            area = (0, _scrollAreaLogic.getScrollAreaY)({
              scrollHeight: 50,
              clientHeight: 50,
              scrollTop: 0
            });
            expect(area).toBe(_index.AreaY.NONE);
          case 2:
          case "end":
            return _context4.stop();
        }
      }, _callee4);
    })));
    it('should calculate the Y scroll area to `none` when clientHeight is greater than scrollHeight', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee5() {
      var area;
      return _regenerator["default"].wrap(function _callee5$(_context5) {
        while (1) switch (_context5.prev = _context5.next) {
          case 0:
            area = (0, _scrollAreaLogic.getScrollAreaY)({
              scrollHeight: 50,
              clientHeight: 51,
              scrollTop: 0
            });
            expect(area).toBe(_index.AreaY.NONE);
          case 2:
          case "end":
            return _context5.stop();
        }
      }, _callee5);
    })));
    it('should calculate the Y scroll area to `top`', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee6() {
      var area;
      return _regenerator["default"].wrap(function _callee6$(_context6) {
        while (1) switch (_context6.prev = _context6.next) {
          case 0:
            area = (0, _scrollAreaLogic.getScrollAreaY)({
              scrollHeight: 100,
              clientHeight: 50,
              scrollTop: 0
            });
            expect(area).toBe(_index.AreaY.TOP);
          case 2:
          case "end":
            return _context6.stop();
        }
      }, _callee6);
    })));
    it('should calculate the Y scroll area to `middle`', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee7() {
      var area;
      return _regenerator["default"].wrap(function _callee7$(_context7) {
        while (1) switch (_context7.prev = _context7.next) {
          case 0:
            area = (0, _scrollAreaLogic.getScrollAreaY)({
              scrollHeight: 100,
              clientHeight: 50,
              scrollTop: 10
            });
            expect(area).toBe(_index.AreaY.MIDDLE);
          case 2:
          case "end":
            return _context7.stop();
        }
      }, _callee7);
    })));
    it('should calculate the Y scroll area to `bottom`', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee8() {
      var area;
      return _regenerator["default"].wrap(function _callee8$(_context8) {
        while (1) switch (_context8.prev = _context8.next) {
          case 0:
            area = (0, _scrollAreaLogic.getScrollAreaY)({
              scrollHeight: 100,
              clientHeight: 50,
              scrollTop: 50
            });
            expect(area).toBe(_index.AreaY.BOTTOM);
          case 2:
          case "end":
            return _context8.stop();
        }
      }, _callee8);
    })));
  });
});