Skip to content

test(menu): add performance tests for mat-menu #20151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions test/benchmarks/material/menu/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
load("@npm_angular_dev_infra_private//benchmark/component_benchmark:component_benchmark.bzl", "component_benchmark")

# TODO(wagnermaciel): Update this target to provide indigo-pink in a way that doesn't require having to import it with
# stylesUrls inside the components once `component_benchmark` supports asset injection.

component_benchmark(
name = "benchmark",
driver = ":menu.perf-spec.ts",
driver_deps = [
"@npm//@angular/dev-infra-private",
"@npm//protractor",
"@npm//@types/jasmine",
],
ng_assets = [":menu.html"],
ng_deps = [
"@npm//@angular/core",
"@npm//@angular/platform-browser",
"//src/material/menu",
],
ng_srcs = [":app.module.ts"],
prefix = "",
styles = ["//src/material/prebuilt-themes:indigo-pink"],
)
33 changes: 33 additions & 0 deletions test/benchmarks/material/menu/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @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 {Component, NgModule, ViewEncapsulation} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {MatMenuModule} from '@angular/material/menu';

/** component: mat-menu */

@Component({
selector: 'app-root',
templateUrl: './menu.html',
encapsulation: ViewEncapsulation.None,
styleUrls: ['//src/material/core/theming/prebuilt/indigo-pink.css'],
})
export class MenuBenchmarkApp {
}


@NgModule({
declarations: [MenuBenchmarkApp],
imports: [
BrowserModule,
MatMenuModule,
],
bootstrap: [MenuBenchmarkApp]
})
export class AppModule {}
33 changes: 33 additions & 0 deletions test/benchmarks/material/menu/menu.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<button mat-button [matMenuTriggerFor]="basic">Basic Menu</button>
<button mat-button [matMenuTriggerFor]="nested">Nested Menu</button>

<mat-menu #basic="matMenu">
<button mat-menu-item>Item 1</button>
<button mat-menu-item>Item 2</button>
<button mat-menu-item>Item 3</button>
<button mat-menu-item>Item 4</button>
<button mat-menu-item>Item 5</button>
<button mat-menu-item>Item 6</button>
<button mat-menu-item>Item 7</button>
<button mat-menu-item>Item 8</button>
<button mat-menu-item>Item 9</button>
<button mat-menu-item>Item 10</button>
</mat-menu>

<!-- Nested Menu with 3 Levels -->

<mat-menu #nested="matMenu">
<button mat-menu-item [matMenuTriggerFor]="sub1">Sub Menu 1</button>
</mat-menu>

<mat-menu #sub1="matMenu">
<button mat-menu-item [matMenuTriggerFor]="sub2">Sub Menu 2</button>
</mat-menu>

<mat-menu #sub2="matMenu">
<button mat-menu-item>Item 1</button>
<button mat-menu-item>Item 2</button>
<button mat-menu-item>Item 3</button>
<button mat-menu-item>Item 4</button>
<button mat-menu-item>Item 5</button>
</mat-menu>
69 changes: 69 additions & 0 deletions test/benchmarks/material/menu/menu.perf-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* @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 {$, by, element, ElementFinder, Key} from 'protractor';
import {runBenchmark} from '@angular/dev-infra-private/benchmark/driver-utilities';

// Clicking to close a menu is problematic. This is a solution that uses `.sendKeys()` avoids
// issues with `.click()`.

async function closeMenu(trigger: ElementFinder) {
const backdropId = await trigger.getAttribute('aria-controls');
if (await $(`#${backdropId}`).isPresent()) {
await $(`#${backdropId}`).sendKeys(Key.ESCAPE);
}
}

describe('menu performance benchmarks', () => {
it('opens a basic menu', async () => {
let trigger: ElementFinder;
await runBenchmark({
id: 'basic-menu-open',
url: '',
ignoreBrowserSynchronization: true,
params: [],
setup: async () => trigger = element(by.buttonText('Basic Menu')),
work: async () => {
await trigger.click();
await closeMenu(trigger);
}
});
});

it('opens the root menu of a set of nested menus', async () => {
let trigger: ElementFinder;
await runBenchmark({
id: 'nested-menu-open-shallow',
url: '',
ignoreBrowserSynchronization: true,
params: [],
setup: async () => trigger = element(by.buttonText('Nested Menu')),
work: async () => {
await trigger.click();
await closeMenu(trigger);
},
});
});

it('fully opens a menu with nested menus', async () => {
let trigger: ElementFinder;
await runBenchmark({
id: 'menu-open-deep',
url: '',
ignoreBrowserSynchronization: true,
params: [],
setup: async () => trigger = element(by.buttonText('Nested Menu')),
work: async () => {
await trigger.click();
await element(by.buttonText('Sub Menu 1')).click();
await element(by.buttonText('Sub Menu 2')).click();
await closeMenu(trigger);
},
});
});
});