Skip to content

Commit 149c6ac

Browse files
committed
test(mdc-checkbox): add performance tests for mdc-checkbox
1 parent cc4e1a2 commit 149c6ac

File tree

3 files changed

+179
-0
lines changed

3 files changed

+179
-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 = ":checkbox.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-checkbox",
18+
],
19+
ng_srcs = [":app.module.ts"],
20+
prefix = "",
21+
styles = ["//src/material-experimental/mdc-theming:indigo_pink_prebuilt"],
22+
)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 {MatCheckboxModule} from '@angular/material-experimental/mdc-checkbox';
12+
13+
/** component: mdc-checkbox */
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 id="indeterminate" (click)="indeterminate()">Indeterminate</button>
21+
22+
<mat-checkbox *ngIf="isVisible"
23+
[checked]="isChecked"
24+
[indeterminate]="isIndeterminate"
25+
(change)="toggleIsChecked()">
26+
Check me!</mat-checkbox>
27+
`,
28+
encapsulation: ViewEncapsulation.None,
29+
styleUrls: ['//src/material-experimental/mdc-theming/prebuilt/indigo-pink.css'],
30+
})
31+
export class CheckboxBenchmarkApp {
32+
isChecked = false;
33+
isVisible = false;
34+
isIndeterminate = false;
35+
36+
show() { this.isVisible = true; }
37+
hide() { this.isVisible = false; }
38+
indeterminate() { this.isIndeterminate = true; }
39+
toggleIsChecked() { this.isChecked = !this.isChecked; }
40+
}
41+
42+
43+
@NgModule({
44+
declarations: [CheckboxBenchmarkApp],
45+
imports: [
46+
BrowserModule,
47+
MatCheckboxModule,
48+
],
49+
providers: [],
50+
bootstrap: [CheckboxBenchmarkApp],
51+
})
52+
export class AppModule {}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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('checkbox performance benchmarks', () => {
13+
beforeAll(() => {
14+
browser.rootEl = '#root';
15+
});
16+
17+
it('renders a checked checkbox', async() => {
18+
await runBenchmark({
19+
id: 'checkbox-render-checked',
20+
url: '',
21+
ignoreBrowserSynchronization: true,
22+
params: [],
23+
setup: async () => {
24+
await $('#show').click();
25+
await $('mat-checkbox').click();
26+
},
27+
prepare: async () => {
28+
expect(await $('mat-checkbox input').isSelected())
29+
.toBe(true, 'The checkbox should be in a selected state.');
30+
await $('#hide').click();
31+
},
32+
work: async () => await $('#show').click()
33+
});
34+
});
35+
36+
it('renders an unchecked checkbox', async() => {
37+
await runBenchmark({
38+
id: 'checkbox-render-unchecked',
39+
url: '',
40+
ignoreBrowserSynchronization: true,
41+
params: [],
42+
setup: async() => await $('#show').click(),
43+
prepare: async () => {
44+
expect(await $('mat-checkbox input').isSelected())
45+
.toBe(false, 'The checkbox should be in an unselected state.');
46+
await $('#hide').click();
47+
},
48+
work: async () => await $('#show').click()
49+
});
50+
});
51+
52+
it('renders an indeterminate checkbox', async() => {
53+
await runBenchmark({
54+
id: 'checkbox-render-indeterminate',
55+
url: '',
56+
ignoreBrowserSynchronization: true,
57+
params: [],
58+
setup: async() => {
59+
await $('#show').click();
60+
await $('#indeterminate').click();
61+
},
62+
prepare: async () => {
63+
expect(await $('mat-checkbox input').getAttribute('indeterminate'))
64+
.toBe('true', 'The checkbox should be in an indeterminate state');
65+
await $('#hide').click();
66+
},
67+
work: async () => await $('#show').click()
68+
});
69+
});
70+
71+
it('updates from unchecked to checked', async() => {
72+
await runBenchmark({
73+
id: 'checkbox-click-unchecked-to-checked',
74+
url: '',
75+
ignoreBrowserSynchronization: true,
76+
params: [],
77+
setup: async () => {
78+
await $('#show').click();
79+
await $('mat-checkbox').click();
80+
},
81+
prepare: async () => {
82+
await $('mat-checkbox').click();
83+
expect(await $('mat-checkbox input').isSelected())
84+
.toBe(false, 'The checkbox should be in an unchecked state.');
85+
},
86+
work: async () => await $('mat-checkbox').click(),
87+
});
88+
});
89+
90+
it('updates from checked to unchecked', async() => {
91+
await runBenchmark({
92+
id: 'checkbox-click-checked-to-unchecked',
93+
url: '',
94+
ignoreBrowserSynchronization: true,
95+
params: [],
96+
setup: async () => await $('#show').click(),
97+
prepare: async () => {
98+
await $('mat-checkbox').click();
99+
expect(await $('mat-checkbox input').isSelected())
100+
.toBe(true, 'The checkbox should be in a checked state.');
101+
},
102+
work: async () => await $('mat-checkbox').click(),
103+
});
104+
});
105+
});

0 commit comments

Comments
 (0)