Skip to content

docs(material/slider): add harness example for slider #21466

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 1 commit into from
Jan 6, 2021
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
6 changes: 6 additions & 0 deletions src/components-examples/material/slider/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ ng_module(
]),
module_name = "@angular/components-examples/material/slider",
deps = [
"//src/cdk/testing",
"//src/cdk/testing/testbed",
"//src/material/card",
"//src/material/checkbox",
"//src/material/input",
"//src/material/slider",
"//src/material/slider/testing",
"@npm//@angular/forms",
"@npm//@angular/platform-browser",
"@npm//@angular/platform-browser-dynamic",
"@npm//@types/jasmine",
],
)

Expand Down
3 changes: 3 additions & 0 deletions src/components-examples/material/slider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ import {MatSliderModule} from '@angular/material/slider';
import {SliderConfigurableExample} from './slider-configurable/slider-configurable-example';
import {SliderFormattingExample} from './slider-formatting/slider-formatting-example';
import {SliderOverviewExample} from './slider-overview/slider-overview-example';
import {SliderHarnessExample} from './slider-harness/slider-harness-example';

export {
SliderConfigurableExample,
SliderFormattingExample,
SliderHarnessExample,
SliderOverviewExample,
};

const EXAMPLES = [
SliderConfigurableExample,
SliderFormattingExample,
SliderHarnessExample,
SliderOverviewExample,
];

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<mat-slider value="50"></mat-slider>
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import {TestBed, ComponentFixture, waitForAsync} from '@angular/core/testing';
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
import {MatSliderHarness} from '@angular/material/slider/testing';
import {HarnessLoader} from '@angular/cdk/testing';
import {BrowserDynamicTestingModule, platformBrowserDynamicTesting}
from '@angular/platform-browser-dynamic/testing';
import {MatSliderModule} from '@angular/material/slider';
import {SliderHarnessExample} from './slider-harness-example';

describe('SliderHarnessExample', () => {
let fixture: ComponentFixture<SliderHarnessExample>;
let loader: HarnessLoader;

beforeAll(() => {
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
});

beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
imports: [MatSliderModule],
declarations: [SliderHarnessExample]
}).compileComponents();
fixture = TestBed.createComponent(SliderHarnessExample);
fixture.detectChanges();
loader = TestbedHarnessEnvironment.loader(fixture);
})
);

it('should load all slider harnesses', async () => {
const sliders = await loader.getAllHarnesses(MatSliderHarness);
expect(sliders.length).toBe(1);
});

it('should get value of slider', async () => {
const slider = await loader.getHarness(MatSliderHarness);
expect(await slider.getValue()).toBe(50);
});

it('should get percentage of slider', async () => {
const slider = await loader.getHarness(MatSliderHarness);
expect(await slider.getPercentage()).toBe(0.5);
});

it('should get max value of slider', async () => {
const slider = await loader.getHarness(MatSliderHarness);
expect(await slider.getMaxValue()).toBe(100);
});


it('should be able to set value of slider', async () => {
const slider = await loader.getHarness(MatSliderHarness);
expect(await slider.getValue()).toBe(50);

await slider.setValue(33);

expect(await slider.getValue()).toBe(33);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {Component} from '@angular/core';

/**
* @title Testing with MatSliderHarness
*/
@Component({
selector: 'slider-harness-example',
templateUrl: 'slider-harness-example.html',
})
export class SliderHarnessExample {}