diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 799fe51e8ce..addc84d69d9 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -94,6 +94,7 @@ /src/material-experimental/mdc-chips/** @mmalerba /src/material-experimental/mdc-helpers/** @mmalerba /src/material-experimental/mdc-menu/** @crisbeto +/src/material-experimental/mdc-progress-spinner/** @andrewseguin /src/material-experimental/mdc-progress-bar/** @andrewseguin # Note to implementer: please repossess /src/material-experimental/mdc-radio/** @mmalerba diff --git a/src/material-experimental/mdc-progress-spinner/BUILD.bazel b/src/material-experimental/mdc-progress-spinner/BUILD.bazel new file mode 100644 index 00000000000..1c53c28f331 --- /dev/null +++ b/src/material-experimental/mdc-progress-spinner/BUILD.bazel @@ -0,0 +1,30 @@ +package(default_visibility = ["//visibility:public"]) + +load("//tools:defaults.bzl", "ng_test_library", "ts_library") + +ts_library( + name = "harness", + srcs = glob( + ["harness/**/*.ts"], + exclude = ["**/*.spec.ts"], + ), + deps = [ + "//src/cdk-experimental/testing", + "//src/cdk/coercion", + "//src/material/progress-spinner", + ], +) + +ng_test_library( + name = "progress_spinner_tests_lib", + srcs = glob( + ["**/*.spec.ts"], + ), + deps = [ + ":harness", + "//src/cdk-experimental/testing", + "//src/cdk-experimental/testing/testbed", + "//src/cdk/testing", + "//src/material/progress-spinner", + ], +) diff --git a/src/material-experimental/mdc-progress-spinner/harness/progress-spinner-harness.spec.ts b/src/material-experimental/mdc-progress-spinner/harness/progress-spinner-harness.spec.ts new file mode 100644 index 00000000000..77864ca622a --- /dev/null +++ b/src/material-experimental/mdc-progress-spinner/harness/progress-spinner-harness.spec.ts @@ -0,0 +1,59 @@ +import {HarnessLoader} from '@angular/cdk-experimental/testing'; +import {TestbedHarnessEnvironment} from '@angular/cdk-experimental/testing/testbed'; +import {Component} from '@angular/core'; +import {ComponentFixture, TestBed} from '@angular/core/testing'; +import {MatProgressSpinnerModule, ProgressSpinnerMode} from '@angular/material/progress-spinner'; + +import {MatProgressSpinnerHarness} from './progress-spinner-harness'; + +let fixture: ComponentFixture; +let loader: HarnessLoader; +let progressSpinnerHarness: typeof MatProgressSpinnerHarness; + +describe('MatProgressSpinnerHarness', () => { + beforeEach(async () => { + await TestBed + .configureTestingModule({ + imports: [MatProgressSpinnerModule], + declarations: [ProgressSpinnerHarnessTest], + }) + .compileComponents(); + + fixture = TestBed.createComponent(ProgressSpinnerHarnessTest); + fixture.detectChanges(); + loader = TestbedHarnessEnvironment.loader(fixture); + progressSpinnerHarness = MatProgressSpinnerHarness; + }); + + runTests(); +}); + +function runTests() { + it('should load all progress spinner harnesses', async () => { + const progressSpinners = await loader.getAllHarnesses(progressSpinnerHarness); + expect(progressSpinners.length).toBe(2); + }); + + it('should get the value', async () => { + fixture.componentInstance.value = 50; + const [determinate, indeterminate] = await loader.getAllHarnesses(progressSpinnerHarness); + expect(await determinate.getValue()).toBe(50); + expect(await indeterminate.getValue()).toBe(null); + }); + + it('should get the mode', async () => { + const [determinate, indeterminate] = await loader.getAllHarnesses(progressSpinnerHarness); + expect(await determinate.getMode()).toBe('determinate'); + expect(await indeterminate.getMode()).toBe('indeterminate'); + }); +} + +@Component({ + template: ` + + + ` +}) +class ProgressSpinnerHarnessTest { + value: number; +} diff --git a/src/material-experimental/mdc-progress-spinner/harness/progress-spinner-harness.ts b/src/material-experimental/mdc-progress-spinner/harness/progress-spinner-harness.ts new file mode 100644 index 00000000000..dec66a7b08d --- /dev/null +++ b/src/material-experimental/mdc-progress-spinner/harness/progress-spinner-harness.ts @@ -0,0 +1,32 @@ +/** + * @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 {ComponentHarness} from '@angular/cdk-experimental/testing'; +import {ProgressSpinnerMode} from '@angular/material/progress-spinner'; +import {coerceNumberProperty} from '@angular/cdk/coercion'; + +/** + * Harness for interacting with a standard mat-progress-spinner in tests. + * @dynamic + */ +export class MatProgressSpinnerHarness extends ComponentHarness { + static hostSelector = 'mat-progress-spinner'; + + /** Gets a promise for the progress spinner's value. */ + async getValue(): Promise { + const host = await this.host(); + const ariaValue = await host.getAttribute('aria-valuenow'); + return ariaValue ? coerceNumberProperty(ariaValue) : null; + } + + /** Gets a promise for the progress spinner's mode. */ + async getMode(): Promise { + const modeAttr = (await this.host()).getAttribute('mode'); + return await modeAttr as ProgressSpinnerMode; + } +}