@vibe/testkit
Version:
Vibe e2e testing toolkit
94 lines • 4.16 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.Search = void 0;
const test_1 = require("@playwright/test");
const BaseElement_1 = require("./BaseElement");
const TextField_1 = require("./TextField");
const IconButton_1 = require("./IconButton");
const MenuButton_1 = require("./MenuButton");
/**
* Class representing a Search element.
* Extends the BaseElement class.
*/
class Search extends BaseElement_1.BaseElement {
/**
* Create a Search element.
* @param {Page} page - The Playwright page object.
* @param {Locator} locator - The locator for the Search element.
* @param {string} elementReportName - The name for reporting purposes.
*/
constructor(page, locator, elementReportName, filterMenuType) {
super(page, locator, elementReportName);
this.input = new TextField_1.TextField(page, locator.locator("[type='search']"), `${elementReportName} - Input`);
this.clearSearchIconButton = new IconButton_1.IconButton(page, locator.locator("[aria-label='Clear']"), `${elementReportName} - Clear Search Icon Button`);
if (filterMenuType) {
this.filterButton = new MenuButton_1.MenuButton(this.getPage(), this.getLocator().locator("[aria-label='Filters']").nth(1), "Filter Button", filterMenuType);
}
}
/**
* Set specified text in search field.
* @param {string} text - Text to be filled in the search field.
* @returns {Promise<void>}
*/
setText(text) {
return __awaiter(this, void 0, void 0, function* () {
yield test_1.test.step(`Set text: ${text} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
yield this.input.setText(text);
}));
});
}
/**
* Clear the text in the search field.
*/
clear() {
return __awaiter(this, void 0, void 0, function* () {
yield test_1.test.step(`Clear text for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
yield this.input.clearText();
}));
});
}
/**
* Get the text from the search field.
* @returns {Promise<string>} The text from the search field.
*/
getText() {
return __awaiter(this, void 0, void 0, function* () {
return yield test_1.test.step(`Get text for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
return yield this.input.getText();
}));
});
}
/**
* Check if the search field is empty.
* @returns {Promise<string>}
*/
isEmpty() {
return __awaiter(this, void 0, void 0, function* () {
return yield test_1.test.step(`Check if search field is empty for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
return yield this.input.isEmpty();
}));
});
}
/**
* Click the clear search button.
* @returns {Promise<void>}
*/
clickClearSearchButton() {
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.clearSearchIconButton.click();
}));
});
}
}
exports.Search = Search;
//# sourceMappingURL=Search.js.map