UNPKG

@vibe/testkit

Version:
120 lines 5.77 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { test } from "@playwright/test"; import { MenuItem } from "./MenuItem"; import { BaseElement } from "./BaseElement"; /** * Class representing a Menu element. * Extends the BaseElement class. */ export class Menu extends BaseElement { /** * Create a Menu element. * @param {Page} page - The Playwright page object. * @param {Locator} locator - The locator for the Menu element. * @param {string} elementReportName - The name for reporting purposes. */ constructor(page, locator, elementReportName) { super(page, locator, elementReportName); } /** * Get all menu items. * @returns {Promise<MenuItem[]>} An array of menu items. */ getAllMenuItems() { return __awaiter(this, void 0, void 0, function* () { return yield test.step(`Get all menu items for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { const items = yield this.getLocator().getByRole("menuitem").all(); return items.map((item, index) => new MenuItem(this.getPage(), item, `Menu item ${index}`)); })); }); } /** * Get a menu item by its name. * @param {string} itemName - The name of the item to retrieve. * @returns {Promise<MenuItem>} The menu item with the specified name. */ getItemByName(itemName) { return __awaiter(this, void 0, void 0, function* () { return yield test.step(`Get menu item by name ${itemName} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { return new MenuItem(this.getPage(), this.getLocator().getByRole("menuitem", { name: itemName }), itemName); })); }); } /** * Get a menu item by its index. * @param {number} index - The index of the item to retrieve. * @returns {Promise<MenuItem>} The menu item with the specified index. */ getItemByIndex(index) { return __awaiter(this, void 0, void 0, function* () { return yield test.step(`Get menu item by index ${index} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { return new MenuItem(this.getPage(), this.getLocator().getByRole("menuitem").nth(index), `Menu item ${index}`); })); }); } /** * Click a menu item by its name. * @param {string} itemName - The name of the item to click. * @returns {Promise<void>} */ selectItem(itemName) { return __awaiter(this, void 0, void 0, function* () { yield test.step(`Click menu item by name ${itemName} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { const menuItem = yield this.getItemByName(itemName); yield menuItem.hover(); yield menuItem.click(); })); }); } /** * Select a sub menu item. * @param {string} rootItem - The name of the root item. * @param {string} subItem - The name of the sub item. * @returns {Promise<void>} */ selectSubItem(rootItem, subItem) { return __awaiter(this, void 0, void 0, function* () { yield test.step(`Select sub menu item ${subItem} in ${rootItem} in ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { const rootMenuItem = yield this.getItemByName(rootItem); yield rootMenuItem.hover(); const secondaryMenu = new Menu(this.getPage(), this.getPage().locator(`.secondary-menu-enter-done`), `Secondary Menu`); yield secondaryMenu.selectItem(subItem); })); }); } /** * Check if a menu item is disabled. * @param {string} itemName - The name of the item to check. * @returns {Promise<boolean>} True if the menu item is disabled, false otherwise. */ isMenuItemDisabled(itemName) { return __awaiter(this, void 0, void 0, function* () { return yield test.step(`Check if menu item is disabled for ${itemName} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { const menuItem = yield this.getItemByName(itemName); return (yield menuItem.getComputedStyle("cursor")) === "not-allowed"; })); }); } /** * Get the name of a menu item by its index. * @param {number} index - The index of the item to retrieve. * @returns {Promise<string>} The name of the menu item with the specified index. */ getMenuItemNameByIndex(index) { return __awaiter(this, void 0, void 0, function* () { return yield test.step(`Get menu item name by index ${index} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { const menuItem = yield this.getItemByIndex(index); return yield menuItem.getText(); })); }); } } //# sourceMappingURL=Menu.js.map