mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
feat(material-experimental): add progress bar test harness skeleton (#16619)
* feat(material-experimental): add progress bar test harness skeleton * use number coercion
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-bar/** @andrewseguin
|
||||
# Note to implementer: please repossess
|
||||
/src/material-experimental/mdc-radio/** @mmalerba
|
||||
/src/material-experimental/mdc-slide-toggle/** @crisbeto
|
||||
|
||||
@@ -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",
|
||||
],
|
||||
)
|
||||
|
||||
ng_test_library(
|
||||
name = "progress_bar_tests_lib",
|
||||
srcs = glob(
|
||||
["**/*.spec.ts"],
|
||||
),
|
||||
deps = [
|
||||
":harness",
|
||||
"//src/cdk-experimental/testing",
|
||||
"//src/cdk-experimental/testing/testbed",
|
||||
"//src/cdk/coercion",
|
||||
"//src/cdk/testing",
|
||||
"//src/material/progress-bar",
|
||||
],
|
||||
)
|
||||
@@ -0,0 +1,60 @@
|
||||
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 {MatProgressBarModule} from '@angular/material/progress-bar';
|
||||
|
||||
import {MatProgressBarHarness} from './progress-bar-harness';
|
||||
|
||||
let fixture: ComponentFixture<ProgressBarHarnessTest>;
|
||||
let loader: HarnessLoader;
|
||||
let progressBarHarness: typeof MatProgressBarHarness;
|
||||
|
||||
describe('MatProgressBarHarness', () => {
|
||||
beforeEach(async () => {
|
||||
await TestBed
|
||||
.configureTestingModule({
|
||||
imports: [MatProgressBarModule],
|
||||
declarations: [ProgressBarHarnessTest],
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(ProgressBarHarnessTest);
|
||||
fixture.detectChanges();
|
||||
loader = TestbedHarnessEnvironment.loader(fixture);
|
||||
progressBarHarness = MatProgressBarHarness;
|
||||
});
|
||||
|
||||
runTests();
|
||||
});
|
||||
|
||||
function runTests() {
|
||||
it('should load all progress bar harnesses', async () => {
|
||||
const progressBars = await loader.getAllHarnesses(progressBarHarness);
|
||||
expect(progressBars.length).toBe(2);
|
||||
});
|
||||
|
||||
it('should get the value', async () => {
|
||||
fixture.componentInstance.value = 50;
|
||||
const [determinate, indeterminate] = await loader.getAllHarnesses(progressBarHarness);
|
||||
expect(await determinate.getValue()).toBe(50);
|
||||
expect(await indeterminate.getValue()).toBe(null);
|
||||
});
|
||||
|
||||
it('should get the mode', async () => {
|
||||
const [determinate, indeterminate] = await loader.getAllHarnesses(progressBarHarness);
|
||||
expect(await determinate.getMode()).toBe('determinate');
|
||||
expect(await indeterminate.getMode()).toBe('indeterminate');
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: Add and test progress bars with modes `buffer` and `query`.
|
||||
@Component({
|
||||
template: `
|
||||
<mat-progress-bar mode="determinate" [value]="value"></mat-progress-bar>
|
||||
<mat-progress-bar mode="indeterminate"></mat-progress-bar>
|
||||
`
|
||||
})
|
||||
class ProgressBarHarnessTest {
|
||||
value: number;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* @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 {coerceNumberProperty} from '@angular/cdk/coercion';
|
||||
|
||||
/**
|
||||
* Harness for interacting with a standard mat-progress-bar in tests.
|
||||
* @dynamic
|
||||
*/
|
||||
export class MatProgressBarHarness extends ComponentHarness {
|
||||
static hostSelector = 'mat-progress-bar';
|
||||
|
||||
/** Gets a promise for the progress bar'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 bar's mode. */
|
||||
async getMode(): Promise<string|null> {
|
||||
return (await this.host()).getAttribute('mode');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user