UNPKG

@vibe/testkit

Version:
142 lines 6.15 kB
"use strict"; 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.Dropdown = void 0; const test_1 = require("@playwright/test"); const TextField_1 = require("./TextField"); const BaseElement_1 = require("./BaseElement"); const ListItem_1 = require("./ListItem"); const IconButton_1 = require("./IconButton"); /** * Class representing a Dropdown element. * Extends the BaseElement class. */ class Dropdown extends BaseElement_1.BaseElement { /** * Create a Dropdown element. * @param {Page} page - The Playwright page object. * @param {Locator} locator - The locator for the Dropdown element. * @param {string} elementReportName - The name for reporting purposes. */ constructor(page, locator, elementReportName) { super(page, locator, elementReportName); this.inputField = new TextField_1.TextField(page, locator.locator("input"), `${elementReportName} - Input Field`); this.clearSelectionIconButton = new IconButton_1.IconButton(page, locator.locator(".clear-indicator"), `${elementReportName} - Clear Selection Icon Button`); } /** * Get a dropdown item by item. * @param {string} item - The name of the item to get the dropdown item for. * @returns {Promise<ListItem>} The dropdown item. */ getDropdownItemByItem(item) { return __awaiter(this, void 0, void 0, function* () { return yield test_1.test.step(`Get dropdown item by item ${item} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { return new ListItem_1.ListItem(this.getPage(), this.getLocator().getByRole("option", { name: item }), item); })); }); } /** * Check if the dropdown is open. * @returns {Promise<boolean>} True if the dropdown is open, false otherwise. */ isDropdownOpen() { return __awaiter(this, void 0, void 0, function* () { return yield test_1.test.step(`Check if dropdown is open for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { return yield this.inputField.isExpanded(); })); }); } /** * Open the dropdown. * @returns {Promise<void>} */ open() { return __awaiter(this, void 0, void 0, function* () { yield test_1.test.step(`Open dropdown for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { if (!(yield this.isDropdownOpen())) { yield this.click(); // Wait for the dropdown to open yield this.getPage().waitForTimeout(200); } })); }); } /** * Close the dropdown. * @returns {Promise<void>} */ close() { return __awaiter(this, void 0, void 0, function* () { yield test_1.test.step(`Close dropdown for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { if (yield this.isDropdownOpen()) { yield this.click(); // Wait for the dropdown to close yield this.getPage().waitForTimeout(200); } })); }); } /** * Select an item from a dropdown. * @param {string} item - The value text to be selected in the dropdown. * @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.open(); yield this.search(item); const listItem = yield this.getDropdownItemByItem(item); yield listItem.click(); })); }); } /** * Search for an item in the dropdown. * @param {string} item - The value text to be searched in the dropdown. * @returns {Promise<void>} */ search(item) { return __awaiter(this, void 0, void 0, function* () { yield test_1.test.step(`Search for ${item} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { yield this.inputField.setText(item); })); }); } /** * Select multiple items from a dropdown. * @param items - The values text to be selected in the dropdown. * @returns {Promise<void>} */ selectMultipleItems(items) { return __awaiter(this, void 0, void 0, function* () { yield test_1.test.step(`Select multiple items ${items} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { yield this.open(); for (const item of items) { yield this.selectItem(item); } })); }); } /** * Clear the selection. * @returns {Promise<void>} */ clearSelection() { return __awaiter(this, void 0, void 0, function* () { yield test_1.test.step(`Clear selection for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { yield this.clearSelectionIconButton.click(); })); }); } } exports.Dropdown = Dropdown; //# sourceMappingURL=Dropdown.js.map