UNPKG

@o3r/testing

Version:

The module provides testing (e2e, unit test) utilities to help you build your own E2E pipeline integrating visual testing.

111 lines 4.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.O3rCheckboxElement = void 0; var tslib_1 = require("tslib"); var element_1 = require("../element"); /** * Implementation dedicated to Playwright. */ var O3rCheckboxElement = /** @class */ (function (_super) { tslib_1.__extends(O3rCheckboxElement, _super); function O3rCheckboxElement(sourceElement) { return _super.call(this, sourceElement) || this; } O3rCheckboxElement.prototype.getInputElement = function () { return tslib_1.__awaiter(this, void 0, void 0, function () { var subInputElement, _a; return tslib_1.__generator(this, function (_b) { switch (_b.label) { case 0: _b.trys.push([0, 2, , 3]); subInputElement = this.sourceElement.element.locator('input[type="checkbox"]'); return [4 /*yield*/, subInputElement.count()]; case 1: if (_b.sent()) { return [2 /*return*/, subInputElement]; } return [2 /*return*/, this.sourceElement.element]; case 2: _a = _b.sent(); return [2 /*return*/, this.sourceElement.element]; case 3: return [2 /*return*/]; } }); }); }; O3rCheckboxElement.prototype.getLabelElement = function () { return tslib_1.__awaiter(this, void 0, void 0, function () { var element, err_1; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 2, , 3]); element = this.sourceElement.element.locator('label'); return [4 /*yield*/, element.count()]; case 1: if (_a.sent()) { return [2 /*return*/, element]; } return [3 /*break*/, 3]; case 2: err_1 = _a.sent(); // eslint-disable-next-line no-console -- no other logger available console.warn('Failed to retrieve label of O3rCheckboxElement', err_1); return [2 /*return*/]; case 3: return [2 /*return*/]; } }); }); }; /** * Check the checkbox element * @param value If specified, determine the value of the checkbox button * If the element contains a label, the label will be used to (un)check the checkbox. */ O3rCheckboxElement.prototype.check = function () { return tslib_1.__awaiter(this, arguments, void 0, function (value) { var labelElement, currentValue; if (value === void 0) { value = true; } return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.getLabelElement()]; case 1: labelElement = _a.sent(); if (!labelElement) return [3 /*break*/, 3]; return [4 /*yield*/, this.isChecked()]; case 2: currentValue = _a.sent(); if (currentValue === value) { // eslint-disable-next-line no-console -- no other logger available console.warn("Checkbox is already ".concat(currentValue ? 'checked' : 'unchecked')); return [2 /*return*/, Promise.resolve()]; } return [2 /*return*/, labelElement.click()]; case 3: return [4 /*yield*/, this.getInputElement()]; case 4: return [2 /*return*/, (_a.sent()).setChecked(value)]; } }); }); }; /** @inheritDoc */ O3rCheckboxElement.prototype.uncheck = function () { return this.check(false); }; /** @inheritDoc */ O3rCheckboxElement.prototype.isChecked = function () { return tslib_1.__awaiter(this, void 0, void 0, function () { var inputElement; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.getInputElement()]; case 1: inputElement = _a.sent(); return [2 /*return*/, inputElement.isChecked()]; } }); }); }; return O3rCheckboxElement; }(element_1.O3rElement)); exports.O3rCheckboxElement = O3rCheckboxElement; //# sourceMappingURL=checkbox-element.js.map