wix-style-react
Version:
359 lines (290 loc) • 11.1 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.inputWithOptionsUniDriverFactory = void 0;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
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 _PopoverCommonUni = require("wix-ui-core/dist/src/components/popover/Popover.common.uni.driver");
var _unidriver = require("../../test/utils/unidriver");
var _InputWithOptionsProxy = require("./InputWithOptions.proxy.driver");
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 (0, _PopoverUni.popoverDriverFactory)(base, body);
};
var popoverCommonTestkit = function popoverCommonTestkit() {
return (0, _PopoverCommonUni.CommonDriver)(base, body);
};
var dropdownLayoutTestkit = /*#__PURE__*/function () {
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
var content;
return _regenerator["default"].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", (0, _DropdownLayoutUni.dropdownLayoutDriverFactory)(content.$(dropdownLayoutSelector)));
case 4:
case "end":
return _context.stop();
}
}
}, _callee);
}));
return function dropdownLayoutTestkit() {
return _ref.apply(this, arguments);
};
}();
var inputTestkit = (0, _InputUni.testkit)(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 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(id) {
var nativeSelect, dataHookPrefix, option, selectedIndex, isPopoverShown;
return _regenerator["default"].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 (0, _unidriver.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 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3() {
return _regenerator["default"].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 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4() {
return _regenerator["default"].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 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5() {
return _regenerator["default"].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 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6(key) {
return _regenerator["default"].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 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7() {
return _regenerator["default"].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 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8() {
return _regenerator["default"].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 (0, _DropdownLayoutUni.dropdownLayoutDriverFactory)(base);
};
var dropdownLayoutDriver = (0, _InputWithOptionsProxy.dropdownLayoutDriverProxy)(dropdownLayoutDummy, dropdownLayoutTestkit, popoverTestkit, inputTestkit);
return {
exists: function exists() {
return driver.exists();
},
driver: driver,
inputDriver: inputTestkit,
dropdownLayoutDriver: dropdownLayoutDriver
};
};
exports.inputWithOptionsUniDriverFactory = inputWithOptionsUniDriverFactory;