UNPKG

@nova-ui/bits

Version:

SolarWinds Nova Framework

150 lines 5.53 kB
// © 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. import { MenuItemAtom } from "./menu-item.atom"; import { Atom } from "../../atom"; import { Helpers } from "../../setup"; import { ButtonAtom } from "../button/button.atom"; import { PopupAtom } from "../popup/popup.atom"; export class MenuAtom extends Atom { static { this.CSS_CLASS = "nui-menu"; } // Returns all menu items (excluding headers) getAllMenuItems() { return this.getLocator().locator(".nui-menu-item:not(.nui-menu-item--header)"); } getPopupBox() { return Atom.findIn(PopupAtom, this.getLocator()); } getMenuButton() { return Atom.findIn(ButtonAtom, this.getLocator()); } async getMenuButtonIconName() { const button = this.getMenuButton(); const icon = button.getIcon(); return icon.getName(); } async toggleMenu() { await this.getMenuButton().click(); } getMenuItemByContainingText(text) { const itemLocator = this.getLocator().locator(".nui-menu-item", { hasText: text, }); return Atom.findIn(MenuItemAtom, itemLocator, true); } async itemCount() { return await this.getAllMenuItems().count(); } async isMenuOpened() { return await this.getPopupBox().isOpened(); } async isMenuClosed() { return await this.getPopupBox().isNotOpened(); } async mouseDownOnMenuButton() { await this.getMenuButton().mouseDown(); } async mouseUp() { await Helpers.page.mouse.up(); } getMenuItemByIndex(idx) { const itemLocator = this.getAllMenuItems().nth(idx); return Atom.findIn(MenuItemAtom, itemLocator, true); } async getMenuItems() { const count = await this.getAllMenuItems().count(); const items = []; for (let i = 0; i < count; i++) { items.push(this.getMenuItemByIndex(i)); } return items; } async getItemTextArray() { const items = this.getAllMenuItems(); const count = await items.count(); const texts = []; for (let i = 0; i < count; i++) { texts.push(await items.nth(i).innerText()); } return texts; } getHeaderElements() { return this.getLocator().locator(".nui-menu-item--header"); } async getHeaderTextArray() { const headers = this.getHeaderElements(); const count = await headers.count(); const texts = []; for (let i = 0; i < count; i++) { texts.push(await headers.nth(i).innerText()); } return texts; } async clickHeaderByIndex(idx) { const headers = this.getHeaderElements(); await headers.nth(idx).click(); } getDividerElements() { return this.getLocator().locator(".nui-divider"); } async clickDividerByIndex(idx) { const dividers = this.getDividerElements(); await dividers.nth(idx).click(); } getSelectedCheckboxElements() { return this.getLocator().locator(".nui-checkbox--checked"); } async getSelectedMenuCheckboxes() { const items = this.getSelectedCheckboxElements(); const count = await items.count(); const selected = []; for (let i = 0; i < count; i++) { selected.push(Atom.findIn(MenuItemAtom, items.nth(i))); } return selected; } getSelectedSwitchElements() { return this.getLocator().locator(".nui-switched"); } async getSelectedMenuSwitches() { const items = this.getSelectedSwitchElements(); const count = await items.count(); const selected = []; for (let i = 0; i < count; i++) { selected.push(Atom.findIn(MenuItemAtom, items.nth(i))); } return selected; } async getSelectedCheckboxesCount() { return (await this.getSelectedMenuCheckboxes()).length; } async getSelectedSwitchesCount() { return (await this.getSelectedMenuSwitches()).length; } getAppendToBodyMenu() { if (!this.menuContentId) { throw new Error("menuContentId is not set"); } return Helpers.page.locator(`#${this.menuContentId}`); } getAppendToBodyMenuDividers() { return this.getAppendToBodyMenu().locator(".nui-menu-group-divider--container"); } } //# sourceMappingURL=menu.atom.js.map