-
Notifications
You must be signed in to change notification settings - Fork 6.8k
test(mdc-menu): add performance tests for mdc-menu #20494
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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-experimental/mdc-menu", | ||
], | ||
ng_srcs = [":app.module.ts"], | ||
prefix = "", | ||
styles = ["//src/material-experimental/mdc-theming:indigo_pink_prebuilt"], | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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-experimental/mdc-menu'; | ||
|
||
/** component: mdc-menu */ | ||
|
||
@Component({ | ||
selector: 'app-root', | ||
templateUrl: './menu.html', | ||
encapsulation: ViewEncapsulation.None, | ||
styleUrls: ['//src/material-experimental/mdc-theming/prebuilt/indigo-pink.css'], | ||
}) | ||
export class MenuBenchmarkApp { | ||
} | ||
|
||
|
||
@NgModule({ | ||
declarations: [MenuBenchmarkApp], | ||
imports: [ | ||
BrowserModule, | ||
MatMenuModule, | ||
], | ||
bootstrap: [MenuBenchmarkApp] | ||
}) | ||
export class AppModule {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* @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 and closes a basic menu', async () => { | ||
let trigger: ElementFinder; | ||
await runBenchmark({ | ||
id: 'open-and-close-basic-menu', | ||
url: '', | ||
ignoreBrowserSynchronization: true, | ||
params: [], | ||
setup: async () => { | ||
trigger = element(by.buttonText('Basic Menu')); | ||
}, | ||
work: async () => { | ||
await trigger.click(); | ||
await closeMenu(trigger); | ||
} | ||
}); | ||
}); | ||
|
||
it('opens and closes the root menu of a set of nested menus', async () => { | ||
let trigger: ElementFinder; | ||
await runBenchmark({ | ||
id: 'shallow-open-and-close-nested-menu', | ||
url: '', | ||
ignoreBrowserSynchronization: true, | ||
params: [], | ||
setup: async () => { | ||
trigger = element(by.buttonText('Nested Menu')); | ||
}, | ||
work: async () => { | ||
await trigger.click(); | ||
await closeMenu(trigger); | ||
}, | ||
}); | ||
}); | ||
|
||
it('fully opens and closes a menu with nested menus', async () => { | ||
let trigger: ElementFinder; | ||
await runBenchmark({ | ||
id: 'deep-open-and-close-nested-menus', | ||
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); | ||
}, | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a note for the dev-infra helper: We should remove the
setup
property from therunBenchmark
function and just do the setup before. e.g. you could just directly assign thetrigger
variable based on what I can tell.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean inside the
work
callback?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I just meant before calling
runBenchmark
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The browser is not open until
runBenchmark
is called.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC the browser is always open with protractor, it just is on an empty page on initialization. So ideally IMO, the test would manually call
await browser.open(<..>)
before and then do all preparation work before starting with the samples.The reason why I'm proposing this is that
setup
andprepare
are very unclear and ambiguous IMO, and as it looks, it's also complicating the logic for preparations (as seen with above for finding the trigger). I don't feel very strongly about it. Changing the name of these properties might help too.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing
runBenchmark
to not callopenBrowser
would require fixing all the old tests in angular/angular, too. Same with renamingsetup
,prepare
, andwork
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's clear to me. Though I think that these usages should ideally not prevent us from maintaining good health and readable code. I mentioned this here as a side note, but I think we should do something in the future.
For the record: I'd be happy to go through the instances in the future if needed. We could also add a separate helper that has the less ambiguous API. All of that is obviously not a priority right now but something to keep in mind since we keep adding new benchmarks and spread this across repositories.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc. @josephperrott