"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 _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireDefault(require("react"));
var _react2 = require("../../utils/test-utils/react");
var _NestableListBaseUni = require("../NestableListBase.uni.driver");
var _NestableListBase = _interopRequireDefault(require("../NestableListBase"));
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/NestableListBase/test/NestableListBase.spec.jsx",
  _this = void 0;
// Mock window.scrollBy which is not implemented in jsdom
beforeAll(function () {
  window.scrollBy = vi.fn();
  Object.defineProperty(window, 'innerHeight', {
    writable: true,
    configurable: true,
    value: 768
  });
});
var renderNestableListBase = function renderNestableListBase() {
  var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  var items = [{
    id: '0',
    text: 'item 0'
  }, {
    id: '1',
    text: 'item 1'
  }, {
    id: '2',
    text: 'item 2',
    children: [{
      id: '22',
      text: 'item 22'
    }]
  }];
  var dataHook = 'nestable-list';
  var renderItem = function renderItem(_ref) {
    var item = _ref.item;
    return /*#__PURE__*/_react["default"].createElement("div", {
      "data-hook": "item-".concat(item.id),
      __self: _this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 29,
        columnNumber: 5
      }
    }, item.text);
  };
  return /*#__PURE__*/_react["default"].createElement(_NestableListBase["default"], (0, _extends2["default"])({
    dataHook: dataHook,
    renderItem: renderItem,
    maxDepth: 2,
    items: items
  }, props, {
    __self: _this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 33,
      columnNumber: 5
    }
  }));
};
describe('NestableListBase', function () {
  afterEach(function () {
    return (0, _react2.cleanup)();
  });
  var render = (0, _react2.createRendererWithUniDriver)(_NestableListBaseUni.nestableListBaseUniDriverFactory);
  it('reorder vertically', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee() {
    var _render, driver;
    return _regenerator["default"].wrap(function _callee$(_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          _render = render(renderNestableListBase()), driver = _render.driver;
          _context.next = 3;
          return driver.reorder({
            dataHookFrom: 'item-0',
            dataHookTo: 'item-1'
          });
        case 3:
          _context.t0 = expect;
          _context.next = 6;
          return driver.getItemPosition({
            dataHook: 'item-0'
          });
        case 6:
          _context.t1 = _context.sent;
          (0, _context.t0)(_context.t1).toEqual(1);
        case 8:
        case "end":
          return _context.stop();
      }
    }, _callee);
  })));
  describe('change depth', function () {
    it('should increment depth level', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2() {
      var _render2, driver;
      return _regenerator["default"].wrap(function _callee2$(_context2) {
        while (1) switch (_context2.prev = _context2.next) {
          case 0:
            _render2 = render(renderNestableListBase()), driver = _render2.driver;
            _context2.next = 3;
            return driver.changeItemDepth({
              dataHook: 'item-1',
              depthLevel: 1
            });
          case 3:
            _context2.t0 = expect;
            _context2.next = 6;
            return driver.getItemDepth({
              dataHook: 'item-1'
            });
          case 6:
            _context2.t1 = _context2.sent;
            (0, _context2.t0)(_context2.t1).toEqual(1);
          case 8:
          case "end":
            return _context2.stop();
        }
      }, _callee2);
    })));
    it('should decrement depth level', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee3() {
      var _render3, driver;
      return _regenerator["default"].wrap(function _callee3$(_context3) {
        while (1) switch (_context3.prev = _context3.next) {
          case 0:
            _render3 = render(renderNestableListBase()), driver = _render3.driver;
            _context3.next = 3;
            return driver.changeItemDepth({
              dataHook: 'item-22',
              depthLevel: -1
            });
          case 3:
            _context3.t0 = expect;
            _context3.next = 6;
            return driver.getItemDepth({
              dataHook: 'item-22'
            });
          case 6:
            _context3.t1 = _context3.sent;
            (0, _context3.t0)(_context3.t1).toEqual(0);
          case 8:
          case "end":
            return _context3.stop();
        }
      }, _callee3);
    })));
  });
});