@vibe/testkit
Version:
Vibe e2e testing toolkit
106 lines • 4.78 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.Combobox = void 0;
const test_1 = require("@playwright/test");
const BaseElement_1 = require("./BaseElement");
const ListItem_1 = require("./ListItem");
const Search_1 = require("./Search");
/**
* Class representing a Combobox element.
* Extends the BaseElement class.
*/
class Combobox extends BaseElement_1.BaseElement {
/**
* Create a Combobox element.
* @param {Page} page - The Playwright page object.
* @param {Locator} locator - The locator for the Combobox element.
* @param {string} elementReportName - The name for reporting purposes.
*/
constructor(page, locator, elementReportName) {
super(page, locator, elementReportName);
this.searchField = new Search_1.Search(page, locator, `${elementReportName} - Search Field`);
}
/**
* Get a combobox item by option.
* @param {string} option - The name of the option to get the combobox item for.
* @returns {Promise<ListItem>} The combobox item.
*/
getComboboxItemByOption(option) {
return __awaiter(this, void 0, void 0, function* () {
return yield test_1.test.step(`Get combobox item by option ${option} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
return new ListItem_1.ListItem(this.getPage(), this.getLocator().getByText(option), option);
}));
});
}
/**
* Select an item from the combobox.
* @param {string} item - The name of the item to select.
* @returns {Promise<void>}
*/
selectItem(item) {
return __awaiter(this, void 0, void 0, function* () {
yield test_1.test.step(`Select item ${item} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
yield this.search(item);
const comboBoxItem = yield this.getComboboxItemByOption(item);
yield comboBoxItem.click();
}));
});
}
/**
* Search for an option in the combobox.
* @param {string} option - The name of the option to search for.
* @returns {Promise<void>}
*/
search(option) {
return __awaiter(this, void 0, void 0, function* () {
yield test_1.test.step(`Search for ${option} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
yield this.searchField.setText(option);
}));
});
}
/**
* Clear the search.
* @returns {Promise<void>}
*/
clearSearch() {
return __awaiter(this, void 0, void 0, function* () {
yield test_1.test.step(`Clear search for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
yield this.searchField.clickClearSearchButton();
}));
});
}
/**
* Get the search input value.
* @returns {Promise<string>} The search input value.
*/
getSearchInputValue() {
return __awaiter(this, void 0, void 0, function* () {
return yield test_1.test.step(`Get search input value for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
return yield this.searchField.getText();
}));
});
}
/**
* Check if the search result is visible.
* @param {string} item - The name of the item to check if the search result is visible for.
* @returns {Promise<boolean>} True if the search result is visible, false otherwise.
*/
isSearchResultVisible(item) {
return __awaiter(this, void 0, void 0, function* () {
return yield test_1.test.step(`Check if search result is visible for ${item} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
return (yield this.getComboboxItemByOption(item)).isVisible(2000);
}));
});
}
}
exports.Combobox = Combobox;
//# sourceMappingURL=Combobox.js.map