mirror of
https://github.com/material-components/material-web.git
synced 2024-10-27 06:04:44 +03:00
fcfc696c46
lots of hard coded stuff to enable our tests. Cleaning this up for generalized client usage. BREAKING CHANGE: menu harnesses will not automatically open menus in quick mode anymore and interactions in menu and list harnesses will not automatically go to the first item but rather the menu roots. PiperOrigin-RevId: 561746073
51 lines
1.2 KiB
TypeScript
51 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;
|
|
return this.element.renderRoot.querySelector('md-list')!.renderRoot
|
|
.querySelector('.list') as HTMLElement;
|
|
}
|
|
|
|
/** @return ListItem harnesses for the menu's items. */
|
|
getItems() {
|
|
return this.element.items.map(
|
|
(item) => new MenuItemHarness(item as typeof item&LitElement));
|
|
}
|
|
|
|
async show() {
|
|
const menu = this.element;
|
|
if (menu.open) {
|
|
return;
|
|
}
|
|
|
|
const opened = new Promise((resolve) => {
|
|
menu.addEventListener('opened', () => {
|
|
resolve(true);
|
|
}, {once: true});
|
|
});
|
|
|
|
menu.show();
|
|
await opened;
|
|
}
|
|
}
|