/** * @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-experimental/testing'; import {coerceBooleanProperty} from '@angular/cdk/coercion'; import {MenuHarnessFilters} from './menu-harness-filters'; import {MatMenuItemHarness} from './menu-item-harness'; /** * Harness for interacting with a standard mat-menu in tests. * @dynamic */ export class MatMenuHarness extends ComponentHarness { static hostSelector = '.mat-menu-trigger'; // TODO: potentially extend MatButtonHarness /** * Gets a `HarnessPredicate` that can be used to search for a menu with specific attributes. * @param options Options for narrowing the search: * - `selector` finds a menu whose host element matches the given selector. * - `label` finds a menu with specific label text. * @return a `HarnessPredicate` configured with the given options. */ static with(options: MenuHarnessFilters = {}): HarnessPredicate { return new HarnessPredicate(MatMenuHarness, options) .addOption('text', options.triggerText, (harness, text) => HarnessPredicate.stringMatches(harness.getTriggerText(), text)); } /** Gets a boolean promise indicating if the menu is disabled. */ async isDisabled(): Promise { const disabled = (await this.host()).getAttribute('disabled'); return coerceBooleanProperty(await disabled); } async isOpen(): Promise { throw Error('not implemented'); } async getTriggerText(): Promise { return (await this.host()).text(); } /** Focuses the menu and returns a void promise that indicates when the action is complete. */ async focus(): Promise { return (await this.host()).focus(); } /** Blurs the menu and returns a void promise that indicates when the action is complete. */ async blur(): Promise { return (await this.host()).blur(); } async open(): Promise { throw Error('not implemented'); } async close(): Promise { throw Error('not implemented'); } async getItems(): Promise { throw Error('not implemented'); } async getItemLabels(): Promise { throw Error('not implemented'); } async getItemByLabel(): Promise { throw Error('not implemented'); } async getItemByIndex(): Promise { throw Error('not implemented'); } async getFocusedItem(): Promise { throw Error('not implemented'); } }