UNPKG

@o3r/testing

Version:

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

60 lines 3.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.O3rSelectElement = 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 O3rSelectElement = /** @class */ (function (_super) { tslib_1.__extends(O3rSelectElement, _super); function O3rSelectElement(sourceElement) { return _super.call(this, sourceElement) || this; } /** @inheritdoc */ O3rSelectElement.prototype.selectByIndex = function (index, _timeout) { return tslib_1.__awaiter(this, void 0, void 0, function () { var options, option, value; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: options = this.sourceElement.queryAll(platform_browser_1.By.css('option')); if (!options[index]) return [3 /*break*/, 3]; option = new element_1.O3rElement(options[index]); return [4 /*yield*/, option.getValue()]; case 1: value = _a.sent(); return [4 /*yield*/, this.setValue(value)]; case 2: _a.sent(); this.sourceElement.triggerEventHandler('change', { target: this.sourceElement.nativeElement, preventDefault: function () { }, stopPropagation: function () { } }); return [3 /*break*/, 4]; case 3: return [2 /*return*/, Promise.reject(new Error("Option with index ".concat(index, " not found in select element.")))]; case 4: return [2 /*return*/]; } }); }); }; /** @inheritdoc */ O3rSelectElement.prototype.selectByValue = function (value, _timeout) { return tslib_1.__awaiter(this, void 0, void 0, function () { var option; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: option = this.sourceElement.query(platform_browser_1.By.css("option[value='".concat(value, "']"))); if (!option) return [3 /*break*/, 2]; return [4 /*yield*/, this.setValue(option.nativeElement.value)]; case 1: _a.sent(); return [2 /*return*/, this.sourceElement.triggerEventHandler('change', { target: this.sourceElement.nativeElement, preventDefault: function () { }, stopPropagation: function () { } })]; case 2: return [2 /*return*/, Promise.reject(new Error("Option with value '".concat(value, "' not found in select element.")))]; } }); }); }; return O3rSelectElement; }(element_1.O3rElement)); exports.O3rSelectElement = O3rSelectElement; //# sourceMappingURL=select-element.js.map