Skip to content

Commit 1e8c313

Browse files
authored
test(mdc-radio): add performance tests for mdc-radio (#20132)
* 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-radio): add performance tests for mdc-radio * fix(mdc-radio-benchmark): remove unnecessary provider
1 parent cd433a4 commit 1e8c313

File tree

3 files changed

+137
-0
lines changed

3 files changed

+137
-0
lines changed

test/benchmarks/mdc/radio/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 = ":radio.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-radio",
18+
],
19+
ng_srcs = [":app.module.ts"],
20+
prefix = "",
21+
styles = ["//src/material-experimental/mdc-theming:indigo_pink_prebuilt"],
22+
)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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 {MatRadioModule} from '@angular/material-experimental/mdc-radio';
12+
13+
/** component: mdc-radio-button */
14+
15+
@Component({
16+
selector: 'app-root',
17+
template: `
18+
<button id="show-two" (click)="showTwo()">Show Two</button>
19+
<button id="hide-two" (click)="hideTwo()">Hide Two</button>
20+
21+
<button id="show-ten" (click)="showTen()">Show Ten</button>
22+
<button id="hide-ten" (click)="hideTen()">Hide Ten</button>
23+
24+
<mat-radio-group aria-label="Select an option" *ngIf="isTwoVisible">
25+
<mat-radio-button value="1" id="btn-1">Option 1</mat-radio-button>
26+
<mat-radio-button value="2" id="btn-2">Option 2</mat-radio-button>
27+
</mat-radio-group>
28+
29+
<mat-radio-group aria-label="Select an option" *ngIf="isTenVisible">
30+
<mat-radio-button value="1">Option 1</mat-radio-button>
31+
<mat-radio-button value="2">Option 2</mat-radio-button>
32+
<mat-radio-button value="3">Option 3</mat-radio-button>
33+
<mat-radio-button value="4">Option 4</mat-radio-button>
34+
<mat-radio-button value="5">Option 5</mat-radio-button>
35+
<mat-radio-button value="6">Option 6</mat-radio-button>
36+
<mat-radio-button value="7">Option 7</mat-radio-button>
37+
<mat-radio-button value="8">Option 8</mat-radio-button>
38+
<mat-radio-button value="9">Option 9</mat-radio-button>
39+
<mat-radio-button value="10">Option 10</mat-radio-button>
40+
</mat-radio-group>
41+
`,
42+
encapsulation: ViewEncapsulation.None,
43+
styleUrls: ['//src/material-experimental/mdc-theming/prebuilt/indigo-pink.css'],
44+
})
45+
export class RadioBenchmarkApp {
46+
isTwoVisible = false;
47+
isTenVisible = false;
48+
49+
showTwo() { this.isTwoVisible = true; }
50+
hideTwo() { this.isTwoVisible = false; }
51+
52+
showTen() { this.isTenVisible = true; }
53+
hideTen() { this.isTenVisible = false; }
54+
}
55+
56+
57+
@NgModule({
58+
declarations: [RadioBenchmarkApp],
59+
imports: [
60+
BrowserModule,
61+
MatRadioModule,
62+
],
63+
bootstrap: [RadioBenchmarkApp],
64+
})
65+
export class AppModule {}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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('radio button performance benchmarks', () => {
13+
beforeAll(() => {
14+
browser.rootEl = '#root';
15+
});
16+
17+
it('renders two radio buttons', async() => {
18+
await runBenchmark({
19+
id: 'render-two-radio-buttons',
20+
url: '',
21+
ignoreBrowserSynchronization: true,
22+
params: [],
23+
prepare: async () => await $('#hide-two').click(),
24+
work: async () => await $('#show-two').click(),
25+
});
26+
});
27+
28+
it('renders ten radio buttons', async() => {
29+
await runBenchmark({
30+
id: 'render-ten-radio-buttons',
31+
url: '',
32+
ignoreBrowserSynchronization: true,
33+
params: [],
34+
prepare: async () => await $('#hide-ten').click(),
35+
work: async () => await $('#show-ten').click(),
36+
});
37+
});
38+
39+
it('changing between radio buttons', async() => {
40+
await runBenchmark({
41+
id: 'click-radio-button',
42+
url: '',
43+
ignoreBrowserSynchronization: true,
44+
params: [],
45+
setup: async() => await $('#show-two').click(),
46+
prepare: async() => await $('#btn-1').click(),
47+
work: async () => await $('#btn-2').click(),
48+
});
49+
});
50+
});

0 commit comments

Comments
 (0)