-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
fix(slider): constraints value between min and max #1567
Changes from 2 commits
a53a129
da2af1e
c9ef34c
920c875
ffbc295
1ad457b
43786b8
35f0044
333b11e
6f322cf
c0e6f83
b56f520
c6b4c22
9422793
dbfd235
2e651e7
95b2a34
8e16992
2ebb46f
f0e3e26
fdc0ac8
65401a3
9eaf7e4
c63b9f4
f10ac7c
8e7f80d
8c1a791
e33360d
86758f3
f43bacf
4570998
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,9 @@ describe('MdSlider', () => { | |
SliderWithSetTickInterval, | ||
SliderWithThumbLabel, | ||
SliderWithTwoWayBinding, | ||
SliderWithValueSmallerThanMin, | ||
SliderWithValueGreaterThanMax, | ||
SliderWithValueBetweenMinAndMax | ||
], | ||
providers: [ | ||
{provide: HAMMER_GESTURE_CONFIG, useFactory: () => { | ||
|
@@ -621,6 +624,102 @@ describe('MdSlider', () => { | |
|
||
// TODO: Add tests for ng-pristine, ng-touched, ng-invalid. | ||
}); | ||
|
||
describe('slider with set min and max and a value smaller than min', () => { | ||
let fixture: ComponentFixture<SliderWithValueSmallerThanMin>; | ||
let sliderDebugElement: DebugElement; | ||
let sliderNativeElement: HTMLElement; | ||
let sliderInstance: MdSlider; | ||
let sliderTrackElement: HTMLElement; | ||
let sliderDimensions: ClientRect; | ||
let thumbElement: HTMLElement; | ||
let thumbDimensions: ClientRect; | ||
|
||
beforeEach(() => { | ||
|
||
fixture = TestBed.createComponent(SliderWithValueSmallerThanMin); | ||
fixture.detectChanges(); | ||
|
||
sliderDebugElement = fixture.debugElement.query(By.directive(MdSlider)); | ||
sliderNativeElement = sliderDebugElement.nativeElement; | ||
sliderInstance = sliderDebugElement.componentInstance; | ||
|
||
sliderTrackElement = <HTMLElement>sliderNativeElement.querySelector('.md-slider-track'); | ||
sliderDimensions = sliderTrackElement.getBoundingClientRect(); | ||
|
||
thumbElement = <HTMLElement>sliderNativeElement.querySelector('.md-slider-thumb-position'); | ||
thumbDimensions = thumbElement.getBoundingClientRect(); | ||
}); | ||
|
||
it('should set the value smaller than the min value', () => { | ||
expect(sliderInstance.value).toBe(3); | ||
expect(sliderInstance.min).toBe(4); | ||
expect(sliderInstance.max).toBe(6); | ||
}); | ||
|
||
it('should place the thumb on the min value', () => { | ||
thumbDimensions = thumbElement.getBoundingClientRect(); | ||
expect(thumbDimensions.left).toBe(sliderDimensions.width * 0.0 + sliderDimensions.left); | ||
}); | ||
}); | ||
|
||
describe('slider with set min and max and a value greater than max', () => { | ||
let fixture: ComponentFixture<SliderWithValueSmallerThanMin>; | ||
let sliderDebugElement: DebugElement; | ||
let sliderNativeElement: HTMLElement; | ||
let sliderInstance: MdSlider; | ||
let sliderTrackElement: HTMLElement; | ||
let sliderDimensions: ClientRect; | ||
let thumbElement: HTMLElement; | ||
let thumbDimensions: ClientRect; | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(SliderWithValueGreaterThanMax); | ||
fixture.detectChanges(); | ||
|
||
sliderDebugElement = fixture.debugElement.query(By.directive(MdSlider)); | ||
sliderNativeElement = sliderDebugElement.nativeElement; | ||
sliderInstance = sliderDebugElement.componentInstance; | ||
|
||
sliderTrackElement = <HTMLElement>sliderNativeElement.querySelector('.md-slider-track'); | ||
sliderDimensions = sliderTrackElement.getBoundingClientRect(); | ||
|
||
thumbElement = <HTMLElement>sliderNativeElement.querySelector('.md-slider-thumb-position'); | ||
thumbDimensions = thumbElement.getBoundingClientRect(); | ||
|
||
}); | ||
|
||
it('should set the value greater than the max value', () => { | ||
expect(sliderInstance.value).toBe(7); | ||
expect(sliderInstance.min).toBe(4); | ||
expect(sliderInstance.max).toBe(6); | ||
}); | ||
|
||
it('should place the thumb on the max value', () => { | ||
thumbDimensions = thumbElement.getBoundingClientRect(); | ||
expect(thumbDimensions.left).toBe(sliderDimensions.width * 1.0 + sliderDimensions.left); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should be able to do expect(thumbDimensions.left).toBe(sliderDimensions.right); |
||
}); | ||
}); | ||
|
||
describe('slider with set min and max and a value between min and max', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This behavior is already captured by existing unit tests in the "slider with set min and max" section. |
||
let fixture: ComponentFixture<SliderWithValueBetweenMinAndMax>; | ||
let sliderDebugElement: DebugElement; | ||
let sliderInstance: MdSlider; | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(SliderWithValueBetweenMinAndMax); | ||
fixture.detectChanges(); | ||
|
||
sliderDebugElement = fixture.debugElement.query(By.directive(MdSlider)); | ||
sliderInstance = sliderDebugElement.injector.get(MdSlider); | ||
}); | ||
|
||
it('should set the value to the max value', () => { | ||
expect(sliderInstance.value).toBe(5); | ||
expect(sliderInstance.min).toBe(4); | ||
expect(sliderInstance.max).toBe(6); | ||
}); | ||
}); | ||
}); | ||
|
||
// The transition has to be removed in order to test the updated positions without setTimeout. | ||
|
@@ -678,6 +777,27 @@ class SliderWithTwoWayBinding { | |
control = new FormControl(''); | ||
} | ||
|
||
@Component({ | ||
template: `<md-slider value="3" min="4" max="6"></md-slider>`, | ||
styles: [noTransitionStyle], | ||
encapsulation: ViewEncapsulation.None | ||
}) | ||
class SliderWithValueSmallerThanMin { } | ||
|
||
@Component({ | ||
template: `<md-slider value="7" min="4" max="6"></md-slider>`, | ||
styles: [noTransitionStyle], | ||
encapsulation: ViewEncapsulation.None | ||
}) | ||
class SliderWithValueGreaterThanMax { } | ||
|
||
@Component({ | ||
template: `<md-slider value="5" min="4" max="6"></md-slider>`, | ||
styles: [noTransitionStyle], | ||
encapsulation: ViewEncapsulation.None | ||
}) | ||
class SliderWithValueBetweenMinAndMax { } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need this component any more. |
||
|
||
/** | ||
* Dispatches a click event from an element. | ||
* Note: The mouse event truncates the position for the click. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can just be