"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 _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _react = _interopRequireDefault(require("react"));
var _unit = require("../../utils/test-utils/unit");
var _CardFolderTabs = _interopRequireDefault(require("../CardFolderTabs"));
var _CardFolderTabsPrivateUni = require("./CardFolderTabs.private.uni.driver");
var _excluded = ["content1", "content2", "disableTab2"];
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/CardFolderTabs/test/CardFolderTabs.spec.jsx",
  _this = void 0;
describe(_CardFolderTabs["default"].displayName, function () {
  var render = (0, _unit.createRendererWithUniDriver)(_CardFolderTabsPrivateUni.cardFolderTabsPrivateDriverFactory);
  var simpleExample = function simpleExample(_ref) {
    var _ref$content = _ref.content1,
      content1 = _ref$content === void 0 ? 'content 1' : _ref$content,
      _ref$content2 = _ref.content2,
      content2 = _ref$content2 === void 0 ? 'content 2' : _ref$content2,
      disableTab2 = _ref.disableTab2,
      rest = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
    return /*#__PURE__*/_react["default"].createElement(_CardFolderTabs["default"], (0, _extends2["default"])({
      activeId: "tab-1"
    }, rest, {
      __self: _this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 21,
        columnNumber: 5
      }
    }), /*#__PURE__*/_react["default"].createElement(_CardFolderTabs["default"].Tab, {
      id: "tab-1",
      name: "First Tab",
      __self: _this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 22,
        columnNumber: 7
      }
    }, content1), /*#__PURE__*/_react["default"].createElement(_CardFolderTabs["default"].Tab, {
      id: "tab-2",
      name: "Second Tab",
      disabled: disableTab2,
      __self: _this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 25,
        columnNumber: 7
      }
    }, content2));
  };
  afterEach(_unit.cleanup);
  it('should render', /*#__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(simpleExample({})), driver = _render.driver;
          _context.t0 = expect;
          _context.next = 4;
          return driver.exists();
        case 4:
          _context.t1 = _context.sent;
          (0, _context.t0)(_context.t1).toBe(true);
        case 6:
        case "end":
          return _context.stop();
      }
    }, _callee);
  })));
  it('should render correct content by selected tab', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2() {
    var onTabChange, dataHook1, dataHook2, _render2, driver;
    return _regenerator["default"].wrap(function _callee2$(_context2) {
      while (1) switch (_context2.prev = _context2.next) {
        case 0:
          onTabChange = vi.fn();
          dataHook1 = 'my-data-hook1';
          dataHook2 = 'my-data-hook2';
          _render2 = render(simpleExample({
            onTabChange: onTabChange,
            content1: /*#__PURE__*/_react["default"].createElement("div", {
              "data-hook": dataHook1,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 47,
                columnNumber: 19
              }
            }),
            content2: /*#__PURE__*/_react["default"].createElement("div", {
              "data-hook": dataHook2,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 48,
                columnNumber: 19
              }
            })
          })), driver = _render2.driver; // First tab is selected (by default)
          _context2.t0 = expect;
          _context2.next = 7;
          return driver.element();
        case 7:
          _context2.t1 = _context2.sent.querySelector("[data-hook=\"".concat(dataHook1, "\"]"));
          (0, _context2.t0)(_context2.t1).toBeTruthy();
          _context2.t2 = expect;
          _context2.next = 12;
          return driver.element();
        case 12:
          _context2.t3 = _context2.sent.querySelector("[data-hook=\"".concat(dataHook2, "\"]"));
          (0, _context2.t2)(_context2.t3).toBe(null);
        case 14:
        case "end":
          return _context2.stop();
      }
    }, _callee2);
  })));
  it('should call onTabChange when tab is selected', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee3() {
    var onTabChange, _render3, driver;
    return _regenerator["default"].wrap(function _callee3$(_context3) {
      while (1) switch (_context3.prev = _context3.next) {
        case 0:
          onTabChange = vi.fn();
          _render3 = render(simpleExample({
            onTabChange: onTabChange
          })), driver = _render3.driver;
          _context3.next = 4;
          return driver.selectTabById('tab-2');
        case 4:
          expect(onTabChange).toHaveBeenCalled();
        case 5:
        case "end":
          return _context3.stop();
      }
    }, _callee3);
  })));
  it('should not call onTabChange when clicking on tab which is disabled', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee4() {
    var onTabChange, _render4, driver;
    return _regenerator["default"].wrap(function _callee4$(_context4) {
      while (1) switch (_context4.prev = _context4.next) {
        case 0:
          onTabChange = vi.fn();
          _render4 = render(simpleExample({
            onTabChange: onTabChange,
            disableTab2: true
          })), driver = _render4.driver;
          _context4.t0 = expect;
          _context4.next = 5;
          return driver.isTabDisabledById('tab-1');
        case 5:
          _context4.t1 = _context4.sent;
          (0, _context4.t0)(_context4.t1).toBe(false);
          _context4.t2 = expect;
          _context4.next = 10;
          return driver.isTabDisabledById('tab-2');
        case 10:
          _context4.t3 = _context4.sent;
          (0, _context4.t2)(_context4.t3).toBe(true);
          _context4.next = 14;
          return driver.selectTabById('tab-2');
        case 14:
          expect(onTabChange).not.toHaveBeenCalled();
        case 15:
        case "end":
          return _context4.stop();
      }
    }, _callee4);
  })));
  describe('tab text size', function () {
    it('should render text size as medium by default', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee5() {
      var _render5, driver;
      return _regenerator["default"].wrap(function _callee5$(_context5) {
        while (1) switch (_context5.prev = _context5.next) {
          case 0:
            _render5 = render(simpleExample({})), driver = _render5.driver;
            _context5.t0 = expect;
            _context5.next = 4;
            return driver.getSize('tab-1');
          case 4:
            _context5.t1 = _context5.sent;
            (0, _context5.t0)(_context5.t1).toBe('medium');
          case 6:
          case "end":
            return _context5.stop();
        }
      }, _callee5);
    })));
    it('should render text size as small if it was provided bt the props', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee6() {
      var _render6, driver;
      return _regenerator["default"].wrap(function _callee6$(_context6) {
        while (1) switch (_context6.prev = _context6.next) {
          case 0:
            _render6 = render(simpleExample({
              size: 'small'
            })), driver = _render6.driver;
            _context6.t0 = expect;
            _context6.next = 4;
            return driver.getSize('tab-1');
          case 4:
            _context6.t1 = _context6.sent;
            (0, _context6.t0)(_context6.t1).toBe('small');
          case 6:
          case "end":
            return _context6.stop();
        }
      }, _callee6);
    })));
  });
});