Skip to content

Commit 6c73555

Browse files
committed
feat(material-experimental): add progress bar test harness skeleton
1 parent 88631b9 commit 6c73555

File tree

4 files changed

+137
-0
lines changed

4 files changed

+137
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
load("//tools:defaults.bzl", "ng_test_library", "ts_library")
4+
5+
ts_library(
6+
name = "harness",
7+
srcs = glob(
8+
["harness/**/*.ts"],
9+
exclude = ["**/*.spec.ts"],
10+
),
11+
deps = [
12+
"//src/cdk-experimental/testing",
13+
],
14+
)
15+
16+
ng_test_library(
17+
name = "progress_bar_tests_lib",
18+
srcs = glob(
19+
["**/*.spec.ts"],
20+
),
21+
deps = [
22+
":harness",
23+
"//src/cdk-experimental/testing",
24+
"//src/cdk-experimental/testing/testbed",
25+
"//src/cdk/testing",
26+
"//src/material/progress-bar",
27+
],
28+
)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import {HarnessLoader} from '@angular/cdk-experimental/testing';
2+
import {TestbedHarnessEnvironment} from '@angular/cdk-experimental/testing/testbed';
3+
import {Component} from '@angular/core';
4+
import {ComponentFixture, TestBed} from '@angular/core/testing';
5+
import {MatProgressBarModule} from '@angular/material/progress-bar';
6+
7+
import {MatProgressBarHarness} from './progress-bar-harness';
8+
9+
let fixture: ComponentFixture<ProgressBarHarnessTest>;
10+
let loader: HarnessLoader;
11+
let progressBarHarness: typeof MatProgressBarHarness;
12+
13+
describe('MatProgressBarHarness', () => {
14+
beforeEach(async () => {
15+
await TestBed
16+
.configureTestingModule({
17+
imports: [MatProgressBarModule],
18+
declarations: [ProgressBarHarnessTest],
19+
})
20+
.compileComponents();
21+
22+
fixture = TestBed.createComponent(ProgressBarHarnessTest);
23+
fixture.detectChanges();
24+
loader = TestbedHarnessEnvironment.loader(fixture);
25+
progressBarHarness = MatProgressBarHarness;
26+
});
27+
28+
runTests();
29+
});
30+
31+
function runTests() {
32+
it('should load all progress bar harnesses', async () => {
33+
const progressBars = await loader.getAllHarnesses(progressBarHarness);
34+
expect(progressBars.length).toBe(4);
35+
});
36+
37+
it('should get the value', async () => {
38+
fixture.componentInstance.value = 50;
39+
const [determinate, indeterminate] = await loader.getAllHarnesses(progressBarHarness);
40+
expect(await determinate.getValue()).toBe(50);
41+
expect(await indeterminate.getValue()).toBe(null);
42+
});
43+
44+
it('should get the mode', async () => {
45+
const [determinate, indeterminate] = await loader.getAllHarnesses(progressBarHarness);
46+
expect(await determinate.getMode()).toBe('determinate');
47+
expect(await indeterminate.getMode()).toBe('indeterminate');
48+
});
49+
}
50+
51+
// TODO: Add and test progress bars with modes `buffer` and `query`.
52+
@Component({
53+
template: `
54+
<mat-progress-bar mode="determinate" [value]="value"></mat-progress-bar>
55+
<mat-progress-bar mode="indeterminate"></mat-progress-bar>
56+
`
57+
})
58+
class ProgressBarHarnessTest {
59+
value: number;
60+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 {ComponentHarness} from '@angular/cdk-experimental/testing';
10+
11+
/**
12+
* Harness for interacting with a standard mat-progress-bar in tests.
13+
* @dynamic
14+
*/
15+
export class MatProgressBarHarness extends ComponentHarness {
16+
static hostSelector = 'mat-progress-bar';
17+
18+
/** Gets a promise for the progress bar's value. */
19+
async getValue(): Promise<number|null> {
20+
const host = await this.host();
21+
const ariaValue = await host.getAttribute('aria-valuenow');
22+
23+
if (ariaValue) {
24+
return Number(ariaValue);
25+
}
26+
27+
return null;
28+
}
29+
30+
/** Gets a promise for the progress bar's mode. */
31+
async getMode(): Promise<string|null> {
32+
return (await this.host()).getAttribute('mode');
33+
}
34+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"extends": "../tsconfig-build",
3+
"files": [
4+
"public-api.ts",
5+
"../typings.d.ts"
6+
],
7+
"angularCompilerOptions": {
8+
"annotateForClosureCompiler": true,
9+
"strictMetadataEmit": true,
10+
"flatModuleOutFile": "index.js",
11+
"flatModuleId": "@angular/material-experimental/mdc-progress-bar",
12+
"skipTemplateCodegen": true,
13+
"fullTemplateTypeCheck": true
14+
}
15+
}

0 commit comments

Comments
 (0)