Skip to content

Commit 5dfbd0d

Browse files
committed
test(mdc-chips): add performance tests for mdc-chips
1 parent 1381af7 commit 5dfbd0d

File tree

3 files changed

+130
-0
lines changed

3 files changed

+130
-0
lines changed

test/benchmarks/mdc/chips/BUILD.bazel

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 = ":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-experimental/mdc-chips",
18+
],
19+
ng_srcs = [":app.module.ts"],
20+
prefix = "",
21+
styles = ["//src/material-experimental/mdc-theming:indigo_pink_prebuilt"],
22+
)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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-experimental/mdc-chips';
12+
13+
/** component: mdc-chip */
14+
15+
@Component({
16+
selector: 'app-root',
17+
template: `
18+
<button id="show-single" (click)="showSingle()">Show Single</button>
19+
<button id="hide-single" (click)="hideSingle()">Hide Single</button>
20+
21+
<button id="show-multiple" (click)="showMultiple()">Show Multiple</button>
22+
<button id="hide-multiple" (click)="hideMultiple()">Hide Multiple</button>
23+
24+
<mat-chip *ngIf="isSingleVisible">One</mat-chip>
25+
26+
<mat-chip-set *ngIf="isMultipleVisible">
27+
<mat-chip>One</mat-chip>
28+
<mat-chip>Two</mat-chip>
29+
<mat-chip>Three</mat-chip>
30+
<mat-chip>Four</mat-chip>
31+
<mat-chip>Five</mat-chip>
32+
<mat-chip>Six</mat-chip>
33+
</mat-chip-set>
34+
`,
35+
encapsulation: ViewEncapsulation.None,
36+
styleUrls: ['//src/material-experimental/mdc-theming/prebuilt/indigo-pink.css'],
37+
})
38+
export class ChipsBenchmarkApp {
39+
isSingleVisible = false;
40+
isMultipleVisible = false;
41+
42+
showSingle() { this.isSingleVisible = true; }
43+
hideSingle() { this.isSingleVisible = false; }
44+
45+
showMultiple() { this.isMultipleVisible = true; }
46+
hideMultiple() { this.isMultipleVisible = false; }
47+
}
48+
49+
50+
@NgModule({
51+
declarations: [ChipsBenchmarkApp],
52+
imports: [
53+
BrowserModule,
54+
MatChipsModule,
55+
],
56+
providers: [],
57+
bootstrap: [ChipsBenchmarkApp],
58+
})
59+
export class AppModule {}
Lines changed: 49 additions & 0 deletions
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-mdc-chip').click(),
47+
});
48+
});
49+
});

0 commit comments

Comments
 (0)