UNPKG

@o3r/testing

Version:

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

124 lines 5.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MatSelect = void 0; var tslib_1 = require("tslib"); var element_1 = require("../element"); /** * Implementation dedicated to Playwright. */ 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_1) { return tslib_1.__awaiter(this, arguments, void 0, function (index, timeout) { var options, selectedOption, option; if (timeout === void 0) { timeout = 5000; } return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.click()]; case 1: _a.sent(); options = this.sourceElement.page.locator('mat-option'); return [4 /*yield*/, options.first().waitFor({ state: 'attached', timeout: timeout })]; case 2: _a.sent(); return [4 /*yield*/, options.count()]; case 3: if ((_a.sent()) >= index + 1) { selectedOption = { element: options.nth(index), page: this.sourceElement.page }; option = new element_1.O3rElement(selectedOption); 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_1) { return tslib_1.__awaiter(this, arguments, void 0, function (value, timeout) { var options, optionsCount, i, selectedOption, option; if (timeout === void 0) { timeout = 5000; } return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.click()]; case 1: _a.sent(); options = this.sourceElement.page.locator('mat-option'); return [4 /*yield*/, options.first().waitFor({ state: 'attached', timeout: timeout })]; case 2: _a.sent(); return [4 /*yield*/, options.count()]; case 3: optionsCount = _a.sent(); i = 0; _a.label = 4; case 4: if (!(i < optionsCount)) return [3 /*break*/, 7]; selectedOption = { element: options.nth(i), page: this.sourceElement.page }; option = new element_1.O3rElement(selectedOption); return [4 /*yield*/, option.getAttribute('ng-reflect-value')]; case 5: if ((_a.sent()) === value) { return [2 /*return*/, option.click()]; } _a.label = 6; case 6: i++; return [3 /*break*/, 4]; case 7: return [2 /*return*/, Promise.reject(new Error("Option with value ".concat(value, " not found in select element.")))]; } }); }); }; /** @inheritdoc */ MatSelect.prototype.selectByLabel = function (label_1) { return tslib_1.__awaiter(this, arguments, void 0, function (label, timeout) { var options, optionsCount, i, selectedOption, option; if (timeout === void 0) { timeout = 5000; } return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.click()]; case 1: _a.sent(); options = this.sourceElement.page.locator('mat-option'); return [4 /*yield*/, options.first().waitFor({ state: 'attached', timeout: timeout })]; case 2: _a.sent(); return [4 /*yield*/, options.count()]; case 3: optionsCount = _a.sent(); i = 0; _a.label = 4; case 4: if (!(i < optionsCount)) return [3 /*break*/, 7]; selectedOption = { element: options.nth(i), page: this.sourceElement.page }; option = new element_1.O3rElement(selectedOption); return [4 /*yield*/, option.getText()]; case 5: if ((_a.sent()) === label) { return [2 /*return*/, option.click()]; } _a.label = 6; case 6: i++; return [3 /*break*/, 4]; case 7: return [2 /*return*/, Promise.reject(new Error("Option with label ".concat(label, " not found in select element.")))]; } }); }); }; /** @inheritDoc */ MatSelect.prototype.getValue = function () { throw new Error('Cannot use "getValue" function on a Material Select element. Use "getPlainText()" instead.'); }; return MatSelect; }(element_1.O3rElement)); exports.MatSelect = MatSelect; //# sourceMappingURL=select-material.js.map