@vibe/testkit
Version:
Vibe e2e testing toolkit
81 lines • 3.39 kB
JavaScript
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 { Button } from "./Button";
/**
* Class representing a menu button that extends the Button class.
*/
export class MenuButton extends 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(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.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.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.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.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;
});
}
}
//# sourceMappingURL=MenuButton.js.map