Skip to content

Commit b648c9d

Browse files
authored
test(material-experimental/mdc-slider): add tests for slider with one-way value binding (#22242)
1 parent 0a9399d commit b648c9d

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

src/material-experimental/mdc-slider/slider.spec.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,56 @@ describe('MDC-based MatSlider' , () => {
728728
});
729729
});
730730
});
731+
732+
describe('slider with value property binding', () => {
733+
let fixture: ComponentFixture<SliderWithOneWayBinding>;
734+
let testComponent: SliderWithOneWayBinding;
735+
let inputInstance: MatSliderThumb;
736+
737+
beforeEach(waitForAsync(() => {
738+
fixture = createComponent(SliderWithOneWayBinding);
739+
fixture.detectChanges();
740+
testComponent = fixture.debugElement.componentInstance;
741+
const sliderDebugElement = fixture.debugElement.query(By.directive(MatSlider));
742+
const sliderInstance = sliderDebugElement.componentInstance;
743+
inputInstance = sliderInstance._getInput(Thumb.END);
744+
}));
745+
746+
it('should update when bound value changes', () => {
747+
testComponent.value = 75;
748+
fixture.detectChanges();
749+
expect(inputInstance.value).toBe(75);
750+
});
751+
});
752+
753+
describe('range slider with value property binding', () => {
754+
let fixture: ComponentFixture<RangeSliderWithOneWayBinding>;
755+
let testComponent: RangeSliderWithOneWayBinding;
756+
let startInputInstance: MatSliderThumb;
757+
let endInputInstance: MatSliderThumb;
758+
759+
beforeEach(waitForAsync(() => {
760+
fixture = createComponent(RangeSliderWithOneWayBinding);
761+
fixture.detectChanges();
762+
testComponent = fixture.debugElement.componentInstance;
763+
const sliderDebugElement = fixture.debugElement.query(By.directive(MatSlider));
764+
const sliderInstance = sliderDebugElement.componentInstance;
765+
startInputInstance = sliderInstance._getInput(Thumb.START);
766+
endInputInstance = sliderInstance._getInput(Thumb.END);
767+
}));
768+
769+
it('should update when bound start value changes', () => {
770+
testComponent.startValue = 30;
771+
fixture.detectChanges();
772+
expect(startInputInstance.value).toBe(30);
773+
});
774+
775+
it('should update when bound end value changes', () => {
776+
testComponent.endValue = 70;
777+
fixture.detectChanges();
778+
expect(endInputInstance.value).toBe(70);
779+
});
780+
});
731781
});
732782

733783

@@ -855,6 +905,30 @@ class DiscreteRangeSliderWithDisplayWith {
855905
}
856906
}
857907

908+
@Component({
909+
template: `
910+
<mat-slider>
911+
<input [value]="value" matSliderThumb>
912+
</mat-slider>
913+
`,
914+
})
915+
class SliderWithOneWayBinding {
916+
value = 50;
917+
}
918+
919+
@Component({
920+
template: `
921+
<mat-slider>
922+
<input [value]="startValue" matSliderStartThumb>
923+
<input [value]="endValue" matSliderEndThumb>
924+
</mat-slider>
925+
`,
926+
})
927+
class RangeSliderWithOneWayBinding {
928+
startValue = 25;
929+
endValue = 75;
930+
}
931+
858932
/** The pointer event types used by the MDC Slider. */
859933
const enum PointerEventType {
860934
POINTER_DOWN = 'pointerdown',

0 commit comments

Comments
 (0)