"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.testkit = exports.default = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _unidriver = require("../utils/test-utils/unidriver");
var _StatusIndicatorUni = require("../StatusIndicator/StatusIndicator.uni.driver");
var _Input = require("./Input.constants");
var _TooltipUni = require("../Tooltip/Tooltip.uni.driver");
var _isPlaywrightUniDriver = require("../utils/test-utils/unidriver/isPlaywrightUniDriver");
var _isDomUniDriver = require("../utils/test-utils/unidriver/isDomUniDriver");
var _isPuppeteerUniDriver = require("../utils/test-utils/unidriver/isPuppeteerUniDriver");
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 testkit = (base, body) => {
  // single $ throws an exception for more than 1 match, so we use the first matching result with $$
  // to support cases of multiple inputs, e.g cases where this driver is used inside other drivers with popovers
  // which includes an input
  var input = base.$$('input').get(0);
  var reactBase = (0, _unidriver.ReactBase)(base);
  var reactBaseInput = (0, _unidriver.ReactBase)(input);
  var clearButtonNode = base.$("[data-hook=input-clear-button]");
  var menuArrowNode = base.$("[data-hook=\"".concat(_Input.dataHooks.menuArrow, "\"]"));
  var getStatusIndicatorDriver = () => (0, _StatusIndicatorUni.statusIndicatorDriverFactory)(base.$("[data-hook=\"".concat(_Input.dataHooks.status, "\"]")), body);
  var getTooltipDriver = () => (0, _TooltipUni.tooltipDriverFactory)(base.$("[data-hook=\"".concat(_Input.dataHooks.tooltip, "\"]")), body);
  var trigger = /*#__PURE__*/function () {
    var _ref = (0, _asyncToGenerator2.default)(function* (eventType, event) {
      if (eventType === 'focus') {
        return yield driver.focus();
      }
      if (eventType === 'blur') {
        return yield driver.blur();
      }
      if (eventType === 'keyUp') {
        return yield driver.keyUp();
      }
      if (eventType === 'keyDown') {
        return yield driver.keyDown(event);
      }
      if (eventType === 'paste') {
        return yield driver.paste();
      }
      if (eventType === 'copy') {
        return yield driver.copy();
      }
      if (eventType === 'change') {
        var castedEvent = event;
        return yield driver.enterText(castedEvent.target.value);
      }
      if (eventType === 'wheel') {
        return yield driver.wheel();
      }
    });
    return function trigger(_x, _x2) {
      return _ref.apply(this, arguments);
    };
  }();
  var driver = _objectSpread(_objectSpread({}, (0, _unidriver.baseUniDriverFactory)(base)), {}, {
    click: () => input.click(),
    getInputAttribute: function () {
      var _getInputAttribute = (0, _asyncToGenerator2.default)(function* (name) {
        return yield input.attr(name);
      });
      function getInputAttribute(_x3) {
        return _getInputAttribute.apply(this, arguments);
      }
      return getInputAttribute;
    }(),
    getInputElementClasses: function () {
      var _getInputElementClasses = (0, _asyncToGenerator2.default)(function* () {
        return yield reactBaseInput._DEPRECATED_getClassList();
      });
      function getInputElementClasses() {
        return _getInputElementClasses.apply(this, arguments);
      }
      return getInputElementClasses;
    }(),
    suffixComponentExists: function () {
      var _suffixComponentExists = (0, _asyncToGenerator2.default)(function* (className) {
        return yield base.$("[data-hook=\"".concat(_Input.dataHooks.suffixes, "\"] ").concat(className)).exists();
      });
      function suffixComponentExists(_x4) {
        return _suffixComponentExists.apply(this, arguments);
      }
      return suffixComponentExists;
    }(),
    getRootElementClasses: function () {
      var _getRootElementClasses = (0, _asyncToGenerator2.default)(function* () {
        return yield reactBase._DEPRECATED_getClassList();
      });
      function getRootElementClasses() {
        return _getRootElementClasses.apply(this, arguments);
      }
      return getRootElementClasses;
    }(),
    getAriaDescribedby: function () {
      var _getAriaDescribedby = (0, _asyncToGenerator2.default)(function* () {
        return yield input.attr('aria-describedby');
      });
      function getAriaDescribedby() {
        return _getAriaDescribedby.apply(this, arguments);
      }
      return getAriaDescribedby;
    }(),
    getAriaLabel: function () {
      var _getAriaLabel = (0, _asyncToGenerator2.default)(function* () {
        return yield input.attr('aria-label');
      });
      function getAriaLabel() {
        return _getAriaLabel.apply(this, arguments);
      }
      return getAriaLabel;
    }(),
    getName: function () {
      var _getName = (0, _asyncToGenerator2.default)(function* () {
        return yield input.attr('name');
      });
      function getName() {
        return _getName.apply(this, arguments);
      }
      return getName;
    }(),
    getMaxLength: function () {
      var _getMaxLength = (0, _asyncToGenerator2.default)(function* () {
        return yield input.attr('maxLength');
      });
      function getMaxLength() {
        return _getMaxLength.apply(this, arguments);
      }
      return getMaxLength;
    }(),
    getType: function () {
      var _getType = (0, _asyncToGenerator2.default)(function* () {
        return yield input.attr('type');
      });
      function getType() {
        return _getType.apply(this, arguments);
      }
      return getType;
    }(),
    getAriaControls: function () {
      var _getAriaControls = (0, _asyncToGenerator2.default)(function* () {
        return yield input.attr('aria-controls');
      });
      function getAriaControls() {
        return _getAriaControls.apply(this, arguments);
      }
      return getAriaControls;
    }(),
    clickIconAffix: function () {
      var _clickIconAffix = (0, _asyncToGenerator2.default)(function* () {
        return yield base.$("[data-hook=\"icon-affix\"]").click();
      });
      function clickIconAffix() {
        return _clickIconAffix.apply(this, arguments);
      }
      return clickIconAffix;
    }(),
    clickCustomAffix: function () {
      var _clickCustomAffix = (0, _asyncToGenerator2.default)(function* () {
        return yield base.$("[data-hook=\"custom-affix\"]").click();
      });
      function clickCustomAffix() {
        return _clickCustomAffix.apply(this, arguments);
      }
      return clickCustomAffix;
    }(),
    getCustomAffixText: function () {
      var _getCustomAffixText = (0, _asyncToGenerator2.default)(function* () {
        var customAffix = yield base.get("[data-hook=\"custom-affix\"]");
        return customAffix.text();
      });
      function getCustomAffixText() {
        return _getCustomAffixText.apply(this, arguments);
      }
      return getCustomAffixText;
    }(),
    hasSuffix: function () {
      var _hasSuffix = (0, _asyncToGenerator2.default)(function* () {
        return yield base.$("[data-hook=\"".concat(_Input.dataHooks.suffixes, "\"]")).exists();
      });
      function hasSuffix() {
        return _hasSuffix.apply(this, arguments);
      }
      return hasSuffix;
    }(),
    getClearButtonTooltipContent: function () {
      var _getClearButtonTooltipContent = (0, _asyncToGenerator2.default)(function* () {
        return yield getTooltipDriver().getTooltipText();
      });
      function getClearButtonTooltipContent() {
        return _getClearButtonTooltipContent.apply(this, arguments);
      }
      return getClearButtonTooltipContent;
    }(),
    prefixComponentExists: function () {
      var _prefixComponentExists = (0, _asyncToGenerator2.default)(function* (style) {
        return !!(yield base.attr(_Input.DATA_ATTR.PREFIX)) && (yield base.$(style).exists());
      });
      function prefixComponentExists(_x5) {
        return _prefixComponentExists.apply(this, arguments);
      }
      return prefixComponentExists;
    }(),
    hasPrefix: function () {
      var _hasPrefix = (0, _asyncToGenerator2.default)(function* () {
        return (yield base.attr(_Input.DATA_ATTR.PREFIX)) === 'true';
      });
      function hasPrefix() {
        return _hasPrefix.apply(this, arguments);
      }
      return hasPrefix;
    }(),
    hasClearButton: function () {
      var _hasClearButton = (0, _asyncToGenerator2.default)(function* () {
        return yield clearButtonNode.exists();
      });
      function hasClearButton() {
        return _hasClearButton.apply(this, arguments);
      }
      return hasClearButton;
    }(),
    clickClear: function () {
      var _clickClear = (0, _asyncToGenerator2.default)(function* () {
        return yield clearButtonNode.click();
      });
      function clickClear() {
        return _clickClear.apply(this, arguments);
      }
      return clickClear;
    }(),
    getValue: function () {
      var _getValue = (0, _asyncToGenerator2.default)(function* () {
        return yield input.value();
      });
      function getValue() {
        return _getValue.apply(this, arguments);
      }
      return getValue;
    }(),
    getText: function () {
      var _getText = (0, _asyncToGenerator2.default)(function* () {
        return yield input.value();
      });
      function getText() {
        return _getText.apply(this, arguments);
      }
      return getText;
    }(),
    getPattern: function () {
      var _getPattern = (0, _asyncToGenerator2.default)(function* () {
        return yield input.attr('pattern');
      });
      function getPattern() {
        return _getPattern.apply(this, arguments);
      }
      return getPattern;
    }(),
    getPlaceholder: function () {
      var _getPlaceholder = (0, _asyncToGenerator2.default)(function* () {
        return yield input.attr('placeholder');
      });
      function getPlaceholder() {
        return _getPlaceholder.apply(this, arguments);
      }
      return getPlaceholder;
    }(),
    isOfSize: function () {
      var _isOfSize = (0, _asyncToGenerator2.default)(function* (size) {
        return (yield base.attr(_Input.DATA_ATTR.SIZE)) === size;
      });
      function isOfSize(_x6) {
        return _isOfSize.apply(this, arguments);
      }
      return isOfSize;
    }(),
    getSize: function () {
      var _getSize = (0, _asyncToGenerator2.default)(function* () {
        return yield base.attr(_Input.DATA_ATTR.SIZE);
      });
      function getSize() {
        return _getSize.apply(this, arguments);
      }
      return getSize;
    }(),
    isDisabled: function () {
      var _isDisabled = (0, _asyncToGenerator2.default)(function* () {
        return (yield base.attr(_Input.DATA_ATTR.DISABLED)) === 'true';
      });
      function isDisabled() {
        return _isDisabled.apply(this, arguments);
      }
      return isDisabled;
    }(),
    isHoveredStyle: function () {
      var _isHoveredStyle = (0, _asyncToGenerator2.default)(function* () {
        return (yield base.attr(_Input.DATA_ATTR.HOVER)) === 'true';
      });
      function isHoveredStyle() {
        return _isHoveredStyle.apply(this, arguments);
      }
      return isHoveredStyle;
    }(),
    isFocusedStyle: function () {
      var _isFocusedStyle = (0, _asyncToGenerator2.default)(function* () {
        return (yield base.attr(_Input.DATA_ATTR.FOCUS)) === 'true';
      });
      function isFocusedStyle() {
        return _isFocusedStyle.apply(this, arguments);
      }
      return isFocusedStyle;
    }(),
    getRequired: function () {
      var _getRequired = (0, _asyncToGenerator2.default)(function* () {
        return yield input.prop('required');
      });
      function getRequired() {
        return _getRequired.apply(this, arguments);
      }
      return getRequired;
    }(),
    enterText: function () {
      var _enterText = (0, _asyncToGenerator2.default)(function* (value) {
        return yield input.enterValue(value);
      });
      function enterText(_x7) {
        return _enterText.apply(this, arguments);
      }
      return enterText;
    }(),
    getAutocomplete: function () {
      var _getAutocomplete = (0, _asyncToGenerator2.default)(function* () {
        return yield input.attr('autocomplete');
      });
      function getAutocomplete() {
        return _getAutocomplete.apply(this, arguments);
      }
      return getAutocomplete;
    }(),
    getDefaultValue: function () {
      var _getDefaultValue = (0, _asyncToGenerator2.default)(function* () {
        return yield input.prop('defaultValue');
      });
      function getDefaultValue() {
        return _getDefaultValue.apply(this, arguments);
      }
      return getDefaultValue;
    }(),
    getTabIndex: function () {
      var _getTabIndex = (0, _asyncToGenerator2.default)(function* () {
        return yield input.prop('tabIndex');
      });
      function getTabIndex() {
        return _getTabIndex.apply(this, arguments);
      }
      return getTabIndex;
    }(),
    isCustomInput: function () {
      var _isCustomInput = (0, _asyncToGenerator2.default)(function* () {
        return (yield input.attr('data-hook')) === 'wsr-custom-input';
      });
      function isCustomInput() {
        return _isCustomInput.apply(this, arguments);
      }
      return isCustomInput;
    }(),
    getReadOnly: function () {
      var _getReadOnly = (0, _asyncToGenerator2.default)(function* () {
        return yield input.prop('readOnly');
      });
      function getReadOnly() {
        return _getReadOnly.apply(this, arguments);
      }
      return getReadOnly;
    }(),
    getDisabled: function () {
      var _getDisabled = (0, _asyncToGenerator2.default)(function* () {
        return yield input.prop('disabled');
      });
      function getDisabled() {
        return _getDisabled.apply(this, arguments);
      }
      return getDisabled;
    }(),
    getTextOverflow: function () {
      var _getTextOverflow = (0, _asyncToGenerator2.default)(function* () {
        return (yield input.prop('style'))['text-overflow'];
      });
      function getTextOverflow() {
        return _getTextOverflow.apply(this, arguments);
      }
      return getTextOverflow;
    }(),
    focus: function () {
      var _focus = (0, _asyncToGenerator2.default)(function* () {
        return yield reactBaseInput.focus();
      });
      function focus() {
        return _focus.apply(this, arguments);
      }
      return focus;
    }(),
    blur: function () {
      var _blur = (0, _asyncToGenerator2.default)(function* () {
        return yield reactBaseInput.blur();
      });
      function blur() {
        return _blur.apply(this, arguments);
      }
      return blur;
    }(),
    keyUp: function () {
      var _keyUp = (0, _asyncToGenerator2.default)(function* () {
        return yield reactBaseInput.keyUp();
      });
      function keyUp() {
        return _keyUp.apply(this, arguments);
      }
      return keyUp;
    }(),
    keyDown: function () {
      var _keyDown = (0, _asyncToGenerator2.default)(function* (eventData) {
        return yield reactBaseInput.keyDown(eventData);
      });
      function keyDown(_x8) {
        return _keyDown.apply(this, arguments);
      }
      return keyDown;
    }(),
    pressKey: function () {
      var _pressKey = (0, _asyncToGenerator2.default)(function* (key) {
        return yield input.pressKey(key);
      });
      function pressKey(_x9) {
        return _pressKey.apply(this, arguments);
      }
      return pressKey;
    }(),
    paste: function () {
      var _paste = (0, _asyncToGenerator2.default)(function* () {
        return yield reactBaseInput.paste();
      });
      function paste() {
        return _paste.apply(this, arguments);
      }
      return paste;
    }(),
    copy: function () {
      var _copy = (0, _asyncToGenerator2.default)(function* () {
        return yield reactBaseInput.copy();
      });
      function copy() {
        return _copy.apply(this, arguments);
      }
      return copy;
    }(),
    wheel: function () {
      var _wheel = (0, _asyncToGenerator2.default)(function* () {
        return yield reactBaseInput.wheel();
      });
      function wheel() {
        return _wheel.apply(this, arguments);
      }
      return wheel;
    }(),
    trigger,
    isFocus: function () {
      var _isFocus = (0, _asyncToGenerator2.default)(function* () {
        return (0, _unidriver.isElementFocused)(input);
      });
      function isFocus() {
        return _isFocus.apply(this, arguments);
      }
      return isFocus;
    }(),
    clickMenuArrow: function () {
      var _clickMenuArrow = (0, _asyncToGenerator2.default)(function* () {
        return yield menuArrowNode.click();
      });
      function clickMenuArrow() {
        return _clickMenuArrow.apply(this, arguments);
      }
      return clickMenuArrow;
    }(),
    hasMenuArrow: function () {
      var _hasMenuArrow = (0, _asyncToGenerator2.default)(function* () {
        return yield menuArrowNode.exists();
      });
      function hasMenuArrow() {
        return _hasMenuArrow.apply(this, arguments);
      }
      return hasMenuArrow;
    }(),
    isRTL: function () {
      var _isRTL = (0, _asyncToGenerator2.default)(function* () {
        return (yield base.attr('dir')) === 'rtl';
      });
      function isRTL() {
        return _isRTL.apply(this, arguments);
      }
      return isRTL;
    }(),
    getCursorLocation: () => input.prop('selectionStart'),
    clearText: () => driver.enterText(''),
    clickOutside: function () {
      var _clickOutside = (0, _asyncToGenerator2.default)(function* () {
        if ((0, _isPlaywrightUniDriver.isPlaywrightUniDriver)(base) || (0, _isPuppeteerUniDriver.isPuppeteerUniDriver)(base)) {
          var LocatorOrHandle = yield base.unwrap();
          return LocatorOrHandle.evaluate(node => {
            return node.ownerDocument.body.click();
          });
        }
        if ((0, _isDomUniDriver.isDomUniDriver)(base)) {
          return document.body.click();
        }
        return _unidriver.ReactBase.clickDocument();
      });
      function clickOutside() {
        return _clickOutside.apply(this, arguments);
      }
      return clickOutside;
    }(),
    isMasked: function () {
      var _isMasked = (0, _asyncToGenerator2.default)(function* () {
        return (yield input.attr('data-mask')) === 'true';
      });
      function isMasked() {
        return _isMasked.apply(this, arguments);
      }
      return isMasked;
    }(),
    isSelected: function () {
      var _isSelected = (0, _asyncToGenerator2.default)(function* () {
        var selectionStart = yield input.prop('selectionStart');
        var selectionEnd = yield input.prop('selectionEnd');
        return selectionStart !== selectionEnd;
      });
      function isSelected() {
        return _isSelected.apply(this, arguments);
      }
      return isSelected;
    }(),
    // Status
    /** Return true if there's a status */
    hasStatus: function () {
      var _hasStatus = (0, _asyncToGenerator2.default)(function* (status) {
        return (yield base.attr(_Input.DATA_ATTR.STATUS)) === status;
      });
      function hasStatus(_x0) {
        return _hasStatus.apply(this, arguments);
      }
      return hasStatus;
    }(),
    /** If there's a status message, returns its text value */
    getStatusMessage: function () {
      var _getStatusMessage = (0, _asyncToGenerator2.default)(function* () {
        var statusIndicatorDriver = getStatusIndicatorDriver();
        return yield statusIndicatorDriver.getMessage();
      });
      function getStatusMessage() {
        return _getStatusMessage.apply(this, arguments);
      }
      return getStatusMessage;
    }()
  });
  return driver;
};
exports.testkit = testkit;
var _default = exports.default = testkit;
//# sourceMappingURL=Input.uni.driver.js.map