@vibe/testkit
Version:
Vibe e2e testing toolkit
158 lines • 6.65 kB
JavaScript
"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.Toast = void 0;
const test_1 = require("@playwright/test");
const BaseElement_1 = require("./BaseElement");
const IconButton_1 = require("./IconButton");
const Link_1 = require("./Link");
const Loader_1 = require("./Loader");
const Button_1 = require("./Button");
/**
* Class representing a Toast element.
* Extends the BaseElement class.
*/
class Toast extends BaseElement_1.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_1.IconButton(page, locator.locator("button").last(), `${elementReportName} - Close Button`);
this.link = new Link_1.Link(page, locator.locator("a"), `${elementReportName} - Link`);
this.loader = new Loader_1.Loader(page, locator.getByRole("alert"), `${elementReportName} - Loader`);
this.button = new Button_1.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_1.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_1.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_1.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_1.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_1.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_1.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_1.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_1.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_1.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_1.test.step(`Get content for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
return yield this.getText();
}));
});
}
}
exports.Toast = Toast;
//# sourceMappingURL=Toast.js.map