UNPKG

@vibe/testkit

Version:
85 lines 3.58 kB
"use strict"; 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()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.MenuButton = void 0; const test_1 = require("@playwright/test"); const Button_1 = require("./Button"); /** * Class representing a menu button that extends the Button class. */ class MenuButton extends Button_1.Button { /** * Create a MenuButton. * @param {Page} page - The Playwright page object. * @param {Locator} locator - The locator for the MenuButton element. * @param {string} elementReportName - The name for reporting purposes. * @param {any} menuType - The type of menu associated with the button. */ constructor(page, locator, elementReportName, menuType) { super(page, locator, elementReportName); this.button = new Button_1.Button(this.page, this.locator, elementReportName); this.menu = menuType; } /** * Select an item from the menu. * @param {string} item - The item to select. * @returns {Promise<void>} */ selectItem(item) { return __awaiter(this, void 0, void 0, function* () { yield test_1.test.step(`Select ${item} from ${this.elementReportName}`, () => __awaiter(this, void 0, void 0, function* () { yield this.openMenu(); yield this.menu.selectItem(item); })); }); } /** * Open the menu if it is not already expanded. * @returns {Promise<void>} */ openMenu() { return __awaiter(this, void 0, void 0, function* () { yield test_1.test.step(`Open menu in ${this.elementReportName}`, () => __awaiter(this, void 0, void 0, function* () { if (!(yield this.isExpanded())) { yield this.button.click(); } })); }); } /** * Close the menu if it is currently expanded. * @returns {Promise<void>} */ closeMenu() { return __awaiter(this, void 0, void 0, function* () { yield test_1.test.step(`Close menu in ${this.elementReportName}`, () => __awaiter(this, void 0, void 0, function* () { if (yield this.isExpanded()) { yield this.button.click(); } })); }); } /** * Check if the menu is expanded. * @returns {Promise<boolean>} True if the menu is expanded, false otherwise. */ isExpanded() { return __awaiter(this, void 0, void 0, function* () { let isExpanded = false; yield test_1.test.step(`Check if menu is expanded in ${this.elementReportName}`, () => __awaiter(this, void 0, void 0, function* () { isExpanded = (yield this.button.getAttributeValue("aria-expanded")) === "true"; })); return isExpanded; }); } } exports.MenuButton = MenuButton; //# sourceMappingURL=MenuButton.js.map