/** * @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 { ContentContainerComponentHarness, HarnessPredicate, TestKey, } from '@angular/cdk/testing'; import { coerceBooleanProperty } from '@angular/cdk/coercion'; export class _MatMenuHarnessBase extends ContentContainerComponentHarness { constructor() { super(...arguments); this._documentRootLocator = this.documentRootLocatorFactory(); } // TODO: potentially extend MatLegacyButtonHarness /** Whether the menu is disabled. */ async isDisabled() { const disabled = (await this.host()).getAttribute('disabled'); return coerceBooleanProperty(await disabled); } /** Whether the menu is open. */ async isOpen() { return !!(await this._getMenuPanel()); } /** Gets the text of the menu's trigger element. */ async getTriggerText() { return (await this.host()).text(); } /** Focuses the menu. */ async focus() { return (await this.host()).focus(); } /** Blurs the menu. */ async blur() { return (await this.host()).blur(); } /** Whether the menu is focused. */ async isFocused() { return (await this.host()).isFocused(); } /** Opens the menu. */ async open() { if (!(await this.isOpen())) { return (await this.host()).click(); } } /** Closes the menu. */ async close() { const panel = await this._getMenuPanel(); if (panel) { return panel.sendKeys(TestKey.ESCAPE); } } /** * Gets a list of `MatMenuItemHarness` representing the items in the menu. * @param filters Optionally filters which menu items are included. */ async getItems(filters) { const panelId = await this._getPanelId(); if (panelId) { return this._documentRootLocator.locatorForAll(this._itemClass.with({ ...(filters || {}), ancestor: `#${panelId}`, }))(); } return []; } /** * Clicks an item in the menu, and optionally continues clicking items in subsequent sub-menus. * @param itemFilter A filter used to represent which item in the menu should be clicked. The * first matching menu item will be clicked. * @param subItemFilters A list of filters representing the items to click in any subsequent * sub-menus. The first item in the sub-menu matching the corresponding filter in * `subItemFilters` will be clicked. */ async clickItem(itemFilter, ...subItemFilters) { await this.open(); const items = await this.getItems(itemFilter); if (!items.length) { throw Error(`Could not find item matching ${JSON.stringify(itemFilter)}`); } if (!subItemFilters.length) { return await items[0].click(); } const menu = await items[0].getSubmenu(); if (!menu) { throw Error(`Item matching ${JSON.stringify(itemFilter)} does not have a submenu`); } return menu.clickItem(...subItemFilters); } async getRootHarnessLoader() { const panelId = await this._getPanelId(); return this.documentRootLocatorFactory().harnessLoaderFor(`#${panelId}`); } /** Gets the menu panel associated with this menu. */ async _getMenuPanel() { const panelId = await this._getPanelId(); return panelId ? this._documentRootLocator.locatorForOptional(`#${panelId}`)() : null; } /** Gets the id of the menu panel associated with this menu. */ async _getPanelId() { const panelId = await (await this.host()).getAttribute('aria-controls'); return panelId || null; } } export class _MatMenuItemHarnessBase extends ContentContainerComponentHarness { /** Whether the menu is disabled. */ async isDisabled() { const disabled = (await this.host()).getAttribute('disabled'); return coerceBooleanProperty(await disabled); } /** Gets the text of the menu item. */ async getText() { return (await this.host()).text(); } /** Focuses the menu item. */ async focus() { return (await this.host()).focus(); } /** Blurs the menu item. */ async blur() { return (await this.host()).blur(); } /** Whether the menu item is focused. */ async isFocused() { return (await this.host()).isFocused(); } /** Clicks the menu item. */ async click() { return (await this.host()).click(); } /** Whether this item has a submenu. */ async hasSubmenu() { return (await this.host()).matchesSelector(this._menuClass.hostSelector); } /** Gets the submenu associated with this menu item, or null if none. */ async getSubmenu() { if (await this.hasSubmenu()) { return new this._menuClass(this.locatorFactory); } return null; } } /** Harness for interacting with an MDC-based mat-menu in tests. */ export class MatMenuHarness extends _MatMenuHarnessBase { constructor() { super(...arguments); this._itemClass = MatMenuItemHarness; } /** The selector for the host element of a `MatMenu` instance. */ static { this.hostSelector = '.mat-mdc-menu-trigger'; } /** * Gets a `HarnessPredicate` that can be used to search for a menu with specific attributes. * @param options Options for filtering which menu instances are considered a match. * @return a `HarnessPredicate` configured with the given options. */ static with(options = {}) { return new HarnessPredicate(this, options).addOption('triggerText', options.triggerText, (harness, text) => HarnessPredicate.stringMatches(harness.getTriggerText(), text)); } } /** Harness for interacting with an MDC-based mat-menu-item in tests. */ export class MatMenuItemHarness extends _MatMenuItemHarnessBase { constructor() { super(...arguments); this._menuClass = MatMenuHarness; } /** The selector for the host element of a `MatMenuItem` instance. */ static { this.hostSelector = '.mat-mdc-menu-item'; } /** * Gets a `HarnessPredicate` that can be used to search for a menu item with specific attributes. * @param options Options for filtering which menu item 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, (harness, text) => HarnessPredicate.stringMatches(harness.getText(), text)) .addOption('hasSubmenu', options.hasSubmenu, async (harness, hasSubmenu) => (await harness.hasSubmenu()) === hasSubmenu); } } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVudS1oYXJuZXNzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vc3JjL21hdGVyaWFsL21lbnUvdGVzdGluZy9tZW51LWhhcm5lc3MudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBRUgsT0FBTyxFQUlMLGdDQUFnQyxFQUVoQyxnQkFBZ0IsRUFFaEIsT0FBTyxHQUNSLE1BQU0sc0JBQXNCLENBQUM7QUFDOUIsT0FBTyxFQUFDLHFCQUFxQixFQUFDLE1BQU0sdUJBQXVCLENBQUM7QUFHNUQsTUFBTSxPQUFnQixtQkFTcEIsU0FBUSxnQ0FBd0M7SUFUbEQ7O1FBVVUseUJBQW9CLEdBQUcsSUFBSSxDQUFDLDBCQUEwQixFQUFFLENBQUM7SUFpSG5FLENBQUM7SUE5R0Msa0RBQWtEO0lBRWxELG9DQUFvQztJQUNwQyxLQUFLLENBQUMsVUFBVTtRQUNkLE1BQU0sUUFBUSxHQUFHLENBQUMsTUFBTSxJQUFJLENBQUMsSUFBSSxFQUFFLENBQUMsQ0FBQyxZQUFZLENBQUMsVUFBVSxDQUFDLENBQUM7UUFDOUQsT0FBTyxxQkFBcUIsQ0FBQyxNQUFNLFFBQVEsQ0FBQyxDQUFDO0lBQy9DLENBQUM7SUFFRCxnQ0FBZ0M7SUFDaEMsS0FBSyxDQUFDLE1BQU07UU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