@nova-ui/bits
Version:
SolarWinds Nova Framework
116 lines • 7.6 kB
JavaScript
"use strict";
// © 2022 SolarWinds Worldwide, LLC. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
Object.defineProperty(exports, "__esModule", { value: true });
exports.MenuAtom = void 0;
const tslib_1 = require("tslib");
const protractor_1 = require("protractor");
const menu_item_atom_1 = require("./menu-item.atom");
const atom_1 = require("../../atom");
const button_atom_1 = require("../button/button.atom");
const popup_atom_1 = require("../popup/popup.atom");
class MenuAtom extends atom_1.Atom {
constructor() {
super(...arguments);
this.getPopupBox = () => atom_1.Atom.findIn(popup_atom_1.PopupAtom, this.getElement());
this.getMenuButton = () => atom_1.Atom.findIn(button_atom_1.ButtonAtom, this.getElement());
this.getMenuButtonIconName = () => tslib_1.__awaiter(this, void 0, void 0, function* () { return yield this.getMenuButton().getIcon().getName(); });
this.toggleMenu = () => tslib_1.__awaiter(this, void 0, void 0, function* () { return this.getMenuButton().click(); });
this.getMenuItemByContainingText = (text) => atom_1.Atom.findIn(menu_item_atom_1.MenuItemAtom, this.getElementByCssContainingText(".nui-menu-item", text));
this.itemCount = () => tslib_1.__awaiter(this, void 0, void 0, function* () { return this.getItemElements().count(); });
this.isMenuOpened = () => tslib_1.__awaiter(this, void 0, void 0, function* () { return this.getPopupBox().isOpened(); });
this.mouseDownOnMenuButton = () => tslib_1.__awaiter(this, void 0, void 0, function* () { return this.getMenuButton().mouseDown(); });
this.mouseUp = () => tslib_1.__awaiter(this, void 0, void 0, function* () { return protractor_1.browser.actions().mouseUp().perform(); });
this.getMenuItemByIndex = (idx) => atom_1.Atom.findIn(menu_item_atom_1.MenuItemAtom, this.getItemElements().get(idx));
// DO NOT USE. The following method is broken and will be fixed in the scope of NUI-6105
this.getMenuItems = () => tslib_1.__awaiter(this, void 0, void 0, function* () {
return this.getItemElements().map((elementFinder) => {
if (!elementFinder) {
throw new Error("elementFinder is not defined");
}
return new menu_item_atom_1.MenuItemAtom(elementFinder);
});
});
this.getItemTextArray = () => tslib_1.__awaiter(this, void 0, void 0, function* () {
return yield this.getItemElements().map((elementFinder) => tslib_1.__awaiter(this, void 0, void 0, function* () { return elementFinder === null || elementFinder === void 0 ? void 0 : elementFinder.getText(); }));
});
this.getHeaderTextArray = () => tslib_1.__awaiter(this, void 0, void 0, function* () {
return yield this.getHeaderElements().map((elementFinder) => tslib_1.__awaiter(this, void 0, void 0, function* () { return elementFinder === null || elementFinder === void 0 ? void 0 : elementFinder.getText(); }));
});
this.clickHeaderByIndex = (idx) => tslib_1.__awaiter(this, void 0, void 0, function* () {
const headers = this.getHeaderElements();
yield protractor_1.browser.wait(() => tslib_1.__awaiter(this, void 0, void 0, function* () { return headers.get(idx).isDisplayed(); }));
yield headers.get(idx).click();
});
this.clickDividerByIndex = (idx) => tslib_1.__awaiter(this, void 0, void 0, function* () {
const dividers = this.getElement().all(protractor_1.by.className("nui-divider"));
yield protractor_1.browser.wait(() => tslib_1.__awaiter(this, void 0, void 0, function* () { return dividers.get(idx).isDisplayed(); }));
yield dividers.get(idx).element(protractor_1.by.xpath("..")).click();
});
this.getSelectedCheckboxesCount = () => tslib_1.__awaiter(this, void 0, void 0, function* () { return (yield this.getSelectedMenuCheckboxes()).length; });
this.getSelectedSwitchesCount = () => tslib_1.__awaiter(this, void 0, void 0, function* () { return (yield this.getSelectedMenuSwitches()).length; });
this.getAppendToBodyMenu = () => protractor_1.browser.element(protractor_1.by.id(this.menuContentId));
this.getAppendToBodyMenuDividers = () => this.getAppendToBodyMenu().all(protractor_1.by.className("nui-menu-group-divider--container"));
this.getHeaderElements = () => super.getElement().all(protractor_1.by.css(".nui-menu-item--header"));
this.getSelectedCheckboxElements = () => super.getElement().all(protractor_1.by.css(".nui-checkbox--checked"));
this.getSelectedSwitchElements = () => super.getElement().all(protractor_1.by.css(".nui-switched"));
this.getElementByCssContainingText = (selector, text) => this.getElement().all(protractor_1.by.cssContainingText(selector, text)).first();
}
/**
* Returns array of checked checkboxes
* @returns {Promise<MenuItemAtom[]>}
*/
getSelectedMenuCheckboxes() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const menuItems = this.getSelectedCheckboxElements();
const menuItemsCount = yield menuItems.count();
const menuItemsSelected = [];
for (let i = 0; i < menuItemsCount; i++) {
menuItemsSelected.push(new menu_item_atom_1.MenuItemAtom(menuItems.get(i)));
}
return menuItemsSelected;
});
}
/**
* Returns array of checked switches
* @returns {Promise<MenuItemAtom[]>}
*/
getSelectedMenuSwitches() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const menuItems = this.getSelectedSwitchElements();
const menuItemsCount = yield menuItems.count();
const menuItemsSelected = [];
for (let i = 0; i < menuItemsCount; i++) {
menuItemsSelected.push(new menu_item_atom_1.MenuItemAtom(menuItems.get(i)));
}
return menuItemsSelected;
});
}
getItemElements() {
const parentElement = this.menuContentId
? this.getAppendToBodyMenu()
: super.getElement();
return parentElement.all(protractor_1.by.css(".nui-menu-item:not(.nui-menu-item--header)"));
}
}
exports.MenuAtom = MenuAtom;
MenuAtom.CSS_CLASS = "nui-menu";
MenuAtom.getAllMenuItems = () => protractor_1.element.all(protractor_1.by.css(".nui-menu-item:not(.nui-menu-item--header"));
//# sourceMappingURL=menu.atom.js.map