UNPKG

@angular/material

Version:
43 lines 6.09 kB
/** * @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'; import { MatOptionHarness } from './option-harness'; /** Harness for interacting with a `mat-optgroup` in tests. */ export class MatOptgroupHarness extends ComponentHarness { constructor() { super(...arguments); this._label = this.locatorFor('.mat-mdc-optgroup-label'); } /** Selector used to locate option group instances. */ static { this.hostSelector = '.mat-mdc-optgroup'; } /** * Gets a `HarnessPredicate` that can be used to search for a option group 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('labelText', options.labelText, async (harness, title) => HarnessPredicate.stringMatches(await harness.getLabelText(), title)); } /** Gets the option group's label text. */ async getLabelText() { return (await this._label()).text(); } /** Gets whether the option group is disabled. */ async isDisabled() { return (await (await this.host()).getAttribute('aria-disabled')) === 'true'; } /** * Gets the options that are inside the group. * @param filter Optionally filters which options are included. */ async getOptions(filter = {}) { return this.locatorForAll(MatOptionHarness.with(filter))(); } } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib3B0Z3JvdXAtaGFybmVzcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3NyYy9tYXRlcmlhbC9jb3JlL3Rlc3Rpbmcvb3B0Z3JvdXAtaGFybmVzcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7QUFFSCxPQUFPLEVBQ0wsZ0JBQWdCLEVBRWhCLGdCQUFnQixHQUNqQixNQUFNLHNCQUFzQixDQUFDO0FBRTlCLE9BQU8sRUFBQyxnQkFBZ0IsRUFBQyxNQUFNLGtCQUFrQixDQUFDO0FBR2xELDhEQUE4RDtBQUM5RCxNQUFNLE9BQ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