/** * @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 { ComponentHarness, HarnessPredicate, } from '@angular/cdk/testing'; /** Harness for interacting with an MDC-based `mat-option` in tests. */ export class MatOptionHarness extends ComponentHarness { constructor() { super(...arguments); /** Element containing the option's text. */ this._text = this.locatorFor('.mdc-list-item__primary-text'); } /** Selector used to locate option instances. */ static { this.hostSelector = '.mat-mdc-option'; } /** * Gets a `HarnessPredicate` that can be used to search for an option with specific attributes. * @param options Options for filtering which option instances are considered a match. * @return a `HarnessPredicate` configured with the given options. */ static with(options = {}) { return new HarnessPredicate(this, options) .addOption('text', options.text, async (harness, title) => HarnessPredicate.stringMatches(await harness.getText(), title)) .addOption('isSelected', options.isSelected, async (harness, isSelected) => (await harness.isSelected()) === isSelected); } /** Clicks the option. */ async click() { return (await this.host()).click(); } /** Gets the option's label text. */ async getText() { return (await this._text()).text(); } /** Gets whether the option is disabled. */ async isDisabled() { return (await this.host()).hasClass('mdc-list-item--disabled'); } /** Gets whether the option is selected. */ async isSelected() { return (await this.host()).hasClass('mdc-list-item--selected'); } /** Gets whether the option is active. */ async isActive() { return (await this.host()).hasClass('mat-mdc-option-active'); } /** Gets whether the option is in multiple selection mode. */ async isMultiple() { return (await this.host()).hasClass('mat-mdc-option-multiple'); } } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib3B0aW9uLWhhcm5lc3MuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9zcmMvbWF0ZXJpYWwvY29yZS90ZXN0aW5nL29wdGlvbi1oYXJuZXNzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7R0FNRztBQUVILE9BQU8sRUFDTCxnQkFBZ0IsRUFFaEIsZ0JBQWdCLEdBQ2pCLE1BQU0sc0JBQXNCLENBQUM7QUFHOUIsdUVB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