mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
feat(material-experimental): add progress spinner test harness… (#16622)
* feat(material-experimental): add progress spinner test harness skeleton * use number coercion * fix build * address feedback
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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",
|
||||
],
|
||||
)
|
||||
+59
@@ -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<ProgressSpinnerHarnessTest>;
|
||||
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<ProgressSpinnerMode>(await determinate.getMode()).toBe('determinate');
|
||||
expect<ProgressSpinnerMode>(await indeterminate.getMode()).toBe('indeterminate');
|
||||
});
|
||||
}
|
||||
|
||||
@Component({
|
||||
template: `
|
||||
<mat-progress-spinner mode="determinate" [value]="value"></mat-progress-spinner>
|
||||
<mat-progress-spinner mode="indeterminate"></mat-progress-spinner>
|
||||
`
|
||||
})
|
||||
class ProgressSpinnerHarnessTest {
|
||||
value: number;
|
||||
}
|
||||
@@ -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<number|null> {
|
||||
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<ProgressSpinnerMode> {
|
||||
const modeAttr = (await this.host()).getAttribute('mode');
|
||||
return await modeAttr as ProgressSpinnerMode;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user