Skip to content

feat(material-experimental): add progress bar test harness skeleton #16619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,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
Expand Down
30 changes: 30 additions & 0 deletions src/material-experimental/mdc-progress-bar/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
],
)
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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');
}
}