wix-style-react
Version:
wix-style-react
123 lines (122 loc) • 5.07 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.inputWithOptionsUniDriverFactory = void 0;
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _InputUni = require("../Input/Input.uni.driver");
var _DropdownLayoutUni = require("../DropdownLayout/DropdownLayout.uni.driver");
var _PopoverUni = require("../Popover/Popover.uni.driver");
var _unidriver = require("../test-utils/utils/unidriver");
var _InputWithOptionsProxy = require("./InputWithOptions.proxy.driver");
var inputWithOptionsUniDriverFactory = (base, body) => {
var inputWrapperSelector = '[data-input-parent]';
var dropdownLayoutSelector = "[data-hook=\"inputwithoptions-dropdownlayout\"]";
var _inputWrapper = base.$(inputWrapperSelector);
var popoverTestkit = () => (0, _PopoverUni.popoverUniDriverFactory)(base, body);
var dropdownLayoutTestkit = /*#__PURE__*/function () {
var _ref = (0, _asyncToGenerator2.default)(function* () {
var content = yield popoverTestkit().getContentElementUniDriver();
return (0, _DropdownLayoutUni.dropdownLayoutDriverFactory)(content.$(dropdownLayoutSelector));
});
return function dropdownLayoutTestkit() {
return _ref.apply(this, arguments);
};
}();
var inputTestkit = (0, _InputUni.testkit)(base.$("".concat(inputWrapperSelector, " > *:first-child ")), body);
var driver = {
exists: () => base.exists(),
/** Select an option by id. (If dropdown options is not opened yet, this will open it and click on the option) */
selectOptionById: function () {
var _selectOptionById = (0, _asyncToGenerator2.default)(function* (id) {
var nativeSelect = yield base.$('[data-hook=native-select]');
if (yield nativeSelect.exists()) {
var dataHookPrefix = "native-option-".concat(id);
var option = yield base.$("[data-hook*=".concat(dataHookPrefix, "]"));
var selectedIndex = yield option.attr('data-index');
return yield (0, _unidriver.ReactBase)(nativeSelect).select(selectedIndex);
}
var isPopoverShown = yield popoverTestkit().isContentElementExists();
if (!isPopoverShown) {
yield inputTestkit.click();
}
yield (yield (yield dropdownLayoutTestkit()).optionById(id)).click();
});
function selectOptionById(_x) {
return _selectOptionById.apply(this, arguments);
}
return selectOptionById;
}(),
isReadOnly: function () {
var _isReadOnly = (0, _asyncToGenerator2.default)(function* () {
return yield inputTestkit.getReadOnly();
});
function isReadOnly() {
return _isReadOnly.apply(this, arguments);
}
return isReadOnly;
}(),
isEditable: function () {
var _isEditable = (0, _asyncToGenerator2.default)(function* () {
return !(yield inputTestkit.getReadOnly()) && !(yield inputTestkit.getDisabled());
});
function isEditable() {
return _isEditable.apply(this, arguments);
}
return isEditable;
}(),
isDisabled: () => inputTestkit.getDisabled(),
/** @deprecated Should be private */
inputWrapper: () => _inputWrapper.getNative(),
// eslint-disable-line no-restricted-properties
focus: () => inputTestkit.focus(),
blur: function () {
var _blur = (0, _asyncToGenerator2.default)(function* () {
return yield (yield dropdownLayoutTestkit()).mouseClickOutside();
});
function blur() {
return _blur.apply(this, arguments);
}
return blur;
}(),
// TODO: use pressKey instead of keyDown
pressKey: function () {
var _pressKey = (0, _asyncToGenerator2.default)(function* (key) {
return yield inputTestkit.keyDown({
key
});
});
function pressKey(_x2) {
return _pressKey.apply(this, arguments);
}
return pressKey;
}(),
outsideClick: function () {
var _outsideClick = (0, _asyncToGenerator2.default)(function* () {
return yield popoverTestkit().clickOutside();
});
function outsideClick() {
return _outsideClick.apply(this, arguments);
}
return outsideClick;
}(),
isFocus: function () {
var _isFocus = (0, _asyncToGenerator2.default)(function* () {
return yield inputTestkit.isFocus();
});
function isFocus() {
return _isFocus.apply(this, arguments);
}
return isFocus;
}()
};
var dropdownLayoutDummy = () => (0, _DropdownLayoutUni.dropdownLayoutDriverFactory)(base);
var dropdownLayoutDriver = (0, _InputWithOptionsProxy.dropdownLayoutDriverProxy)(dropdownLayoutDummy, dropdownLayoutTestkit, popoverTestkit, inputTestkit);
return {
exists: () => driver.exists(),
driver,
inputDriver: inputTestkit,
dropdownLayoutDriver
};
};
exports.inputWithOptionsUniDriverFactory = inputWithOptionsUniDriverFactory;
//# sourceMappingURL=InputWithOptions.uni.driver.js.map