UNPKG

wix-style-react

Version:
307 lines (254 loc) • 10.9 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } import _regeneratorRuntime from "@babel/runtime/regenerator"; import { baseUniDriverFactory, findByHook } from '../../test/utils/unidriver'; import { dropdownLayoutDriverFactory } from '../DropdownLayout/DropdownLayout.uni.driver'; import { testkit } from "wix-ui-core/dist/es/src/components/popover/Popover.uni.driver"; import popoverCommonDriverFactory from '../Popover/Popover.common.driver'; import { DATA_HOOKS } from '../DropdownLayout/DataAttr'; export var dropdownBaseDriverFactory = function dropdownBaseDriverFactory(base, body) { var byDataHook = function byDataHook(dataHook) { return base.$("[data-hook=\"".concat(dataHook, "\"]")); }; var getTargetElement = function getTargetElement(dataHook) { return byDataHook(dataHook); }; var getContentElement = /*#__PURE__*/function () { var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: return _context.abrupt("return", popoverCommonDriverFactory(base, body).getContentElement()); case 1: case "end": return _context.stop(); } } }, _callee); })); return function getContentElement() { return _ref.apply(this, arguments); }; }(); var createDropdownLayoutDriver = /*#__PURE__*/function () { var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() { return _regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: _context2.t0 = dropdownLayoutDriverFactory; _context2.next = 3; return getContentElement(); case 3: _context2.t1 = _context2.sent.$("[data-hook=\"dropdown-base-dropdownlayout\"]"); return _context2.abrupt("return", (0, _context2.t0)(_context2.t1)); case 5: case "end": return _context2.stop(); } } }, _callee2); })); return function createDropdownLayoutDriver() { return _ref2.apply(this, arguments); }; }(); return _objectSpread(_objectSpread({}, baseUniDriverFactory(base)), {}, { /** Returns the target element */ clickTargetElement: function clickTargetElement(dataHook) { return getTargetElement(dataHook).click(); }, /** Hover the target element */ hoverTargetElement: function hoverTargetElement(dataHook) { return getTargetElement(dataHook).hover(); }, /** Returns `true` if the dropdown is being shown */ isDropdownShown: function isDropdownShown() { return testkit(base, body).isContentElementExists(); }, /** Select a specific option (requires the DropdownBase to be opened) */ selectOption: function () { var _selectOption = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(index) { return _regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: _context3.next = 2; return createDropdownLayoutDriver(); case 2: return _context3.abrupt("return", _context3.sent.clickAtOption(index)); case 3: case "end": return _context3.stop(); } } }, _callee3); })); function selectOption(_x) { return _selectOption.apply(this, arguments); } return selectOption; }(), /** Select a specific option by its data hook (requires the DropdownBase to be opened) */ selectOptionByDataHook: function () { var _selectOptionByDataHook = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(dataHook) { return _regeneratorRuntime.wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: _context4.next = 2; return createDropdownLayoutDriver(); case 2: return _context4.abrupt("return", _context4.sent.clickAtOptionByDataHook(dataHook)); case 3: case "end": return _context4.stop(); } } }, _callee4); })); function selectOptionByDataHook(_x2) { return _selectOptionByDataHook.apply(this, arguments); } return selectOptionByDataHook; }(), /** Click outside of the component */ clickOutside: function clickOutside() { return testkit(base, body).clickOutside(); }, /** Options count (requires the DropdownBase to be opened) */ optionsCount: function () { var _optionsCount = _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 createDropdownLayoutDriver(); case 2: return _context5.abrupt("return", _context5.sent.optionsLength()); case 3: case "end": return _context5.stop(); } } }, _callee5); })); function optionsCount() { return _optionsCount.apply(this, arguments); } return optionsCount; }(), optionContentAt: function () { var _optionContentAt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(position) { var dropdownLayoutDriver, optionsDrivers, optionElement, option, nodeContent, contentIsNode; return _regeneratorRuntime.wrap(function _callee6$(_context6) { while (1) { switch (_context6.prev = _context6.next) { case 0: _context6.next = 2; return createDropdownLayoutDriver(); case 2: dropdownLayoutDriver = _context6.sent; _context6.next = 5; return dropdownLayoutDriver.options(); case 5: optionsDrivers = _context6.sent; _context6.next = 8; return optionsDrivers[position].element(); case 8: optionElement = _context6.sent; _context6.next = 11; return findByHook(optionElement, DATA_HOOKS.OPTION); case 11: option = _context6.sent; /* Option content can be 1. node - <div>some text</div> 2. text - some text */ nodeContent = option.$$(':first-child'); _context6.next = 15; return nodeContent.count(); case 15: _context6.t0 = _context6.sent; contentIsNode = _context6.t0 > 0; if (!contentIsNode) { _context6.next = 23; break; } _context6.next = 20; return nodeContent.get(0).getNative(); case 20: return _context6.abrupt("return", _context6.sent); case 23: return _context6.abrupt("return", option.text()); case 24: case "end": return _context6.stop(); } } }, _callee6); })); function optionContentAt(_x3) { return _optionContentAt.apply(this, arguments); } return optionContentAt; }(), /** Returns the selected option (requires the DropdownBase to be opened)*/ getSelectedOptionId: function () { var _getSelectedOptionId = _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 createDropdownLayoutDriver(); case 2: return _context7.abrupt("return", _context7.sent.getSelectedOptionId()); case 3: case "end": return _context7.stop(); } } }, _callee7); })); function getSelectedOptionId() { return _getSelectedOptionId.apply(this, arguments); } return getSelectedOptionId; }(), /** Returns the marked option (requires the DropdownBase to be opened)*/ getMarkedOption: function () { var _getMarkedOption = _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 createDropdownLayoutDriver(); case 2: return _context8.abrupt("return", _context8.sent.markedOption()); case 3: case "end": return _context8.stop(); } } }, _callee8); })); function getMarkedOption() { return _getMarkedOption.apply(this, arguments); } return getMarkedOption; }(), mouseEnter: function mouseEnter() { return testkit(base, body).mouseEnter(); }, mouseLeave: function mouseLeave() { return testkit(base, body).mouseLeave(); } }); };