Skip to content

Commit 55c39d8

Browse files
authored
test(slide-toggle): add performance tests for mat-slide-toggle (#19572)
1 parent 8147cc9 commit 55c39d8

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-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 = ":slide-toggle.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/slide-toggle",
18+
],
19+
ng_srcs = [":app.module.ts"],
20+
prefix = "",
21+
styles = ["//src/material/prebuilt-themes:indigo-pink"],
22+
)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 {MatSlideToggleModule} from '@angular/material/slide-toggle';
12+
13+
@Component({
14+
selector: 'app-root',
15+
template: `
16+
<button id="show" (click)="show()">Show</button>
17+
<button id="hide" (click)="hide()">Hide</button>
18+
19+
<ng-container *ngIf="isVisible">
20+
<mat-slide-toggle>Slide me!</mat-slide-toggle>
21+
</ng-container>
22+
`,
23+
encapsulation: ViewEncapsulation.None,
24+
styleUrls: ['//src/material/core/theming/prebuilt/indigo-pink.css'],
25+
})
26+
export class SlideToggleBenchmarkApp {
27+
isVisible = false;
28+
show() { this.isVisible = true; }
29+
hide() { this.isVisible = false; }
30+
}
31+
32+
33+
@NgModule({
34+
declarations: [SlideToggleBenchmarkApp],
35+
imports: [
36+
BrowserModule,
37+
MatSlideToggleModule,
38+
],
39+
providers: [],
40+
bootstrap: [SlideToggleBenchmarkApp]
41+
})
42+
export class AppModule {}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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('slide toggle performance benchmarks', () => {
13+
beforeAll(() => {
14+
browser.rootEl = '#root';
15+
});
16+
17+
it('renders a slide toggle', async() => {
18+
await runBenchmark({
19+
id: 'slide-toggle-render',
20+
url: '',
21+
ignoreBrowserSynchronization: true,
22+
params: [],
23+
prepare: async () => await $('#hide').click(),
24+
work: async () => await $('#show').click(),
25+
});
26+
});
27+
28+
it('clicks a slide toggle', async() => {
29+
await runBenchmark({
30+
id: 'slide-toggle-click',
31+
url: '',
32+
ignoreBrowserSynchronization: true,
33+
params: [],
34+
setup: async () => await $('#show').click(),
35+
work: async () => await $('.mat-slide-toggle-bar').click(),
36+
});
37+
});
38+
});

0 commit comments

Comments
 (0)