mirror of
https://github.com/material-components/material-web.git
synced 2024-11-10 11:21:43 +03:00
7d5af92ad0
PiperOrigin-RevId: 504701523
47 lines
1.0 KiB
TypeScript
47 lines
1.0 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright 2022 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
import {Harness} from '../testing/harness.js';
|
|
|
|
import {Menu} from './lib/menu.js';
|
|
import {MenuItemHarness} from './lib/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));
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|