/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { HarnessPredicate, parallel, } from '@angular/cdk/testing'; import { MatOptionHarness, MatOptgroupHarness, } from '@angular/material/core/testing'; import { MatFormFieldControlHarness } from '@angular/material/form-field/testing/control'; export class _MatSelectHarnessBase extends MatFormFieldControlHarness { constructor() { super(...arguments); this._documentRootLocator = this.documentRootLocatorFactory(); this._backdrop = this._documentRootLocator.locatorFor('.cdk-overlay-backdrop'); } /** Gets a boolean promise indicating if the select is disabled. */ async isDisabled() { return (await this.host()).hasClass(`${this._prefix}-select-disabled`); } /** Gets a boolean promise indicating if the select is valid. */ async isValid() { return !(await (await this.host()).hasClass('ng-invalid')); } /** Gets a boolean promise indicating if the select is required. */ async isRequired() { return (await this.host()).hasClass(`${this._prefix}-select-required`); } /** Gets a boolean promise indicating if the select is empty (no value is selected). */ async isEmpty() { return (await this.host()).hasClass(`${this._prefix}-select-empty`); } /** Gets a boolean promise indicating if the select is in multi-selection mode. */ async isMultiple() { return (await this.host()).hasClass(`${this._prefix}-select-multiple`); } /** Gets a promise for the select's value text. */ async getValueText() { const value = await this.locatorFor(`.${this._prefix}-select-value`)(); return value.text(); } /** Focuses the select and returns a void promise that indicates when the action is complete. */ async focus() { return (await this.host()).focus(); } /** Blurs the select and returns a void promise that indicates when the action is complete. */ async blur() { return (await this.host()).blur(); } /** Whether the select is focused. */ async isFocused() { return (await this.host()).isFocused(); } /** Gets the options inside the select panel. */ async getOptions(filter) { return this._documentRootLocator.locatorForAll(this._optionClass.with({ ...(filter || {}), ancestor: await this._getPanelSelector(), }))(); } /** Gets the groups of options inside the panel. */ async getOptionGroups(filter) { return this._documentRootLocator.locatorForAll(this._optionGroupClass.with({ ...(filter || {}), ancestor: await this._getPanelSelector(), }))(); } /** Gets whether the select is open. */ async isOpen() { return !!(await this._documentRootLocator.locatorForOptional(await this._getPanelSelector())()); } /** Opens the select's panel. */ async open() { if (!(await this.isOpen())) { const trigger = await this.locatorFor(`.${this._prefix}-select-trigger`)(); return trigger.click(); } } /** * Clicks the options that match the passed-in filter. If the select is in multi-selection * mode all options will be clicked, otherwise the harness will pick the first matching option. */ async clickOptions(filter) { await this.open(); const [isMultiple, options] = await parallel(() => [ this.isMultiple(), this.getOptions(filter), ]); if (options.length === 0) { throw Error('Select does not have options matching the specified filter'); } if (isMultiple) { await parallel(() => options.map(option => option.click())); } else { await options[0].click(); } } /** Closes the select's panel. */ async close() { if (await this.isOpen()) { // This is the most consistent way that works both in both single and multi-select modes, // but it assumes that only one overlay is open at a time. We should be able to make it // a bit more precise after #16645 where we can dispatch an ESCAPE press to the host instead. return (await this._backdrop()).click(); } } /** Gets the selector that should be used to find this select's panel. */ async _getPanelSelector() { const id = await (await this.host()).getAttribute('id'); return `#${id}-panel`; } } /** Harness for interacting with an MDC-based mat-select in tests. */ export class MatSelectHarness extends _MatSelectHarnessBase { constructor() { super(...arguments); this._prefix = 'mat-mdc'; this._optionClass = MatOptionHarness; this._optionGroupClass = MatOptgroupHarness; } static { this.hostSelector = '.mat-mdc-select'; } /** * Gets a `HarnessPredicate` that can be used to search for a select with specific attributes. * @param options Options for filtering which select instances are considered a match. * @return a `HarnessPredicate` configured with the given options. */ static with(options = {}) { return new HarnessPredicate(this, options).addOption('disabled', options.disabled, async (harness, disabled) => { return (await harness.isDisabled()) === disabled; }); } } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2VsZWN0LWhhcm5lc3MuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9zcmMvbWF0ZXJpYWwvc2VsZWN0L3Rlc3Rpbmcvc2VsZWN0LWhhcm5lc3MudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBRUgsT0FBTyxFQUlMLGdCQUFnQixFQUNoQixRQUFRLEdBQ1QsTUFBTSxzQ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