UNPKG

@o3r/testing

Version:

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

106 lines 4.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MatSelect = void 0; var tslib_1 = require("tslib"); var platform_browser_1 = require("@angular/platform-browser"); var element_1 = require("../element"); /** * Implementation dedicated to angular / TestBed. */ 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(); options = this.sourceElement.queryAll(platform_browser_1.By.css('mat-option')); if (options[index]) { option = new element_1.O3rElement(options[index]); return [2 /*return*/, option.click()]; } else { return [2 /*return*/, Promise.reject(new Error("Option with index ".concat(index, " not found in select element.")))]; } 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(); options = this.sourceElement.queryAll(platform_browser_1.By.css('mat-option')); _i = 0, options_1 = options; _a.label = 2; case 2: if (!(_i < options_1.length)) return [3 /*break*/, 5]; opt = options_1[_i]; option = new element_1.O3rElement(opt); return [4 /*yield*/, option.getAttribute('ng-reflect-value')]; case 3: if ((_a.sent()) === value) { return [2 /*return*/, option.click()]; } _a.label = 4; case 4: _i++; return [3 /*break*/, 2]; case 5: 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(); options = this.sourceElement.queryAll(platform_browser_1.By.css('mat-option')); _i = 0, options_2 = options; _a.label = 2; case 2: if (!(_i < options_2.length)) return [3 /*break*/, 5]; opt = options_2[_i]; option = new element_1.O3rElement(opt); return [4 /*yield*/, option.getText()]; case 3: if ((_a.sent()) === label) { return [2 /*return*/, option.click()]; } _a.label = 4; case 4: _i++; return [3 /*break*/, 2]; case 5: 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