material-web/menu/harness.ts
Andrew Jakubowicz a8c2fa9a8b fix(menu)!: rename "lib" directory to "internal"
BREAKING CHANGE: Rename `@material/web/menu/lib` to `@material/web/menu/internal`. Prefer not using internal files.

PiperOrigin-RevId: 550589890
2023-07-24 09:45:01 -07:00

52 lines
1.2 KiB
TypeScript

/**
* @license
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import {LitElement} from 'lit';
import {Harness} from '../testing/harness.js';
import {Menu} from './internal/menu.js';
import {MenuItemHarness} from './internal/menuitem/harness.js';
export {MenuItemHarness} from './internal/menuitem/harness.js';
/**
* Test harness for menu.
*/
export class MenuHarness extends Harness<Menu> {
/**
* Shows the menu and returns the first list item element.
*/
protected override async getInteractiveElement() {
await this.element.updateComplete;
await this.show();
return (await this.getItems())[0].getInteractiveElement();
}
/** @return ListItem harnesses for the menu's items. */
getItems() {
return this.element.items.map(
(item) => new MenuItemHarness(item as typeof item&LitElement));
}
async show(quick = true) {
const menu = this.element;
menu.quick = quick;
if (menu.open) {
return;
}
const opened = new Promise((resolve) => {
menu.addEventListener('opened', () => {
resolve(true);
}, {once: true});
});
menu.show();
await opened;
}
}