UNPKG

@vibe/testkit

Version:
154 lines 6.4 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 { IconButton } from "./IconButton"; import { Link } from "./Link"; import { Loader } from "./Loader"; import { Button } from "./Button"; /** * Class representing a Toast element. * Extends the BaseElement class. */ export class Toast extends BaseElement { /** * Create a Toast element. * @param {Page} page - The Playwright page object. * @param {Locator} locator - The locator for the Toast element. * @param {string} elementReportName - The name for reporting purposes. */ constructor(page, locator, elementReportName) { super(page, locator, elementReportName); this.closeButton = new IconButton(page, locator.locator("button").last(), `${elementReportName} - Close Button`); this.link = new Link(page, locator.locator("a"), `${elementReportName} - Link`); this.loader = new Loader(page, locator.getByRole("alert"), `${elementReportName} - Loader`); this.button = new Button(page, locator.locator("button").first(), `${elementReportName} - Button`); } /** * Close the toast. * @returns {Promise<void>} */ close() { return __awaiter(this, void 0, void 0, function* () { yield test.step(`Click close button for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { yield this.closeButton.click(); })); }); } /** * Check if the toast has a close button. * @returns {Promise<boolean>} True if the toast has a close button, false otherwise. */ hasCloseButton() { return __awaiter(this, void 0, void 0, function* () { return yield test.step(`Check if toast has close button for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { return yield this.closeButton.isVisible(); })); }); } /** * Get the type of the toast. * @returns {Promise<string | null>} The type of the toast. */ getType() { return __awaiter(this, void 0, void 0, function* () { return yield test.step(`Get toast type: ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { const classList = yield this.getAttributeValue("class"); if (!classList) return null; const types = ["normal", "positive", "negative", "warning", "dark"]; for (const type of types) { if (classList.includes(`type${type.charAt(0).toUpperCase() + type.slice(1)}`)) { return type; } } return "normal"; })); }); } /** * Check if the toast is loading. * @returns {Promise<boolean>} True if the toast is loading, false otherwise. */ isLoading() { return __awaiter(this, void 0, void 0, function* () { return yield test.step(`Check if toast is loading: ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { return yield this.loader.isVisible(); })); }); } /** * Get the text of the link. * @returns {Promise<string>} The text of the link. */ getLinkText() { return __awaiter(this, void 0, void 0, function* () { return yield test.step(`Get link text for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { return yield this.link.getText(); })); }); } /** * Get the href of the link. * @returns {Promise<string>} The href of the link. */ getLinkHref() { return __awaiter(this, void 0, void 0, function* () { return yield test.step(`Get link href for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { return yield this.link.getLinkHref(); })); }); } /** * Click the link. * @returns {Promise<void>} */ clickLink() { return __awaiter(this, void 0, void 0, function* () { return yield test.step(`Click link for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { yield this.link.click(); })); }); } /** * Click the button. * @returns {Promise<void>} */ clickButton() { return __awaiter(this, void 0, void 0, function* () { return yield test.step(`Click button for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { yield this.button.click(); })); }); } /** * Get the text of the button. * @returns {Promise<string>} The text of the button. */ getButtonText() { return __awaiter(this, void 0, void 0, function* () { return yield test.step(`Get button text for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { return yield this.button.getText(); })); }); } /** * Get the content of the toast. * @returns {Promise<string>} The content of the toast. */ getContent() { return __awaiter(this, void 0, void 0, function* () { return yield test.step(`Get content for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { return yield this.getText(); })); }); } } //# sourceMappingURL=Toast.js.map