"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.tooltipDriverFactory = void 0;
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _PopoverUni = require("../Popover/Popover.uni.driver");
var _unidriver = require("../utils/test-utils/unidriver");
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var tooltipDriverFactory = (base, body) => {
  var popoverDriver = (0, _PopoverUni.popoverUniDriverFactory)(base, body);
  return _objectSpread(_objectSpread({}, (0, _unidriver.baseUniDriverFactory)(base)), {}, {
    /** Clicks on the target element */
    click: function () {
      var _click = (0, _asyncToGenerator2.default)(function* () {
        return popoverDriver.click();
      });
      function click() {
        return _click.apply(this, arguments);
      }
      return click;
    }(),
    /** returns true if tooltip element exists on the DOM */
    tooltipExists: function () {
      var _tooltipExists = (0, _asyncToGenerator2.default)(function* () {
        return popoverDriver.isContentElementExists();
      });
      function tooltipExists() {
        return _tooltipExists.apply(this, arguments);
      }
      return tooltipExists;
    }(),
    /** mouse over the target element */
    mouseEnter: function () {
      var _mouseEnter = (0, _asyncToGenerator2.default)(function* () {
        return popoverDriver.mouseEnter();
      });
      function mouseEnter() {
        return _mouseEnter.apply(this, arguments);
      }
      return mouseEnter;
    }(),
    /** mouse leaves the target element */
    mouseLeave: function () {
      var _mouseLeave = (0, _asyncToGenerator2.default)(function* () {
        return popoverDriver.mouseLeave();
      });
      function mouseLeave() {
        return _mouseLeave.apply(this, arguments);
      }
      return mouseLeave;
    }(),
    /** clicks outside the tooltip target */
    clickOutside: function () {
      var _clickOutside = (0, _asyncToGenerator2.default)(function* () {
        return popoverDriver.clickOutside();
      });
      function clickOutside() {
        return _clickOutside.apply(this, arguments);
      }
      return clickOutside;
    }(),
    /** returns tooltips content value in string */
    getTooltipText: function () {
      var _getTooltipText = (0, _asyncToGenerator2.default)(function* () {
        yield popoverDriver.mouseEnter();
        try {
          var text = yield (yield popoverDriver.getContentElementUniDriver()).text();
          // Clean yourself!
          yield popoverDriver.mouseLeave();
          return text;
        } catch (e) {
          return null;
        }
      });
      function getTooltipText() {
        return _getTooltipText.apply(this, arguments);
      }
      return getTooltipText;
    }(),
    /**
     * Checks whether tooltip has a given size
     * @param {boolean} sizeName The tooltip size
     * @return {Promise<boolean>}
     */
    hasSize: function () {
      var _hasSize = (0, _asyncToGenerator2.default)(function* (sizeName) {
        return (yield base.attr("data-size")) === sizeName;
      });
      function hasSize(_x) {
        return _hasSize.apply(this, arguments);
      }
      return hasSize;
    }()
  });
};
exports.tooltipDriverFactory = tooltipDriverFactory;
//# sourceMappingURL=Tooltip.uni.driver.js.map