UNPKG

wix-style-react

Version:
135 lines (112 loc) 5.47 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 { dropdownBaseDriverFactory } from '../DropdownBase/DropdownBase.uni.driver'; import { dropdownLayoutDriverFactory } from '../DropdownLayout/DropdownLayout.uni.driver'; import popoverCommonDriverFactory from '../Popover/Popover.common.driver'; import { baseUniDriverFactory } from 'wix-ui-test-utils/base-driver'; export var PopoverMenuDriver = function PopoverMenuDriver(base, body) { var dropdownBaseTestkit = dropdownBaseDriverFactory(base, body); var createDropdownLayoutDriver = /*#__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: _context.t0 = dropdownLayoutDriverFactory; _context.next = 3; return getContentElement(); case 3: _context.t1 = _context.sent.$("[data-hook=\"dropdown-base-dropdownlayout\"]"); return _context.abrupt("return", (0, _context.t0)(_context.t1)); case 5: case "end": return _context.stop(); } } }, _callee); })); return function createDropdownLayoutDriver() { return _ref.apply(this, arguments); }; }(); var getContentElement = /*#__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: return _context2.abrupt("return", popoverCommonDriverFactory(base, body).getContentElement()); case 1: case "end": return _context2.stop(); } } }, _callee2); })); return function getContentElement() { return _ref2.apply(this, arguments); }; }(); return _objectSpread(_objectSpread({}, baseUniDriverFactory(base)), {}, { /** Returns true of popoverMenu exists */ exists: function exists() { return dropdownBaseTestkit.exists(); }, /** Returns trigger element */ getTriggerElement: function getTriggerElement(dataHook) { return base.$("[data-hook=\"".concat(dataHook, "\"]")); }, /** Select a specific option by its index (requires the menu to be opened) */ clickAtChild: function clickAtChild(index) { return dropdownBaseTestkit.selectOption(index); }, /** Select a specific option by its data-hook (requires the menu to be opened) */ clickAtChildByDataHook: function clickAtChildByDataHook(dataHook) { return dropdownBaseTestkit.selectOptionByDataHook(dataHook); }, /** Return true if the menu is opened */ isMenuOpen: function isMenuOpen() { return dropdownBaseTestkit.isDropdownShown(); }, /** Returns children count */ childrenCount: function childrenCount() { return dropdownBaseTestkit.optionsCount(); }, /** Returns text of <PopoverMenu.MenuItem/> of a specific index */ itemContentAt: function () { var _itemContentAt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(index) { var dropdownLayoutDriver, options, nodeContent; return _regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: _context3.next = 2; return createDropdownLayoutDriver(); case 2: dropdownLayoutDriver = _context3.sent; _context3.next = 5; return dropdownLayoutDriver.options(); case 5: options = _context3.sent; nodeContent = options[index].element().$$(':first-child'); _context3.next = 9; return nodeContent.get(0).text(); case 9: return _context3.abrupt("return", _context3.sent); case 10: case "end": return _context3.stop(); } } }, _callee3); })); function itemContentAt(_x) { return _itemContentAt.apply(this, arguments); } return itemContentAt; }() }); };