Skip to content

Commit 219b4ea

Browse files
authored
test(chips): add performance tests for mat-chips (#19550)
1 parent 55c39d8 commit 219b4ea

File tree

3 files changed

+128
-0
lines changed

3 files changed

+128
-0
lines changed
+22
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 = ":chips.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/chips",
18+
],
19+
ng_srcs = [":app.module.ts"],
20+
prefix = "",
21+
styles = ["//src/material/prebuilt-themes:indigo-pink"],
22+
)
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 {Component, NgModule, ViewEncapsulation} from '@angular/core';
10+
import {BrowserModule} from '@angular/platform-browser';
11+
import {MatChipsModule} from '@angular/material/chips';
12+
13+
@Component({
14+
selector: 'app-root',
15+
template: `
16+
<button id="show-single" (click)="showSingle()">Show Single</button>
17+
<button id="hide-single" (click)="hideSingle()">Hide Single</button>
18+
19+
<button id="show-multiple" (click)="showMultiple()">Show Multiple</button>
20+
<button id="hide-multiple" (click)="hideMultiple()">Hide Multiple</button>
21+
22+
<mat-chip *ngIf="isSingleVisible">One</mat-chip>
23+
24+
<mat-chip-list *ngIf="isMultipleVisible">
25+
<mat-chip>One</mat-chip>
26+
<mat-chip>Two</mat-chip>
27+
<mat-chip>Three</mat-chip>
28+
<mat-chip>Four</mat-chip>
29+
<mat-chip>Five</mat-chip>
30+
<mat-chip>Six</mat-chip>
31+
</mat-chip-list>
32+
`,
33+
encapsulation: ViewEncapsulation.None,
34+
styleUrls: ['//src/material/core/theming/prebuilt/indigo-pink.css'],
35+
})
36+
export class ChipsBenchmarkApp {
37+
isSingleVisible = false;
38+
isMultipleVisible = false;
39+
40+
showSingle() { this.isSingleVisible = true; }
41+
hideSingle() { this.isSingleVisible = false; }
42+
43+
showMultiple() { this.isMultipleVisible = true; }
44+
hideMultiple() { this.isMultipleVisible = false; }
45+
}
46+
47+
48+
@NgModule({
49+
declarations: [ChipsBenchmarkApp],
50+
imports: [
51+
BrowserModule,
52+
MatChipsModule,
53+
],
54+
providers: [],
55+
bootstrap: [ChipsBenchmarkApp],
56+
})
57+
export class AppModule {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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} from 'protractor';
10+
import {runBenchmark} from '@angular/dev-infra-private/benchmark/driver-utilities';
11+
12+
describe('chip performance benchmarks', () => {
13+
beforeAll(() => {
14+
browser.rootEl = '#root';
15+
});
16+
17+
it('renders a single chip', async() => {
18+
await runBenchmark({
19+
id: 'single-chip-render',
20+
url: '',
21+
ignoreBrowserSynchronization: true,
22+
params: [],
23+
prepare: async () => await $('#hide-single').click(),
24+
work: async () => await $('#show-single').click(),
25+
});
26+
});
27+
28+
it('renders multiple chips', async() => {
29+
await runBenchmark({
30+
id: 'multiple-chip-render',
31+
url: '',
32+
ignoreBrowserSynchronization: true,
33+
params: [],
34+
prepare: async () => await $('#hide-multiple').click(),
35+
work: async () => await $('#show-multiple').click(),
36+
});
37+
});
38+
39+
it('clicks a chip', async() => {
40+
await runBenchmark({
41+
id: 'chip-click',
42+
url: '',
43+
ignoreBrowserSynchronization: true,
44+
params: [],
45+
setup: async() => await $('#show-single').click(),
46+
work: async () => await $('.mat-chip').click(),
47+
});
48+
});
49+
});

0 commit comments

Comments
 (0)