@o3r/testing
Version:
The module provides testing (e2e, unit test) utilities to help you build your own E2E pipeline integrating visual testing.
57 lines • 2.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MatSelect = void 0;
const platform_browser_1 = require("@angular/platform-browser");
const element_1 = require("../element");
/**
* Implementation dedicated to angular / TestBed.
*/
class MatSelect extends element_1.O3rElement {
constructor(sourceElement) {
super(sourceElement);
}
/** @inheritdoc */
async selectByIndex(index, _timeout) {
await this.click();
const options = this.sourceElement.queryAll(platform_browser_1.By.css('mat-option'));
if (options[index]) {
const option = new element_1.O3rElement(options[index]);
return option.click();
}
else {
return Promise.reject(new Error(`Option with index ${index} not found in select element.`));
}
}
/** @inheritdoc */
async selectByValue(value, _timeout) {
await this.click();
const options = this.sourceElement.queryAll(platform_browser_1.By.css('mat-option'));
for (const opt of options) {
const option = new element_1.O3rElement(opt);
if (await option.getAttribute('ng-reflect-value') === value) {
return option.click();
}
}
return Promise.reject(new Error(`Option with value ${value} not found in select element.`));
}
/** @inheritdoc */
async selectByLabel(label, _timeout) {
await this.click();
const options = this.sourceElement.queryAll(platform_browser_1.By.css('mat-option'));
for (const opt of options) {
const option = new element_1.O3rElement(opt);
if (await option.getText() === label) {
return option.click();
}
}
return Promise.reject(new Error(`Option with label ${label} not found in select element.`));
}
/** @inheritDoc */
getValue() {
// 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.getValue();
}
}
exports.MatSelect = MatSelect;
//# sourceMappingURL=select-material.js.map