Skip to content

Commit 8f3bc66

Browse files
wagnermacielmmalerba
authored andcommitted
test(mdc-button): add performance tests for mdc-button (#20032)
* test(mdc-button): add performance tests for mdc-button * 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 * fixup! test(mdc-button): add performance tests for mdc-button
1 parent 7b0bb2c commit 8f3bc66

File tree

6 files changed

+109
-0
lines changed

6 files changed

+109
-0
lines changed

src/material-experimental/mdc-theming/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ sass_library(
3434
"//src/material-experimental/mdc-table:mdc_table_scss_lib",
3535
"//src/material-experimental/mdc-tabs:mdc_tabs_scss_lib",
3636
"//src/material/core:core_scss_lib",
37+
"//src/material/core:theming_scss_lib",
3738
],
3839
)
3940

src/material-experimental/mdc-theming/_all-theme.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
@import '../mdc-progress-bar/progress-bar-theme';
1414
@import '../mdc-input/input-theme';
1515
@import '../mdc-form-field/form-field-theme';
16+
@import '../../material/core/core';
1617
@import '../../material/core/theming/check-duplicate-styles';
1718

1819
@mixin angular-material-mdc-theme($theme-or-color-config) {

src/material-experimental/mdc-theming/prebuilt/indigo-pink.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
@import '../all-theme';
22
@import '../../mdc-typography/all-typography';
33

4+
// Include non-theme styles for core.
5+
@include mat-core();
6+
47
// Define a theme.
58
$primary: mat-palette($mat-indigo);
69
$accent: mat-palette($mat-pink, A200, A100, A400);
@@ -10,3 +13,4 @@ $theme: mat-light-theme($primary, $accent);
1013
// Include all theme styles for the components.
1114
@include angular-material-mdc-theme($theme);
1215
@include angular-material-mdc-typography();
16+
@include mat-core-theme($theme);
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 = ":button.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-button",
18+
],
19+
ng_srcs = [":app.module.ts"],
20+
prefix = "",
21+
styles = ["//src/material-experimental/mdc-theming:indigo_pink_prebuilt"],
22+
)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 {MatButtonModule} from '@angular/material-experimental/mdc-button';
12+
13+
/** component: mdc-raised-button */
14+
15+
@Component({
16+
selector: 'app-root',
17+
template: `
18+
<button id="show" (click)="show()">Show</button>
19+
<button id="hide" (click)="hide()">Hide</button>
20+
<button *ngIf="isVisible" mat-raised-button>Basic</button>
21+
`,
22+
encapsulation: ViewEncapsulation.None,
23+
styleUrls: ['//src/material-experimental/mdc-theming/prebuilt/indigo-pink.css'],
24+
})
25+
export class ButtonBenchmarkApp {
26+
isChecked = false;
27+
isVisible = false;
28+
29+
show() { this.isVisible = true; }
30+
hide() { this.isVisible = false; }
31+
}
32+
33+
34+
@NgModule({
35+
declarations: [ButtonBenchmarkApp],
36+
imports: [
37+
BrowserModule,
38+
MatButtonModule,
39+
],
40+
providers: [],
41+
bootstrap: [ButtonBenchmarkApp],
42+
})
43+
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('button performance benchmarks', () => {
13+
beforeAll(() => {
14+
browser.rootEl = '#root';
15+
});
16+
17+
it('renders a basic raised button', async() => {
18+
await runBenchmark({
19+
id: 'button-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 basic raised button', async() => {
29+
await runBenchmark({
30+
id: 'button-click',
31+
url: '',
32+
ignoreBrowserSynchronization: true,
33+
params: [],
34+
setup: async () => await $('#show').click(),
35+
work: async () => await $('.mat-mdc-raised-button').click(),
36+
});
37+
});
38+
});

0 commit comments

Comments
 (0)