@vibe/testkit
Version:
Vibe e2e testing toolkit
104 lines • 4.55 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 { BaseElement } from "./BaseElement";
import { Button } from "./Button";
/**
* Class representing a SplitButton element.
* Extends the BaseElement class.
*/
export class SplitButton extends BaseElement {
/**
* Create a SplitButton element.
* @param {Page} page - The Playwright page object.
* @param {Locator} locator - The locator for the SplitButton element.
* @param {string} elementReportName - The name for reporting purposes.
*/
constructor(page, locator, elementReportName, menu) {
super(page, locator, elementReportName);
this.primaryButton = new Button(page, locator.locator("button").first(), `${elementReportName} - Primary Button`);
this.secondaryButton = new Button(page, locator.locator("button").last(), `${elementReportName} - Secondary Button`);
this.menu = menu;
}
/**
* Select an item from the menu.
* @param {string} itemName - The name of the item to select.
* @returns {Promise<void>}
*/
selectItem(itemName) {
return __awaiter(this, void 0, void 0, function* () {
yield test.step(`Select item by name ${itemName} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
yield this.openMenu();
yield this.menu.selectItem(itemName);
}));
});
}
/**
* Open the secondary button menu.
*/
openMenu() {
return __awaiter(this, void 0, void 0, function* () {
yield test.step(`Open menu for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
if (!(yield this.isMenuExpanded())) {
yield this.secondaryButton.click();
// Wait for the menu to open
yield this.getPage().waitForTimeout(100);
}
}));
});
}
/**
* Close the secondary button menu.
*/
closeMenu() {
return __awaiter(this, void 0, void 0, function* () {
yield test.step(`Close menu for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
if (yield this.isMenuExpanded()) {
yield this.secondaryButton.click();
// Wait for the menu to close
yield this.getPage().waitForTimeout(100);
}
}));
});
}
/**
* Click the primary button.
*/
clickPrimaryButton() {
return __awaiter(this, void 0, void 0, function* () {
yield test.step(`Click primary button for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
yield this.primaryButton.click();
}));
});
}
/**
* Get the text of the primary button.
* @returns {Promise<string>} The text of the primary button.
*/
getPrimaryButtonText() {
return __awaiter(this, void 0, void 0, function* () {
return yield test.step(`Get primary button text for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
return yield this.primaryButton.getText();
}));
});
}
/**
* Check if the secondary button menu is expanded.
* @returns {Promise<boolean>} True if the secondary button menu is expanded, false otherwise.
*/
isMenuExpanded() {
return __awaiter(this, void 0, void 0, function* () {
return yield test.step(`Check if menu is expanded for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
return yield this.secondaryButton.isExpanded();
}));
});
}
}
//# sourceMappingURL=SplitButton.js.map