@o3r/testing
Version:
The module provides testing (e2e, unit test) utilities to help you build your own E2E pipeline integrating visual testing.
113 lines • 5.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MatSelect = void 0;
var tslib_1 = require("tslib");
var protractor_1 = require("protractor");
var element_1 = require("../element");
/**
* Implementation dedicated to Protractor.
* @deprecated Will be removed in v13, please use Playwright instead
*/
var MatSelect = /** @class */ (function (_super) {
tslib_1.__extends(MatSelect, _super);
function MatSelect(sourceElement) {
return _super.call(this, sourceElement) || this;
}
/** @inheritdoc */
MatSelect.prototype.selectByIndex = function (index, _timeout) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var options, option;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.click()];
case 1:
_a.sent();
return [4 /*yield*/, protractor_1.element.all(protractor_1.By.css('mat-option')).asElementFinders_()];
case 2:
options = _a.sent();
if (typeof options[index] === 'undefined') {
return [2 /*return*/, Promise.reject(new Error("Option with index ".concat(index, " not found in select element.")))];
}
else {
option = new element_1.O3rElement(options[index]);
return [2 /*return*/, option.click()];
}
return [2 /*return*/];
}
});
});
};
/** @inheritdoc */
MatSelect.prototype.selectByValue = function (value, _timeout) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var options, _i, options_1, opt, option;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.click()];
case 1:
_a.sent();
return [4 /*yield*/, protractor_1.element.all(protractor_1.By.css('mat-option')).asElementFinders_()];
case 2:
options = _a.sent();
_i = 0, options_1 = options;
_a.label = 3;
case 3:
if (!(_i < options_1.length)) return [3 /*break*/, 6];
opt = options_1[_i];
option = new element_1.O3rElement(opt);
return [4 /*yield*/, option.getAttribute('ng-reflect-value')];
case 4:
if ((_a.sent()) === value) {
return [2 /*return*/, option.click()];
}
_a.label = 5;
case 5:
_i++;
return [3 /*break*/, 3];
case 6: return [2 /*return*/, Promise.reject(new Error("Option with value ".concat(value, " not found in select element.")))];
}
});
});
};
/** @inheritdoc */
MatSelect.prototype.selectByLabel = function (label, _timeout) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var options, _i, options_2, opt, option;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.click()];
case 1:
_a.sent();
return [4 /*yield*/, protractor_1.element.all(protractor_1.By.css('mat-option')).asElementFinders_()];
case 2:
options = _a.sent();
_i = 0, options_2 = options;
_a.label = 3;
case 3:
if (!(_i < options_2.length)) return [3 /*break*/, 6];
opt = options_2[_i];
option = new element_1.O3rElement(opt);
return [4 /*yield*/, option.getText()];
case 4:
if ((_a.sent()) === label) {
return [2 /*return*/, option.click()];
}
_a.label = 5;
case 5:
_i++;
return [3 /*break*/, 3];
case 6: return [2 /*return*/, Promise.reject(new Error("Option with label ".concat(label, " not found in select element.")))];
}
});
});
};
/** @inheritDoc */
MatSelect.prototype.getValue = function () {
// eslint-disable-next-line no-console -- no other logger available
console.warn('Usage of "getValue" is not recommended on Material Select elements. Use "getPlainText()" instead.');
return _super.prototype.getValue.call(this);
};
return MatSelect;
}(element_1.O3rElement));
exports.MatSelect = MatSelect;
//# sourceMappingURL=select-material.js.map