@@ -37,15 +37,13 @@ describe('MDC-based MatSlider' , () => {
37
37
}
38
38
39
39
describe ( 'standard slider' , ( ) => {
40
- let fixture : ComponentFixture < StandardSlider > ;
41
- let sliderDebugElement : DebugElement ;
42
40
let sliderInstance : MatSlider ;
43
41
let inputInstance : MatSliderThumb ;
44
42
45
43
beforeEach ( waitForAsync ( ( ) => {
46
- fixture = createComponent ( StandardSlider ) ;
44
+ const fixture = createComponent ( StandardSlider ) ;
47
45
fixture . detectChanges ( ) ;
48
- sliderDebugElement = fixture . debugElement . query ( By . directive ( MatSlider ) ) ;
46
+ const sliderDebugElement = fixture . debugElement . query ( By . directive ( MatSlider ) ) ;
49
47
sliderInstance = sliderDebugElement . componentInstance ;
50
48
inputInstance = sliderInstance . _getInput ( Thumb . END ) ;
51
49
} ) ) ;
@@ -364,6 +362,101 @@ describe('MDC-based MatSlider' , () => {
364
362
expect ( isRippleVisible ( 'focus' ) ) . toBeFalse ( ) ;
365
363
} ) ) ;
366
364
} ) ;
365
+
366
+ describe ( 'slider with set min and max' , ( ) => {
367
+ let fixture : ComponentFixture < SliderWithMinAndMax > ;
368
+ let sliderInstance : MatSlider ;
369
+ let inputInstance : MatSliderThumb ;
370
+
371
+ beforeEach ( waitForAsync ( ( ) => {
372
+ fixture = createComponent ( SliderWithMinAndMax ) ;
373
+ fixture . detectChanges ( ) ;
374
+ const sliderDebugElement = fixture . debugElement . query ( By . directive ( MatSlider ) ) ;
375
+ sliderInstance = sliderDebugElement . componentInstance ;
376
+ inputInstance = sliderInstance . _getInput ( Thumb . END ) ;
377
+ } ) ) ;
378
+
379
+ it ( 'should set the default values from the attributes' , ( ) => {
380
+ expect ( inputInstance . value ) . toBe ( 25 ) ;
381
+ expect ( sliderInstance . min ) . toBe ( 25 ) ;
382
+ expect ( sliderInstance . max ) . toBe ( 75 ) ;
383
+ } ) ;
384
+
385
+ it ( 'should set the correct value on mousedown' , ( ) => {
386
+ setValueByClick ( sliderInstance , 33 , platform . IOS ) ;
387
+ expect ( inputInstance . value ) . toBe ( 33 ) ;
388
+ } ) ;
389
+
390
+ it ( 'should set the correct value on slide' , ( ) => {
391
+ slideToValue ( sliderInstance , 55 , Thumb . END , platform . IOS ) ;
392
+ expect ( inputInstance . value ) . toBe ( 55 ) ;
393
+ } ) ;
394
+
395
+ it ( 'should be able to set the min and max values when they are more precise ' +
396
+ 'than the step' , ( ) => {
397
+ sliderInstance . step = 10 ;
398
+ fixture . detectChanges ( ) ;
399
+ slideToValue ( sliderInstance , 25 , Thumb . END , platform . IOS ) ;
400
+ expect ( inputInstance . value ) . toBe ( 25 ) ;
401
+ slideToValue ( sliderInstance , 75 , Thumb . END , platform . IOS ) ;
402
+ expect ( inputInstance . value ) . toBe ( 75 ) ;
403
+ } ) ;
404
+ } ) ;
405
+
406
+ describe ( 'range slider with set min and max' , ( ) => {
407
+ let fixture : ComponentFixture < RangeSliderWithMinAndMax > ;
408
+ let sliderInstance : MatSlider ;
409
+ let startInputInstance : MatSliderThumb ;
410
+ let endInputInstance : MatSliderThumb ;
411
+
412
+ beforeEach ( waitForAsync ( ( ) => {
413
+ fixture = createComponent ( RangeSliderWithMinAndMax ) ;
414
+ fixture . detectChanges ( ) ;
415
+ const sliderDebugElement = fixture . debugElement . query ( By . directive ( MatSlider ) ) ;
416
+ sliderInstance = sliderDebugElement . componentInstance ;
417
+ startInputInstance = sliderInstance . _getInput ( Thumb . START ) ;
418
+ endInputInstance = sliderInstance . _getInput ( Thumb . END ) ;
419
+ } ) ) ;
420
+
421
+ it ( 'should set the default values from the attributes' , ( ) => {
422
+ expect ( startInputInstance . value ) . toBe ( 25 ) ;
423
+ expect ( endInputInstance . value ) . toBe ( 75 ) ;
424
+ expect ( sliderInstance . min ) . toBe ( 25 ) ;
425
+ expect ( sliderInstance . max ) . toBe ( 75 ) ;
426
+ } ) ;
427
+
428
+ it ( 'should set the correct start value on mousedown behind the start thumb' , ( ) => {
429
+ sliderInstance . _setValue ( 50 , Thumb . START ) ;
430
+ setValueByClick ( sliderInstance , 33 , platform . IOS ) ;
431
+ expect ( startInputInstance . value ) . toBe ( 33 ) ;
432
+ } ) ;
433
+
434
+ it ( 'should set the correct end value on mousedown behind the end thumb' , ( ) => {
435
+ sliderInstance . _setValue ( 50 , Thumb . END ) ;
436
+ setValueByClick ( sliderInstance , 66 , platform . IOS ) ;
437
+ expect ( endInputInstance . value ) . toBe ( 66 ) ;
438
+ } ) ;
439
+
440
+ it ( 'should set the correct start value on slide' , ( ) => {
441
+ slideToValue ( sliderInstance , 40 , Thumb . START , platform . IOS ) ;
442
+ expect ( startInputInstance . value ) . toBe ( 40 ) ;
443
+ } ) ;
444
+
445
+ it ( 'should set the correct end value on slide' , ( ) => {
446
+ slideToValue ( sliderInstance , 60 , Thumb . END , platform . IOS ) ;
447
+ expect ( endInputInstance . value ) . toBe ( 60 ) ;
448
+ } ) ;
449
+
450
+ it ( 'should be able to set the min and max values when they are more precise ' +
451
+ 'than the step' , ( ) => {
452
+ sliderInstance . step = 10 ;
453
+ fixture . detectChanges ( ) ;
454
+ slideToValue ( sliderInstance , 25 , Thumb . START , platform . IOS ) ;
455
+ expect ( startInputInstance . value ) . toBe ( 25 ) ;
456
+ slideToValue ( sliderInstance , 75 , Thumb . END , platform . IOS ) ;
457
+ expect ( endInputInstance . value ) . toBe ( 75 ) ;
458
+ } ) ;
459
+ } ) ;
367
460
} ) ;
368
461
369
462
@@ -405,6 +498,25 @@ class DisabledSlider {}
405
498
} )
406
499
class DisabledRangeSlider { }
407
500
501
+ @Component ( {
502
+ template : `
503
+ <mat-slider min="25" max="75">
504
+ <input matSliderThumb>
505
+ </mat-slider>
506
+ ` ,
507
+ } )
508
+ class SliderWithMinAndMax { }
509
+
510
+ @Component ( {
511
+ template : `
512
+ <mat-slider min="25" max="75">
513
+ <input matSliderStartThumb>
514
+ <input matSliderEndThumb>
515
+ </mat-slider>
516
+ ` ,
517
+ } )
518
+ class RangeSliderWithMinAndMax { }
519
+
408
520
/** The pointer event types used by the MDC Slider. */
409
521
const enum PointerEventType {
410
522
POINTER_DOWN = 'pointerdown' ,
@@ -442,7 +554,7 @@ function slideToValue(slider: MatSlider, value: number, thumbPosition: Thumb, is
442
554
const thumbElement = slider . _getThumbElement ( thumbPosition ) ;
443
555
444
556
const sliderDimensions = sliderElement . getBoundingClientRect ( ) ;
445
- let thumbDimensions = thumbElement . getBoundingClientRect ( ) ;
557
+ const thumbDimensions = thumbElement . getBoundingClientRect ( ) ;
446
558
447
559
const startX = thumbDimensions . left + ( thumbDimensions . width / 2 ) ;
448
560
const startY = thumbDimensions . top + ( thumbDimensions . height / 2 ) ;
0 commit comments