"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 _Dropzone = _interopRequireDefault(require("../Dropzone"));
var _DropzonePrivateUni = require("./Dropzone.private.uni.driver");
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/Dropzone/test/Dropzone.spec.jsx",
  _this = void 0;
var dropzoneWithStub = function dropzoneWithStub() {
  var stub = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : vi.fn();
  return /*#__PURE__*/_react["default"].createElement(_Dropzone["default"], {
    onDrop: stub,
    __self: _this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 11,
      columnNumber: 3
    }
  }, /*#__PURE__*/_react["default"].createElement(_Dropzone["default"].Overlay, {
    __self: _this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 12,
      columnNumber: 5
    }
  }, /*#__PURE__*/_react["default"].createElement("span", {
    __self: _this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 13,
      columnNumber: 7
    }
  })), /*#__PURE__*/_react["default"].createElement(_Dropzone["default"].Content, {
    __self: _this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 15,
      columnNumber: 5
    }
  }, /*#__PURE__*/_react["default"].createElement("span", {
    __self: _this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 16,
      columnNumber: 7
    }
  })));
};
describe(_Dropzone["default"].displayName, function () {
  var someFiles = [new File(['foo'], 'foo.txt', {
    type: 'text/plain'
  })];
  var render = (0, _unit.createRendererWithUniDriver)(_DropzonePrivateUni.dropzonePrivateDriverFactory);
  it('should render', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee() {
    var driver;
    return _regenerator["default"].wrap(function _callee$(_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          driver = render(dropzoneWithStub()).driver;
          _context.t0 = expect;
          _context.next = 4;
          return driver.exists();
        case 4:
          _context.t1 = _context.sent;
          (0, _context.t0)(_context.t1).toBe(true);
          _context.t2 = expect;
          _context.next = 9;
          return driver.getContentElement().exists();
        case 9:
          _context.t3 = _context.sent;
          (0, _context.t2)(_context.t3).toBe(true);
          _context.t4 = expect;
          _context.next = 14;
          return driver.getOverlayElement().exists();
        case 14:
          _context.t5 = _context.sent;
          (0, _context.t4)(_context.t5).toBe(false);
        case 16:
        case "end":
          return _context.stop();
      }
    }, _callee);
  })));
  describe('event handling', function () {
    var driver, onDropStub;
    beforeEach(function () {
      onDropStub = vi.fn();
      driver = render(dropzoneWithStub(onDropStub)).driver;
    });
    afterEach(function () {
      (0, _unit.cleanup)();
    });
    it('should call onDrop when drop event happens and it has files', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2() {
      return _regenerator["default"].wrap(function _callee2$(_context2) {
        while (1) switch (_context2.prev = _context2.next) {
          case 0:
            _context2.next = 2;
            return driver.dropFiles(someFiles);
          case 2:
            expect(onDropStub).toHaveBeenCalledWith(someFiles);
          case 3:
          case "end":
            return _context2.stop();
        }
      }, _callee2);
    })));
    it("should not call onDrop when drop event happens and it doesn't has files", /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee3() {
      return _regenerator["default"].wrap(function _callee3$(_context3) {
        while (1) switch (_context3.prev = _context3.next) {
          case 0:
            _context3.next = 2;
            return driver.dropFiles([]);
          case 2:
            expect(onDropStub).not.toHaveBeenCalled();
          case 3:
          case "end":
            return _context3.stop();
        }
      }, _callee3);
    })));
    it('should render the overlay when files are hovered on the dropzone', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee4() {
      return _regenerator["default"].wrap(function _callee4$(_context4) {
        while (1) switch (_context4.prev = _context4.next) {
          case 0:
            _context4.next = 2;
            return driver.hover(someFiles);
          case 2:
            _context4.t0 = expect;
            _context4.next = 5;
            return driver.getOverlayElement().exists();
          case 5:
            _context4.t1 = _context4.sent;
            (0, _context4.t0)(_context4.t1).toBe(true);
          case 7:
          case "end":
            return _context4.stop();
        }
      }, _callee4);
    })));
    it("should not render the overlay when hover event happens and it doesn't have files", /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee5() {
      return _regenerator["default"].wrap(function _callee5$(_context5) {
        while (1) switch (_context5.prev = _context5.next) {
          case 0:
            _context5.next = 2;
            return driver.hover([]);
          case 2:
            _context5.t0 = expect;
            _context5.next = 5;
            return driver.getOverlayElement().exists();
          case 5:
            _context5.t1 = _context5.sent;
            (0, _context5.t0)(_context5.t1).toBe(false);
          case 7:
          case "end":
            return _context5.stop();
        }
      }, _callee5);
    })));
    it('should unrender the overlay when files are unhovered on the dropzone', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee6() {
      return _regenerator["default"].wrap(function _callee6$(_context6) {
        while (1) switch (_context6.prev = _context6.next) {
          case 0:
            _context6.next = 2;
            return driver.hover(someFiles);
          case 2:
            _context6.t0 = expect;
            _context6.next = 5;
            return driver.getOverlayElement().exists();
          case 5:
            _context6.t1 = _context6.sent;
            (0, _context6.t0)(_context6.t1).toBe(true);
            _context6.next = 9;
            return driver.unhover();
          case 9:
            _context6.t2 = expect;
            _context6.next = 12;
            return driver.getOverlayElement().exists();
          case 12:
            _context6.t3 = _context6.sent;
            (0, _context6.t2)(_context6.t3).toBe(false);
          case 14:
          case "end":
            return _context6.stop();
        }
      }, _callee6);
    })));
    it('should unrender the overlay when files are dropped on the dropzone', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee7() {
      return _regenerator["default"].wrap(function _callee7$(_context7) {
        while (1) switch (_context7.prev = _context7.next) {
          case 0:
            _context7.next = 2;
            return driver.hover(someFiles);
          case 2:
            _context7.t0 = expect;
            _context7.next = 5;
            return driver.getOverlayElement().exists();
          case 5:
            _context7.t1 = _context7.sent;
            (0, _context7.t0)(_context7.t1).toBe(true);
            _context7.next = 9;
            return driver.dropFiles(someFiles);
          case 9:
            _context7.t2 = expect;
            _context7.next = 12;
            return driver.getOverlayElement().exists();
          case 12:
            _context7.t3 = _context7.sent;
            (0, _context7.t2)(_context7.t3).toBe(false);
          case 14:
          case "end":
            return _context7.stop();
        }
      }, _callee7);
    })));
    it('should have correct drag-active classes when files are hovered on the dropzone', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee8() {
      var dragActiveClass, containerClass;
      return _regenerator["default"].wrap(function _callee8$(_context8) {
        while (1) switch (_context8.prev = _context8.next) {
          case 0:
            dragActiveClass = 'dropzone__container--drag-active';
            containerClass = 'dropzone__container';
            _context8.t0 = expect;
            _context8.next = 5;
            return driver.hasClass(containerClass);
          case 5:
            _context8.t1 = _context8.sent;
            (0, _context8.t0)(_context8.t1).toBe(true);
            _context8.t2 = expect;
            _context8.next = 10;
            return driver.hasClass(dragActiveClass);
          case 10:
            _context8.t3 = _context8.sent;
            (0, _context8.t2)(_context8.t3).toBe(false);
            _context8.next = 14;
            return driver.hover(someFiles);
          case 14:
            _context8.t4 = expect;
            _context8.next = 17;
            return driver.hasClass(dragActiveClass);
          case 17:
            _context8.t5 = _context8.sent;
            (0, _context8.t4)(_context8.t5).toBe(true);
          case 19:
          case "end":
            return _context8.stop();
        }
      }, _callee8);
    })));
  });
});