Skip to content

Commit 25ce323

Browse files
authored
test(mdc-form-field): add performance tests for mdc-form-field (#20135)
* 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 * test(mdc-form-field): add performance tests for mdc-form-field * fix(mdc-form-field-benchmark): remove unnecessary provider
1 parent e83dbb1 commit 25ce323

File tree

4 files changed

+126
-0
lines changed

4 files changed

+126
-0
lines changed

test/benchmarks/mdc/button/button.perf-spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,15 @@ describe('button performance benchmarks', () => {
3232
ignoreBrowserSynchronization: true,
3333
params: [],
3434
setup: async () => await $('#show').click(),
35+
<<<<<<< HEAD
36+
<<<<<<< HEAD
3537
work: async () => await $('.mat-mdc-raised-button').click(),
38+
=======
39+
work: async () => await $('.mat-raised-button').click(),
40+
>>>>>>> f1ae4d955... test(mdc-button): add performance tests for mdc-button
41+
=======
42+
work: async () => await $('.mat-mdc-raised-button').click(),
43+
>>>>>>> 63f2747fc... fixup! test(mdc-button): add performance tests for mdc-button
3644
});
3745
});
3846
});
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 = ":form-field.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-form-field",
18+
"//src/material-experimental/mdc-input",
19+
],
20+
ng_srcs = [":app.module.ts"],
21+
prefix = "",
22+
styles = ["//src/material-experimental/mdc-theming:indigo_pink_prebuilt"],
23+
)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 {MatFormFieldModule} from '@angular/material-experimental/mdc-form-field';
12+
import {MatInputModule} from '@angular/material-experimental/mdc-input';
13+
14+
/** component: mdc-form-field */
15+
16+
@Component({
17+
selector: 'app-root',
18+
template: `
19+
<button id="show-input" (click)="showInput()">Show Input</button>
20+
<button id="show-textarea" (click)="showTextarea()">Show Textarea</button>
21+
22+
<button id="hide" (click)="hide()">Hide</button>
23+
24+
<mat-form-field appearance="fill" *ngIf="isInputVisible">
25+
<mat-label>Input</mat-label>
26+
<input matInput>
27+
</mat-form-field>
28+
29+
<mat-form-field appearance="fill" *ngIf="isTextareaVisible">
30+
<mat-label>Textarea</mat-label>
31+
<textarea matInput></textarea>
32+
</mat-form-field>
33+
`,
34+
encapsulation: ViewEncapsulation.None,
35+
styleUrls: ['//src/material-experimental/mdc-theming/prebuilt/indigo-pink.css'],
36+
})
37+
export class FormFieldBenchmarkApp {
38+
isInputVisible = false;
39+
isTextareaVisible = false;
40+
41+
showInput() { this.isInputVisible = true; }
42+
showTextarea() { this.isTextareaVisible = true; }
43+
44+
hide() {
45+
this.isInputVisible = false;
46+
this.isTextareaVisible = false;
47+
}
48+
}
49+
50+
51+
@NgModule({
52+
declarations: [FormFieldBenchmarkApp],
53+
imports: [
54+
BrowserModule,
55+
MatFormFieldModule,
56+
MatInputModule,
57+
],
58+
bootstrap: [FormFieldBenchmarkApp],
59+
})
60+
export class AppModule {}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
function runFormFieldRenderBenchmark(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('form field performance benchmarks', () => {
24+
beforeAll(() => {
25+
browser.rootEl = '#root';
26+
});
27+
28+
it('renders an input in a form field', async() => {
29+
await runFormFieldRenderBenchmark('input-form-field-render', '#show-input');
30+
});
31+
32+
it('renders an textarea in a form field', async() => {
33+
await runFormFieldRenderBenchmark('textarea-form-field-render', '#show-textarea');
34+
});
35+
});

0 commit comments

Comments
 (0)