Skip to content

Commit 8eefd94

Browse files
committed
test(tabs): add performance tests for mat-tabs
1 parent 49de56c commit 8eefd94

File tree

3 files changed

+146
-0
lines changed

3 files changed

+146
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
load("@npm_angular_dev_infra_private//benchmark/component_benchmark:component_benchmark.bzl", "component_benchmark")
2+
3+
# TODO(wagnermaciel): Update this target to provide indigo-pink in a way that doesn't require having to import it with
4+
# stylesUrls inside the components once `component_benchmark` supports asset injection.
5+
6+
component_benchmark(
7+
name = "benchmark",
8+
driver = ":tabs.perf-spec.ts",
9+
driver_deps = [
10+
"@npm//@angular/dev-infra-private",
11+
"@npm//protractor",
12+
"@npm//@types/jasmine",
13+
],
14+
ng_deps = [
15+
"@npm//@angular/core",
16+
"@npm//@angular/platform-browser",
17+
"//src/material/tabs",
18+
],
19+
ng_srcs = [":app.module.ts"],
20+
prefix = "",
21+
styles = ["//src/material/prebuilt-themes:indigo-pink"],
22+
)
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {Component, NgModule, ViewEncapsulation} from '@angular/core';
10+
import {BrowserModule} from '@angular/platform-browser';
11+
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
12+
import {MatTabsModule} from '@angular/material/tabs';
13+
14+
@Component({
15+
selector: 'app-root',
16+
template: `
17+
<button id="show-small-tab-group" (click)="showSmallTabGroup()">Show Small Tab Group</button>
18+
<button id="show-large-tab-group" (click)="showLargeTabGroup()">Show Large Tab Group</button>
19+
<button id="hide" (click)="hide()">Hide</button>
20+
21+
<mat-tab-group *ngIf="isSmallTabGroupVisible">
22+
<mat-tab label="First"> Content 1 </mat-tab>
23+
<mat-tab label="Second"> Content 2 </mat-tab>
24+
<mat-tab label="Third"> Content 3 </mat-tab>
25+
</mat-tab-group>
26+
27+
<mat-tab-group *ngIf="isLargeTabGroupVisible">
28+
<mat-tab label="First"> Content 1 </mat-tab>
29+
<mat-tab label="Second"> Content 2 </mat-tab>
30+
<mat-tab label="Third"> Content 3 </mat-tab>
31+
<mat-tab label="Fourth"> Content 4 </mat-tab>
32+
<mat-tab label="Fifth"> Content 5 </mat-tab>
33+
<mat-tab label="Sixth"> Content 6 </mat-tab>
34+
<mat-tab label="Seventh"> Content 7 </mat-tab>
35+
<mat-tab label="Eigth"> Content 8 </mat-tab>
36+
<mat-tab label="Ninth"> Content 9 </mat-tab>
37+
<mat-tab label="Tenth"> Content 10 </mat-tab>
38+
</mat-tab-group>
39+
`,
40+
encapsulation: ViewEncapsulation.None,
41+
styleUrls: ['//src/material/core/theming/prebuilt/indigo-pink.css'],
42+
})
43+
export class TabsBenchmarkApp {
44+
isSmallTabGroupVisible = false;
45+
isLargeTabGroupVisible = false;
46+
47+
showSmallTabGroup() { this.isSmallTabGroupVisible = true; }
48+
showLargeTabGroup() { this.isLargeTabGroupVisible = true; }
49+
50+
hide() {
51+
this.isSmallTabGroupVisible = false;
52+
this.isLargeTabGroupVisible = false;
53+
}
54+
}
55+
56+
57+
@NgModule({
58+
declarations: [TabsBenchmarkApp],
59+
imports: [
60+
BrowserModule,
61+
BrowserAnimationsModule,
62+
MatTabsModule,
63+
],
64+
providers: [],
65+
bootstrap: [TabsBenchmarkApp],
66+
})
67+
export class AppModule {}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {$, $$, browser, ElementArrayFinder} from 'protractor';
10+
import {runBenchmark} from '@angular/dev-infra-private/benchmark/driver-utilities';
11+
12+
describe('tabs performance benchmarks', () => {
13+
beforeAll(() => {
14+
browser.rootEl = '#root';
15+
});
16+
17+
it('renders a small tab group', async() => {
18+
await runBenchmark({
19+
id: 'small-tab-group-render',
20+
url: '',
21+
ignoreBrowserSynchronization: true,
22+
params: [],
23+
prepare: async () => await $('#hide').click(),
24+
work: async () => await $('#show-small-tab-group').click(),
25+
});
26+
});
27+
28+
it('renders a large tab group', async() => {
29+
await runBenchmark({
30+
id: 'large-tab-group-render',
31+
url: '',
32+
ignoreBrowserSynchronization: true,
33+
params: [],
34+
prepare: async () => await $('#hide').click(),
35+
work: async () => await $('#show-large-tab-group').click(),
36+
});
37+
});
38+
39+
it('switches between tabs', async() => {
40+
let tabs: any[];
41+
let tabToClick = 0;
42+
await runBenchmark({
43+
id: 'tab-switching',
44+
url: '',
45+
ignoreBrowserSynchronization: true,
46+
params: [],
47+
setup: async () => {
48+
await $('#show-small-tab-group').click();
49+
tabs = await $$('.mat-tab-label');
50+
},
51+
prepare: async () => {
52+
tabToClick = tabToClick < tabs.length - 1 ? tabToClick + 1 : 0;
53+
},
54+
work: async () => await tabs[tabToClick].click(),
55+
});
56+
});
57+
});

0 commit comments

Comments
 (0)