@@ -26,7 +26,8 @@ describe('MdSlider', () => {
26
26
SliderWithValue ,
27
27
SliderWithStep ,
28
28
SliderWithAutoTickInterval ,
29
- SliderWithSetTickInterval
29
+ SliderWithSetTickInterval ,
30
+ SliderWithThumbLabel ,
30
31
] ,
31
32
} ) ;
32
33
@@ -118,7 +119,7 @@ describe('MdSlider', () => {
118
119
// offset relative to the track, subtract the offset on the track fill.
119
120
let thumbPosition = thumbDimensions . left - trackFillDimensions . left ;
120
121
// The track fill width should be equal to the thumb's position.
121
- expect ( Math . round ( trackFillDimensions . width ) ) . toBe ( Math . round ( thumbPosition ) ) ;
122
+ expect ( trackFillDimensions . width ) . toBe ( thumbPosition ) ;
122
123
} ) ;
123
124
124
125
it ( 'should update the thumb position on click' , ( ) => {
@@ -144,7 +145,7 @@ describe('MdSlider', () => {
144
145
// offset relative to the track, subtract the offset on the track fill.
145
146
let thumbPosition = thumbDimensions . left - trackFillDimensions . left ;
146
147
// The track fill width should be equal to the thumb's position.
147
- expect ( Math . round ( trackFillDimensions . width ) ) . toBe ( Math . round ( thumbPosition ) ) ;
148
+ expect ( trackFillDimensions . width ) . toBe ( thumbPosition ) ;
148
149
} ) ;
149
150
150
151
it ( 'should update the thumb position on slide' , ( ) => {
@@ -309,7 +310,7 @@ describe('MdSlider', () => {
309
310
310
311
// The closest snap is halfway on the slider.
311
312
expect ( thumbDimensions . left ) . toBe ( sliderDimensions . width * 0.5 + sliderDimensions . left ) ;
312
- expect ( Math . round ( trackFillDimensions . width ) ) . toBe ( Math . round ( thumbPosition ) ) ;
313
+ expect ( trackFillDimensions . width ) . toBe ( thumbPosition ) ;
313
314
} ) ;
314
315
315
316
it ( 'should snap the thumb and fill to the nearest value on slide' , ( ) => {
@@ -325,7 +326,7 @@ describe('MdSlider', () => {
325
326
326
327
// The closest snap is at the halfway point on the slider.
327
328
expect ( thumbDimensions . left ) . toBe ( sliderDimensions . left + sliderDimensions . width * 0.5 ) ;
328
- expect ( Math . round ( trackFillDimensions . width ) ) . toBe ( Math . round ( thumbPosition ) ) ;
329
+ expect ( trackFillDimensions . width ) . toBe ( thumbPosition ) ;
329
330
330
331
} ) ;
331
332
} ) ;
@@ -410,7 +411,7 @@ describe('MdSlider', () => {
410
411
411
412
// The closest step is at 75% of the slider.
412
413
expect ( thumbDimensions . left ) . toBe ( sliderDimensions . width * 0.75 + sliderDimensions . left ) ;
413
- expect ( Math . round ( trackFillDimensions . width ) ) . toBe ( Math . round ( thumbPosition ) ) ;
414
+ expect ( trackFillDimensions . width ) . toBe ( thumbPosition ) ;
414
415
} ) ;
415
416
416
417
it ( 'should set the correct step value on slide' , ( ) => {
@@ -433,7 +434,7 @@ describe('MdSlider', () => {
433
434
434
435
// The closest snap is at the end of the slider.
435
436
expect ( thumbDimensions . left ) . toBe ( sliderDimensions . width + sliderDimensions . left ) ;
436
- expect ( Math . round ( trackFillDimensions . width ) ) . toBe ( Math . round ( thumbPosition ) ) ;
437
+ expect ( trackFillDimensions . width ) . toBe ( thumbPosition ) ;
437
438
} ) ;
438
439
} ) ;
439
440
@@ -516,6 +517,77 @@ describe('MdSlider', () => {
516
517
+ 'black 2px, transparent 2px, transparent)' ) ;
517
518
} ) ;
518
519
} ) ;
520
+
521
+ describe ( 'slider with thumb label' , ( ) => {
522
+ let fixture : ComponentFixture < SliderWithThumbLabel > ;
523
+ let sliderDebugElement : DebugElement ;
524
+ let sliderNativeElement : HTMLElement ;
525
+ let sliderInstance : MdSlider ;
526
+ let sliderTrackElement : HTMLElement ;
527
+ let sliderContainerElement : Element ;
528
+ let thumbLabelTextElement : Element ;
529
+
530
+ beforeEach ( async ( ( ) => {
531
+ builder . createAsync ( SliderWithThumbLabel ) . then ( f => {
532
+ fixture = f ;
533
+ fixture . detectChanges ( ) ;
534
+
535
+ sliderDebugElement = fixture . debugElement . query ( By . directive ( MdSlider ) ) ;
536
+ sliderNativeElement = sliderDebugElement . nativeElement ;
537
+ sliderInstance = sliderDebugElement . componentInstance ;
538
+ sliderTrackElement = < HTMLElement > sliderNativeElement . querySelector ( '.md-slider-track' ) ;
539
+ sliderContainerElement = sliderNativeElement . querySelector ( '.md-slider-container' ) ;
540
+ thumbLabelTextElement = sliderNativeElement . querySelector ( '.md-slider-thumb-label-text' ) ;
541
+ } ) ;
542
+ } ) ) ;
543
+
544
+ it ( 'should add the thumb label class to the slider container' , ( ) => {
545
+ expect ( sliderContainerElement . classList ) . toContain ( 'md-slider-thumb-label-showing' ) ;
546
+ } ) ;
547
+
548
+ it ( 'should update the thumb label text on click' , ( ) => {
549
+ expect ( thumbLabelTextElement . textContent ) . toBe ( '0' ) ;
550
+
551
+ dispatchClickEvent ( sliderTrackElement , 0.13 ) ;
552
+ fixture . detectChanges ( ) ;
553
+
554
+ // The thumb label text is set to the slider's value. These should always be the same.
555
+ expect ( thumbLabelTextElement . textContent ) . toBe ( '13' ) ;
556
+ } ) ;
557
+
558
+ it ( 'should update the thumb label text on slide' , ( ) => {
559
+ expect ( thumbLabelTextElement . textContent ) . toBe ( '0' ) ;
560
+
561
+ dispatchSlideEvent ( sliderTrackElement , sliderNativeElement , 0 , 0.56 , gestureConfig ) ;
562
+ fixture . detectChanges ( ) ;
563
+
564
+ // The thumb label text is set to the slider's value. These should always be the same.
565
+ expect ( thumbLabelTextElement . textContent ) . toBe ( `${ sliderInstance . value } ` ) ;
566
+ } ) ;
567
+
568
+ it ( 'should show the thumb label on click' , ( ) => {
569
+ expect ( sliderContainerElement . classList ) . not . toContain ( 'md-slider-active' ) ;
570
+ expect ( sliderContainerElement . classList ) . toContain ( 'md-slider-thumb-label-showing' ) ;
571
+
572
+ dispatchClickEvent ( sliderNativeElement , 0.49 ) ;
573
+ fixture . detectChanges ( ) ;
574
+
575
+ // The thumb label appears when the slider is active and the 'md-slider-thumb-label-showing'
576
+ // class is applied.
577
+ expect ( sliderContainerElement . classList ) . toContain ( 'md-slider-thumb-label-showing' ) ;
578
+ expect ( sliderContainerElement . classList ) . toContain ( 'md-slider-active' ) ;
579
+ } ) ;
580
+
581
+ it ( 'should show the thumb label on slide' , ( ) => {
582
+ expect ( sliderContainerElement . classList ) . not . toContain ( 'md-slider-active' ) ;
583
+
584
+ dispatchSlideEvent ( sliderTrackElement , sliderNativeElement , 0 , 0.91 , gestureConfig ) ;
585
+ fixture . detectChanges ( ) ;
586
+
587
+ expect ( sliderContainerElement . classList ) . toContain ( 'md-slider-thumb-label-showing' ) ;
588
+ expect ( sliderContainerElement . classList ) . toContain ( 'md-slider-active' ) ;
589
+ } ) ;
590
+ } ) ;
519
591
} ) ;
520
592
521
593
// The transition has to be removed in order to test the updated positions without setTimeout.
@@ -572,6 +644,17 @@ class SliderWithAutoTickInterval { }
572
644
} )
573
645
class SliderWithSetTickInterval { }
574
646
647
+ @Component ( {
648
+ template : `<md-slider thumb-label></md-slider>` ,
649
+ styles : [ `
650
+ .md-slider-thumb-label, .md-slider-thumb-label-text {
651
+ transition: none !important;
652
+ }
653
+ ` ] ,
654
+ encapsulation : ViewEncapsulation . None
655
+ } )
656
+ class SliderWithThumbLabel { }
657
+
575
658
/**
576
659
* Dispatches a click event from an element.
577
660
* Note: The mouse event truncates the position for the click.
0 commit comments