Skip to content

Commit cd433a4

Browse files
authored
test(mdc-chips): add performance tests for mdc-chips (#20131)
* fix(mdc-indigo-pink): add mat-core and mat-core-theme to indigo-pink * fixup! fix(mdc-indigo-pink): add mat-core and mat-core-theme to indigo-pink * test(mdc-chips): add performance tests for mdc-chips * fix(mdc-chips-benchmark): remove unnecessary providers * fix(mdc-chips-benchmark): add tests for grid and listbox * fixup! fix(mdc-chips-benchmark): add tests for grid and listbox
1 parent d2b499d commit cd433a4

File tree

4 files changed

+160
-0
lines changed

4 files changed

+160
-0
lines changed

test/benchmarks/mdc/chips/BUILD.bazel

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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_assets = [":chips.html"],
15+
ng_deps = [
16+
"@npm//@angular/core",
17+
"@npm//@angular/platform-browser",
18+
"//src/material-experimental/mdc-chips",
19+
],
20+
ng_srcs = [":app.module.ts"],
21+
prefix = "",
22+
styles = ["//src/material-experimental/mdc-theming:indigo_pink_prebuilt"],
23+
)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
templateUrl: './chips.html',
18+
encapsulation: ViewEncapsulation.None,
19+
styleUrls: ['//src/material-experimental/mdc-theming/prebuilt/indigo-pink.css'],
20+
})
21+
export class ChipsBenchmarkApp {
22+
isSingleChipVisible = false;
23+
isSetVisible = false;
24+
isGridVisible = false;
25+
isListboxVisible = false;
26+
27+
showSingleChip() { this.isSingleChipVisible = true; }
28+
showSet() { this.isSetVisible = true; }
29+
showGrid() { this.isGridVisible = true; }
30+
showListbox() { this.isListboxVisible = true; }
31+
32+
hide() {
33+
this.isSingleChipVisible = false;
34+
this.isSetVisible = false;
35+
this.isGridVisible = false;
36+
this.isListboxVisible = false;
37+
}
38+
}
39+
40+
@NgModule({
41+
declarations: [ChipsBenchmarkApp],
42+
imports: [
43+
BrowserModule,
44+
MatChipsModule,
45+
],
46+
bootstrap: [ChipsBenchmarkApp],
47+
})
48+
export class AppModule {}

test/benchmarks/mdc/chips/chips.html

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<button id="show-single-chip" (click)="showSingleChip()">Show Single Chip</button>
2+
<button id="show-chip-set" (click)="showSet()">Show Chip Set</button>
3+
<button id="show-chip-grid" (click)="showGrid()">Show Chip Grid</button>
4+
<button id="show-chip-listbox" (click)="showListbox()">Show Chip Listbox</button>
5+
<button id="hide" (click)="hide()">Hide</button>
6+
7+
<mat-chip id="single-chip" *ngIf="isSingleChipVisible">One</mat-chip>
8+
9+
<mat-chip-set *ngIf="isSetVisible">
10+
<mat-chip>One</mat-chip>
11+
<mat-chip>Two</mat-chip>
12+
<mat-chip>Three</mat-chip>
13+
<mat-chip>Four</mat-chip>
14+
<mat-chip>Five</mat-chip>
15+
<mat-chip>Six</mat-chip>
16+
</mat-chip-set>
17+
18+
<mat-chip-grid #chipGrid1 *ngIf="isGridVisible">
19+
<mat-chip-row>One</mat-chip-row>
20+
<mat-chip-row>Two</mat-chip-row>
21+
<mat-chip-row>Three</mat-chip-row>
22+
<mat-chip-row>Four</mat-chip-row>
23+
<mat-chip-row>Five</mat-chip-row>
24+
<mat-chip-row>Six</mat-chip-row>
25+
<input [matChipInputFor]="chipGrid1"/>
26+
</mat-chip-grid>
27+
28+
<mat-chip-listbox *ngIf="isListboxVisible">
29+
<mat-chip>One</mat-chip>
30+
<mat-chip>Two</mat-chip>
31+
<mat-chip>Three</mat-chip>
32+
<mat-chip>Four</mat-chip>
33+
<mat-chip>Five</mat-chip>
34+
<mat-chip>Six</mat-chip>
35+
</mat-chip-listbox>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
async function runRenderBenchmark(testId: string, showBtnId: string) {
13+
return runBenchmark({
14+
id: testId,
15+
url: '',
16+
ignoreBrowserSynchronization: true,
17+
params: [],
18+
prepare: async () => await $('#hide').click(),
19+
work: async () => await $(showBtnId).click(),
20+
});
21+
}
22+
23+
describe('chip performance benchmarks', () => {
24+
beforeAll(() => {
25+
browser.rootEl = '#root';
26+
});
27+
28+
it('renders a single chip', async() => {
29+
await runRenderBenchmark('single-chip-render', '#show-single-chip');
30+
});
31+
32+
it('renders a set', async() => {
33+
await runRenderBenchmark('chip-set-render', '#show-chip-set');
34+
});
35+
36+
it('renders a grid', async() => {
37+
await runRenderBenchmark('chip-grid-render', '#show-chip-grid');
38+
});
39+
40+
it('renders a listbox', async() => {
41+
await runRenderBenchmark('chip-listbox-render', '#show-chip-listbox');
42+
});
43+
44+
it('clicks a chip', async() => {
45+
await runBenchmark({
46+
id: 'chip-click',
47+
url: '',
48+
ignoreBrowserSynchronization: true,
49+
params: [],
50+
setup: async() => await $('#show-single-chip').click(),
51+
work: async () => await $('#single-chip').click(),
52+
});
53+
});
54+
});

0 commit comments

Comments
 (0)