Skip to content

test(material-experimental/mdc-slider): add tests for slider with one… #22242

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
Mar 16, 2021
Merged
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
74 changes: 74 additions & 0 deletions src/material-experimental/mdc-slider/slider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,56 @@ describe('MDC-based MatSlider' , () => {
});
});
});

describe('slider with value property binding', () => {
let fixture: ComponentFixture<SliderWithOneWayBinding>;
let testComponent: SliderWithOneWayBinding;
let inputInstance: MatSliderThumb;

beforeEach(waitForAsync(() => {
fixture = createComponent(SliderWithOneWayBinding);
fixture.detectChanges();
testComponent = fixture.debugElement.componentInstance;
const sliderDebugElement = fixture.debugElement.query(By.directive(MatSlider));
const sliderInstance = sliderDebugElement.componentInstance;
inputInstance = sliderInstance._getInput(Thumb.END);
}));

it('should update when bound value changes', () => {
testComponent.value = 75;
fixture.detectChanges();
expect(inputInstance.value).toBe(75);
});
});

describe('range slider with value property binding', () => {
let fixture: ComponentFixture<RangeSliderWithOneWayBinding>;
let testComponent: RangeSliderWithOneWayBinding;
let startInputInstance: MatSliderThumb;
let endInputInstance: MatSliderThumb;

beforeEach(waitForAsync(() => {
fixture = createComponent(RangeSliderWithOneWayBinding);
fixture.detectChanges();
testComponent = fixture.debugElement.componentInstance;
const sliderDebugElement = fixture.debugElement.query(By.directive(MatSlider));
const sliderInstance = sliderDebugElement.componentInstance;
startInputInstance = sliderInstance._getInput(Thumb.START);
endInputInstance = sliderInstance._getInput(Thumb.END);
}));

it('should update when bound start value changes', () => {
testComponent.startValue = 30;
fixture.detectChanges();
expect(startInputInstance.value).toBe(30);
});

it('should update when bound end value changes', () => {
testComponent.endValue = 70;
fixture.detectChanges();
expect(endInputInstance.value).toBe(70);
});
});
});


Expand Down Expand Up @@ -855,6 +905,30 @@ class DiscreteRangeSliderWithDisplayWith {
}
}

@Component({
template: `
<mat-slider>
<input [value]="value" matSliderThumb>
</mat-slider>
`,
})
class SliderWithOneWayBinding {
value = 50;
}

@Component({
template: `
<mat-slider>
<input [value]="startValue" matSliderStartThumb>
<input [value]="endValue" matSliderEndThumb>
</mat-slider>
`,
})
class RangeSliderWithOneWayBinding {
startValue = 25;
endValue = 75;
}

/** The pointer event types used by the MDC Slider. */
const enum PointerEventType {
POINTER_DOWN = 'pointerdown',
Expand Down