Skip to content

Commit

Permalink
test(button): add performance tests for mat-raised-button (#19545)
Browse files Browse the repository at this point in the history
  • Loading branch information
wagnermaciel authored Jun 26, 2020
1 parent 219b4ea commit 286fd99
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 8 deletions.
22 changes: 22 additions & 0 deletions test/benchmarks/material/button/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
load("@npm_angular_dev_infra_private//benchmark/component_benchmark:component_benchmark.bzl", "component_benchmark")

# TODO(wagnermaciel): Update this target to provide indigo-pink in a way that doesn't require having to import it with
# stylesUrls inside the components once `component_benchmark` supports asset injection.

component_benchmark(
name = "benchmark",
driver = ":button.perf-spec.ts",
driver_deps = [
"@npm//@angular/dev-infra-private",
"@npm//protractor",
"@npm//@types/jasmine",
],
ng_deps = [
"@npm//@angular/core",
"@npm//@angular/platform-browser",
"//src/material/button",
],
ng_srcs = [":app.module.ts"],
prefix = "",
styles = ["//src/material/prebuilt-themes:indigo-pink"],
)
42 changes: 42 additions & 0 deletions test/benchmarks/material/button/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {Component, NgModule, ViewEncapsulation} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {MatButtonModule} from '@angular/material/button';

@Component({
selector: 'app-root',
template: `
<button id="show" (click)="show()">Show</button>
<button id="hide" (click)="hide()">Hide</button>
<button *ngIf="isVisible" mat-raised-button>Basic</button>
`,
encapsulation: ViewEncapsulation.None,
styleUrls: ['//src/material/core/theming/prebuilt/indigo-pink.css'],
})
export class ButtonBenchmarkApp {
isChecked = false;
isVisible = false;

show() { this.isVisible = true; }
hide() { this.isVisible = false; }
}


@NgModule({
declarations: [ButtonBenchmarkApp],
imports: [
BrowserModule,
MatButtonModule,
],
providers: [],
bootstrap: [ButtonBenchmarkApp],
})
export class AppModule {}
38 changes: 38 additions & 0 deletions test/benchmarks/material/button/button.perf-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {$, browser} from 'protractor';
import {runBenchmark} from '@angular/dev-infra-private/benchmark/driver-utilities';

describe('button performance benchmarks', () => {
beforeAll(() => {
browser.rootEl = '#root';
});

it('renders a basic raised button', async() => {
await runBenchmark({
id: 'button-render',
url: '',
ignoreBrowserSynchronization: true,
params: [],
prepare: async () => await $('#hide').click(),
work: async () => await $('#show').click(),
});
});

it('clicks a basic raised button', async() => {
await runBenchmark({
id: 'button-click',
url: '',
ignoreBrowserSynchronization: true,
params: [],
setup: async () => await $('#show').click(),
work: async () => await $('.mat-raised-button').click(),
});
});
});
14 changes: 6 additions & 8 deletions test/benchmarks/material/checkbox/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ import {MatCheckboxModule} from '@angular/material/checkbox';
<button id="hide" (click)="hide()">Hide</button>
<button id="indeterminate" (click)="indeterminate()">Indeterminate</button>
<ng-container *ngIf="isVisible">
<mat-checkbox
[checked]="isChecked"
[indeterminate]="isIndeterminate"
(change)="toggleIsChecked()">
Check me!</mat-checkbox>
</ng-container>
<mat-checkbox *ngIf="isVisible"
[checked]="isChecked"
[indeterminate]="isIndeterminate"
(change)="toggleIsChecked()">
Check me!</mat-checkbox>
`,
encapsulation: ViewEncapsulation.None,
styleUrls: ['//src/material/core/theming/prebuilt/indigo-pink.css'],
Expand All @@ -47,6 +45,6 @@ export class CheckboxBenchmarkApp {
MatCheckboxModule,
],
providers: [],
bootstrap: [CheckboxBenchmarkApp]
bootstrap: [CheckboxBenchmarkApp],
})
export class AppModule {}

0 comments on commit 286fd99

Please sign in to comment.