UNPKG

@o3r/testing

Version:

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

66 lines 3.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MatAutocomplete = void 0; var tslib_1 = require("tslib"); var element_1 = require("../element"); /** * Implementation dedicated to Playwright. */ var MatAutocomplete = /** @class */ (function (_super) { tslib_1.__extends(MatAutocomplete, _super); function MatAutocomplete(sourceElement) { return _super.call(this, sourceElement) || this; } /** @inheritdoc */ MatAutocomplete.prototype.selectByValue = function (value_1) { return tslib_1.__awaiter(this, arguments, void 0, function (value, timeout) { var element, matOptions, matOptionsCount, options, i, _a, _b, _c, selectedOption; if (timeout === void 0) { timeout = 5000; } return tslib_1.__generator(this, function (_d) { switch (_d.label) { case 0: return [4 /*yield*/, this.setValue(value)]; case 1: _d.sent(); return [4 /*yield*/, this.click()]; case 2: _d.sent(); element = this.sourceElement.page; matOptions = element.locator('.mat-option, mat-option'); return [4 /*yield*/, matOptions.first().waitFor({ state: 'attached', timeout: timeout })]; case 3: _d.sent(); return [4 /*yield*/, matOptions.count()]; case 4: matOptionsCount = _d.sent(); options = []; if (!(matOptionsCount > 1)) return [3 /*break*/, 9]; i = 0; _d.label = 5; case 5: if (!(i < matOptionsCount)) return [3 /*break*/, 8]; _b = (_a = options).push; _c = element_1.getPlainText; return [4 /*yield*/, matOptions.nth(i).innerText()]; case 6: _b.apply(_a, [_c.apply(void 0, [_d.sent()])]); _d.label = 7; case 7: i++; return [3 /*break*/, 5]; case 8: throw new Error("MatAutocomplete selectByValue works only for filtered autocomplete. Found multiple values: ".concat(options.join(', '))); case 9: if (!(matOptionsCount === 1)) return [3 /*break*/, 11]; selectedOption = { element: matOptions.nth(0), page: this.sourceElement.page }; return [4 /*yield*/, new element_1.O3rElement(selectedOption).click()]; case 10: _d.sent(); return [2 /*return*/, this.sourceElement.element.press('Tab')]; case 11: return [2 /*return*/, Promise.reject(new Error('Element with selector .mat-option, mat-option not found.'))]; } }); }); }; return MatAutocomplete; }(element_1.O3rElement)); exports.MatAutocomplete = MatAutocomplete; //# sourceMappingURL=autocomplete-material.js.map