@o3r/testing
Version:
The module provides testing (e2e, unit test) utilities to help you build your own E2E pipeline integrating visual testing.
36 lines • 1.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MatAutocomplete = void 0;
const element_1 = require("../element");
/**
* Implementation dedicated to Playwright.
*/
class MatAutocomplete extends element_1.O3rElement {
constructor(sourceElement) {
super(sourceElement);
}
/** @inheritdoc */
async selectByValue(value, timeout = 5000) {
await this.setValue(value);
await this.click();
const element = this.sourceElement.page;
const matOptions = element.locator('.mat-option, mat-option');
await matOptions.first().waitFor({ state: 'attached', timeout });
const matOptionsCount = await matOptions.count();
const options = [];
if (matOptionsCount > 1) {
for (let i = 0; i < matOptionsCount; i++) {
options.push((0, element_1.getPlainText)(await matOptions.nth(i).innerText()));
}
throw new Error(`MatAutocomplete selectByValue works only for filtered autocomplete. Found multiple values: ${options.join(', ')}`);
}
if (matOptionsCount === 1) {
const selectedOption = { element: matOptions.nth(0), page: this.sourceElement.page };
await new element_1.O3rElement(selectedOption).click();
return this.sourceElement.element.press('Tab');
}
return Promise.reject(new Error('Element with selector .mat-option, mat-option not found.'));
}
}
exports.MatAutocomplete = MatAutocomplete;
//# sourceMappingURL=autocomplete-material.js.map