UNPKG

@vibe/testkit

Version:
97 lines 4.71 kB
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 { ListItem } from "./ListItem"; /** * Class representing a ColorPicker element. * Extends the BaseElement class. */ export class ColorPicker extends BaseElement { /** * Create a ColorPicker element. * @param {Page} page - The Playwright page object. * @param {Locator} locator - The locator for the ColorPicker element. * @param {string} elementReportName - The name for reporting purposes. */ constructor(page, locator, elementReportName) { super(page, locator, elementReportName); } /** * Get all color picker items. * @returns {Promise<ListItem[]>} An array of color picker items. */ getAllColorPickerItems() { return __awaiter(this, void 0, void 0, function* () { return yield test.step(`Get all color picker items for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { return (yield this.getLocator().locator("li").all()).map((listItem, index) => new ListItem(this.getPage(), listItem, `Color Picker Item ${index + 1}`)); })); }); } /** * Get a color picker item by color. * @param {ColorPickerColor} color - The color to get the color picker item for. * @returns {Promise<ListItem>} The color picker item. */ getColorPickerItemByColor(color) { return __awaiter(this, void 0, void 0, function* () { return yield test.step(`Get color picker item by color ${color} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { return new ListItem(this.getPage(), this.getLocator().getByTestId(`color-picker-item_${color}`), color); })); }); } /** * Select a color from the color picker. * @param {ColorPickerColor} color - The color to select. * @returns {Promise<void>} */ selectColor(color) { return __awaiter(this, void 0, void 0, function* () { yield test.step(`Select color ${color} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { const colorItem = yield this.getColorPickerItemByColor(color); yield colorItem.click(); })); }); } /** * Check if a color is selected. * @param {ColorPickerColor} color - The color to check. * @returns {Promise<boolean>} True if the color is selected, false otherwise. */ isColorSelected(color) { return __awaiter(this, void 0, void 0, function* () { return yield test.step(`Check if color ${color} is selected for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { const colorItem = yield this.getColorPickerItemByColor(color); return (yield colorItem.getAttributeValue("class")).includes("selectedColor"); })); }); } /** * Get the currently selected color. * @returns {Promise<string>} The selected color. */ getSelectedColor() { return __awaiter(this, void 0, void 0, function* () { return yield test.step(`Get selected color for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { const listItems = yield this.getAllColorPickerItems(); // Find the selected color for (const listItem of listItems) { if ((yield listItem.getAttributeValue("class")).includes("selectedColor")) { const dataTestId = yield listItem.getAttributeValue("data-testid"); return dataTestId.replace("color-picker-item_", ""); } } // If no selected color found, throw error throw new Error("No selected color found"); })); }); } } //# sourceMappingURL=ColorPicker.js.map