diff --git a/test/benchmarks/mdc/chips/BUILD.bazel b/test/benchmarks/mdc/chips/BUILD.bazel new file mode 100644 index 000000000000..8b4fc3f2be05 --- /dev/null +++ b/test/benchmarks/mdc/chips/BUILD.bazel @@ -0,0 +1,23 @@ +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 = ":chips.perf-spec.ts", + driver_deps = [ + "@npm//@angular/dev-infra-private", + "@npm//protractor", + "@npm//@types/jasmine", + ], + ng_assets = [":chips.html"], + ng_deps = [ + "@npm//@angular/core", + "@npm//@angular/platform-browser", + "//src/material-experimental/mdc-chips", + ], + ng_srcs = [":app.module.ts"], + prefix = "", + styles = ["//src/material-experimental/mdc-theming:indigo_pink_prebuilt"], +) diff --git a/test/benchmarks/mdc/chips/app.module.ts b/test/benchmarks/mdc/chips/app.module.ts new file mode 100644 index 000000000000..d3245e7d01f3 --- /dev/null +++ b/test/benchmarks/mdc/chips/app.module.ts @@ -0,0 +1,48 @@ +/** + * @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 {MatChipsModule} from '@angular/material-experimental/mdc-chips'; + +/** component: mdc-chip */ + +@Component({ + selector: 'app-root', + templateUrl: './chips.html', + encapsulation: ViewEncapsulation.None, + styleUrls: ['//src/material-experimental/mdc-theming/prebuilt/indigo-pink.css'], +}) +export class ChipsBenchmarkApp { + isSingleChipVisible = false; + isSetVisible = false; + isGridVisible = false; + isListboxVisible = false; + + showSingleChip() { this.isSingleChipVisible = true; } + showSet() { this.isSetVisible = true; } + showGrid() { this.isGridVisible = true; } + showListbox() { this.isListboxVisible = true; } + + hide() { + this.isSingleChipVisible = false; + this.isSetVisible = false; + this.isGridVisible = false; + this.isListboxVisible = false; + } +} + +@NgModule({ + declarations: [ChipsBenchmarkApp], + imports: [ + BrowserModule, + MatChipsModule, + ], + bootstrap: [ChipsBenchmarkApp], +}) +export class AppModule {} diff --git a/test/benchmarks/mdc/chips/chips.html b/test/benchmarks/mdc/chips/chips.html new file mode 100644 index 000000000000..88656642ff3a --- /dev/null +++ b/test/benchmarks/mdc/chips/chips.html @@ -0,0 +1,35 @@ + + + + + + +One + + + One + Two + Three + Four + Five + Six + + + + One + Two + Three + Four + Five + Six + + + + + One + Two + Three + Four + Five + Six + diff --git a/test/benchmarks/mdc/chips/chips.perf-spec.ts b/test/benchmarks/mdc/chips/chips.perf-spec.ts new file mode 100755 index 000000000000..4c259bf036ae --- /dev/null +++ b/test/benchmarks/mdc/chips/chips.perf-spec.ts @@ -0,0 +1,54 @@ +/** + * @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'; + +async function runRenderBenchmark(testId: string, showBtnId: string) { + return runBenchmark({ + id: testId, + url: '', + ignoreBrowserSynchronization: true, + params: [], + prepare: async () => await $('#hide').click(), + work: async () => await $(showBtnId).click(), + }); +} + +describe('chip performance benchmarks', () => { + beforeAll(() => { + browser.rootEl = '#root'; + }); + + it('renders a single chip', async() => { + await runRenderBenchmark('single-chip-render', '#show-single-chip'); + }); + + it('renders a set', async() => { + await runRenderBenchmark('chip-set-render', '#show-chip-set'); + }); + + it('renders a grid', async() => { + await runRenderBenchmark('chip-grid-render', '#show-chip-grid'); + }); + + it('renders a listbox', async() => { + await runRenderBenchmark('chip-listbox-render', '#show-chip-listbox'); + }); + + it('clicks a chip', async() => { + await runBenchmark({ + id: 'chip-click', + url: '', + ignoreBrowserSynchronization: true, + params: [], + setup: async() => await $('#show-single-chip').click(), + work: async () => await $('#single-chip').click(), + }); + }); +});