@vibe/testkit
Version:
Vibe e2e testing toolkit
108 lines • 4.77 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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SplitButton = void 0;
const test_1 = require("@playwright/test");
const BaseElement_1 = require("./BaseElement");
const Button_1 = require("./Button");
/**
* Class representing a SplitButton element.
* Extends the BaseElement class.
*/
class SplitButton extends BaseElement_1.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_1.Button(page, locator.locator("button").first(), `${elementReportName} - Primary Button`);
this.secondaryButton = new Button_1.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_1.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_1.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_1.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_1.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_1.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_1.test.step(`Check if menu is expanded for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
return yield this.secondaryButton.isExpanded();
}));
});
}
}
exports.SplitButton = SplitButton;
//# sourceMappingURL=SplitButton.js.map