wix-style-react
Version:
340 lines (283 loc) • 10.5 kB
JavaScript
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import { testkit as inputUniDriverFactory } from '../Input/Input.uni.driver';
import { dropdownLayoutDriverFactory } from '../DropdownLayout/DropdownLayout.uni.driver';
import { popoverDriverFactory } from '../Popover/Popover.uni.driver';
import { CommonDriver } from "wix-ui-core/dist/es/src/components/popover/Popover.common.uni.driver";
import { ReactBase } from '../../test/utils/unidriver';
import { dropdownLayoutDriverProxy } from './InputWithOptions.proxy.driver';
export var inputWithOptionsUniDriverFactory = function inputWithOptionsUniDriverFactory(base, body) {
var inputWrapperSelector = '[data-input-parent]';
var dropdownLayoutSelector = "[data-hook=\"inputwithoptions-dropdownlayout\"]";
var _inputWrapper = base.$(inputWrapperSelector);
var popoverTestkit = function popoverTestkit() {
return popoverDriverFactory(base, body);
};
var popoverCommonTestkit = function popoverCommonTestkit() {
return CommonDriver(base, body);
};
var dropdownLayoutTestkit = /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
var content;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return popoverCommonTestkit().getContentElement();
case 2:
content = _context.sent;
return _context.abrupt("return", dropdownLayoutDriverFactory(content.$(dropdownLayoutSelector)));
case 4:
case "end":
return _context.stop();
}
}
}, _callee);
}));
return function dropdownLayoutTestkit() {
return _ref.apply(this, arguments);
};
}();
var inputTestkit = inputUniDriverFactory(base.$("".concat(inputWrapperSelector, " > *:first-child ")), body);
var driver = {
exists: function exists() {
return 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 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(id) {
var nativeSelect, dataHookPrefix, option, selectedIndex, isPopoverShown;
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return base.$('[data-hook=native-select]');
case 2:
nativeSelect = _context2.sent;
_context2.next = 5;
return nativeSelect.exists();
case 5:
if (!_context2.sent) {
_context2.next = 16;
break;
}
dataHookPrefix = "native-option-".concat(id);
_context2.next = 9;
return base.$("[data-hook*=".concat(dataHookPrefix, "]"));
case 9:
option = _context2.sent;
_context2.next = 12;
return option.attr('data-index');
case 12:
selectedIndex = _context2.sent;
_context2.next = 15;
return ReactBase(nativeSelect).select(selectedIndex);
case 15:
return _context2.abrupt("return", _context2.sent);
case 16:
_context2.next = 18;
return popoverTestkit().isContentElementExists();
case 18:
isPopoverShown = _context2.sent;
if (isPopoverShown) {
_context2.next = 22;
break;
}
_context2.next = 22;
return inputTestkit.click();
case 22:
_context2.next = 24;
return dropdownLayoutTestkit();
case 24:
_context2.next = 26;
return _context2.sent.optionById(id);
case 26:
_context2.next = 28;
return _context2.sent.click();
case 28:
case "end":
return _context2.stop();
}
}
}, _callee2);
}));
function selectOptionById(_x) {
return _selectOptionById.apply(this, arguments);
}
return selectOptionById;
}(),
isReadOnly: function () {
var _isReadOnly = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
_context3.next = 2;
return inputTestkit.getReadOnly();
case 2:
return _context3.abrupt("return", _context3.sent);
case 3:
case "end":
return _context3.stop();
}
}
}, _callee3);
}));
function isReadOnly() {
return _isReadOnly.apply(this, arguments);
}
return isReadOnly;
}(),
isEditable: function () {
var _isEditable = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
_context4.next = 2;
return inputTestkit.getReadOnly();
case 2:
_context4.t0 = !_context4.sent;
if (!_context4.t0) {
_context4.next = 7;
break;
}
_context4.next = 6;
return inputTestkit.getDisabled();
case 6:
_context4.t0 = !_context4.sent;
case 7:
return _context4.abrupt("return", _context4.t0);
case 8:
case "end":
return _context4.stop();
}
}
}, _callee4);
}));
function isEditable() {
return _isEditable.apply(this, arguments);
}
return isEditable;
}(),
isDisabled: function isDisabled() {
return inputTestkit.getDisabled();
},
/** @deprecated Should be private */
inputWrapper: function inputWrapper() {
return _inputWrapper.getNative();
},
// eslint-disable-line no-restricted-properties
focus: function focus() {
return inputTestkit.focus();
},
blur: function () {
var _blur = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
_context5.next = 2;
return dropdownLayoutTestkit();
case 2:
_context5.next = 4;
return _context5.sent.mouseClickOutside();
case 4:
return _context5.abrupt("return", _context5.sent);
case 5:
case "end":
return _context5.stop();
}
}
}, _callee5);
}));
function blur() {
return _blur.apply(this, arguments);
}
return blur;
}(),
// TODO: use pressKey instead of keyDown
pressKey: function () {
var _pressKey = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(key) {
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
_context6.next = 2;
return inputTestkit.keyDown({
key: key
});
case 2:
return _context6.abrupt("return", _context6.sent);
case 3:
case "end":
return _context6.stop();
}
}
}, _callee6);
}));
function pressKey(_x2) {
return _pressKey.apply(this, arguments);
}
return pressKey;
}(),
outsideClick: function () {
var _outsideClick = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
return _regeneratorRuntime.wrap(function _callee7$(_context7) {
while (1) {
switch (_context7.prev = _context7.next) {
case 0:
_context7.next = 2;
return popoverTestkit().clickOutside();
case 2:
return _context7.abrupt("return", _context7.sent);
case 3:
case "end":
return _context7.stop();
}
}
}, _callee7);
}));
function outsideClick() {
return _outsideClick.apply(this, arguments);
}
return outsideClick;
}(),
isFocus: function () {
var _isFocus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8() {
return _regeneratorRuntime.wrap(function _callee8$(_context8) {
while (1) {
switch (_context8.prev = _context8.next) {
case 0:
_context8.next = 2;
return inputTestkit.isFocus();
case 2:
return _context8.abrupt("return", _context8.sent);
case 3:
case "end":
return _context8.stop();
}
}
}, _callee8);
}));
function isFocus() {
return _isFocus.apply(this, arguments);
}
return isFocus;
}()
};
var dropdownLayoutDummy = function dropdownLayoutDummy() {
return dropdownLayoutDriverFactory(base);
};
var dropdownLayoutDriver = dropdownLayoutDriverProxy(dropdownLayoutDummy, dropdownLayoutTestkit, popoverTestkit, inputTestkit);
return {
exists: function exists() {
return driver.exists();
},
driver: driver,
inputDriver: inputTestkit,
dropdownLayoutDriver: dropdownLayoutDriver
};
};