@@ -26,7 +26,8 @@ describe('MdSlider', () => {
2626 SliderWithValue ,
2727 SliderWithStep ,
2828 SliderWithAutoTickInterval ,
29- SliderWithSetTickInterval
29+ SliderWithSetTickInterval ,
30+ SliderWithThumbLabel ,
3031 ] ,
3132 } ) ;
3233
@@ -118,7 +119,7 @@ describe('MdSlider', () => {
118119 // offset relative to the track, subtract the offset on the track fill.
119120 let thumbPosition = thumbDimensions . left - trackFillDimensions . left ;
120121 // 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 ) ;
122123 } ) ;
123124
124125 it ( 'should update the thumb position on click' , ( ) => {
@@ -144,7 +145,7 @@ describe('MdSlider', () => {
144145 // offset relative to the track, subtract the offset on the track fill.
145146 let thumbPosition = thumbDimensions . left - trackFillDimensions . left ;
146147 // 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 ) ;
148149 } ) ;
149150
150151 it ( 'should update the thumb position on slide' , ( ) => {
@@ -309,7 +310,7 @@ describe('MdSlider', () => {
309310
310311 // The closest snap is halfway on the slider.
311312 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 ) ;
313314 } ) ;
314315
315316 it ( 'should snap the thumb and fill to the nearest value on slide' , ( ) => {
@@ -325,7 +326,7 @@ describe('MdSlider', () => {
325326
326327 // The closest snap is at the halfway point on the slider.
327328 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 ) ;
329330
330331 } ) ;
331332 } ) ;
@@ -410,7 +411,7 @@ describe('MdSlider', () => {
410411
411412 // The closest step is at 75% of the slider.
412413 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 ) ;
414415 } ) ;
415416
416417 it ( 'should set the correct step value on slide' , ( ) => {
@@ -433,7 +434,7 @@ describe('MdSlider', () => {
433434
434435 // The closest snap is at the end of the slider.
435436 expect ( thumbDimensions . left ) . toBe ( sliderDimensions . width + sliderDimensions . left ) ;
436- expect ( Math . round ( trackFillDimensions . width ) ) . toBe ( Math . round ( thumbPosition ) ) ;
437+ expect ( trackFillDimensions . width ) . toBe ( thumbPosition ) ;
437438 } ) ;
438439 } ) ;
439440
@@ -516,6 +517,77 @@ describe('MdSlider', () => {
516517 + 'black 2px, transparent 2px, transparent)' ) ;
517518 } ) ;
518519 } ) ;
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+ } ) ;
519591} ) ;
520592
521593// The transition has to be removed in order to test the updated positions without setTimeout.
@@ -572,6 +644,17 @@ class SliderWithAutoTickInterval { }
572644} )
573645class SliderWithSetTickInterval { }
574646
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+
575658/**
576659 * Dispatches a click event from an element.
577660 * Note: The mouse event truncates the position for the click.
0 commit comments