@vibe/testkit
Version:
Vibe e2e testing toolkit
60 lines • 2.83 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.Toggle = void 0;
const test_1 = require("@playwright/test");
const BaseElement_1 = require("./BaseElement");
const Button_1 = require("./Button");
const TextField_1 = require("./TextField");
/**
* Class representing a Toggle element.
* Extends the BaseElement class.
*/
class Toggle extends BaseElement_1.BaseElement {
/**
* Create a Toggle with a wrapper element that contains the input and button elements.
* @param {Page} page - The Playwright page object.
* @param {Locator} locator - The locator for the wrapper element that contains the input and button elements.
* @param {string} elementReportName - The name for reporting purposes.
*/
constructor(page, locator, elementReportName) {
super(page, locator, elementReportName);
this.input = new TextField_1.TextField(page, locator.locator("input"), `${elementReportName} - Input`);
this.button = new Button_1.Button(page, locator.locator("div"), `${elementReportName} - Button`);
}
/**
* Set the toggle state.
* @param {boolean} isToCheck - True to turn on the toggle, false to turn off.
* @returns {Promise<void>}
*/
set(isToCheck) {
return __awaiter(this, void 0, void 0, function* () {
yield test_1.test.step(`Set toggle to ${isToCheck} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
if ((yield this.isOn()) !== isToCheck) {
yield this.button.click();
}
}));
});
}
/**
* Check if the toggle is on.
* @returns {Promise<boolean>} True if the toggle is on, false otherwise.
*/
isOn() {
return __awaiter(this, void 0, void 0, function* () {
return yield test_1.test.step(`Check if toggle is on for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
return yield this.input.isChecked();
}));
});
}
}
exports.Toggle = Toggle;
//# sourceMappingURL=Toggle.js.map