UNPKG

wix-style-react

Version:
70 lines (61 loc) 1.87 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var popoverMenuDriverFactory = function popoverMenuDriverFactory(component) { var _menuItemDataHook = void 0; var itemsArray = function itemsArray() { return $$(_menuItemDataHook.split(' ').reduce(function (q, hook) { return q + ('[data-hook~="' + hook + '"]'); }, '')); }; var itemAt = function itemAt(index) { return itemsArray().get(index); }; // before accessing menu methods one need to init driver with menu-item data hook var protect = function protect(fn) { return function () { if (!_menuItemDataHook) { throw new Error('Before accessing menu fields init menu item data hook with "driver.given.menuItemDataHook(\'myDataHook\')" command'); } return fn.apply(undefined, arguments); }; }; var driver = { exists: function exists() { return component.isPresent(); }, click: function click() { return component.click(); }, element: function element() { return component; }, init: { menuItemDataHook: function menuItemDataHook(dataHook) { _menuItemDataHook = dataHook; return driver; } }, menu: { isShown: protect(function () { return driver.menu.element().isDisplayed(); }), itemsLength: protect(function () { return itemsArray().count(); }), itemContentAt: protect(function (index) { return itemAt(index).$$('button >span').get(1).getText(); }), clickItemAt: protect(function (index) { return itemAt(index).click(); }), // menu items parent node (not actual menu root) element: protect(function () { return itemAt(0).element(by.xpath('..')); }) } }; return driver; }; exports.default = popoverMenuDriverFactory;