@@ -68,35 +68,39 @@ describe('MdSlider', () => {
6868 it ( 'should update the value on a click' , ( ) => {
6969 expect ( sliderInstance . value ) . toBe ( 0 ) ;
7070
71- dispatchClickEventSequence ( sliderTrackElement , sliderNativeElement , 0.19 ) ;
71+ dispatchClickEventSequence ( sliderNativeElement , 0.19 ) ;
72+
7273 expect ( sliderInstance . value ) . toBe ( 19 ) ;
7374 } ) ;
7475
7576 it ( 'should update the value on a slide' , ( ) => {
7677 expect ( sliderInstance . value ) . toBe ( 0 ) ;
7778
78- dispatchSlideEventSequence ( sliderTrackElement , sliderNativeElement , 0 , 0.89 , gestureConfig ) ;
79+ dispatchSlideEventSequence ( sliderNativeElement , 0 , 0.89 , gestureConfig ) ;
80+
7981 expect ( sliderInstance . value ) . toBe ( 89 ) ;
8082 } ) ;
8183
8284 it ( 'should set the value as min when sliding before the track' , ( ) => {
8385 expect ( sliderInstance . value ) . toBe ( 0 ) ;
8486
85- dispatchSlideEventSequence ( sliderTrackElement , sliderNativeElement , 0 , - 1.33 , gestureConfig ) ;
87+ dispatchSlideEventSequence ( sliderNativeElement , 0 , - 1.33 , gestureConfig ) ;
88+
8689 expect ( sliderInstance . value ) . toBe ( 0 ) ;
8790 } ) ;
8891
8992 it ( 'should set the value as max when sliding past the track' , ( ) => {
9093 expect ( sliderInstance . value ) . toBe ( 0 ) ;
9194
92- dispatchSlideEventSequence ( sliderTrackElement , sliderNativeElement , 0 , 1.75 , gestureConfig ) ;
95+ dispatchSlideEventSequence ( sliderNativeElement , 0 , 1.75 , gestureConfig ) ;
96+
9397 expect ( sliderInstance . value ) . toBe ( 100 ) ;
9498 } ) ;
9599
96100 it ( 'should update the track fill on click' , ( ) => {
97101 expect ( trackFillElement . style . flexBasis ) . toBe ( '0%' ) ;
98102
99- dispatchClickEventSequence ( sliderTrackElement , sliderNativeElement , 0.39 ) ;
103+ dispatchClickEventSequence ( sliderNativeElement , 0.39 ) ;
100104 fixture . detectChanges ( ) ;
101105
102106 expect ( trackFillElement . style . flexBasis ) . toBe ( '39%' ) ;
@@ -105,7 +109,7 @@ describe('MdSlider', () => {
105109 it ( 'should update the track fill on slide' , ( ) => {
106110 expect ( trackFillElement . style . flexBasis ) . toBe ( '0%' ) ;
107111
108- dispatchSlideEventSequence ( sliderTrackElement , sliderNativeElement , 0 , 0.86 , gestureConfig ) ;
112+ dispatchSlideEventSequence ( sliderNativeElement , 0 , 0.86 , gestureConfig ) ;
109113 fixture . detectChanges ( ) ;
110114
111115 expect ( trackFillElement . style . flexBasis ) . toBe ( '86%' ) ;
@@ -114,14 +118,14 @@ describe('MdSlider', () => {
114118 it ( 'should add the md-slider-active class on click' , ( ) => {
115119 expect ( sliderNativeElement . classList ) . not . toContain ( 'md-slider-active' ) ;
116120
117- dispatchClickEventSequence ( sliderTrackElement , sliderNativeElement , 0.23 ) ;
121+ dispatchClickEventSequence ( sliderNativeElement , 0.23 ) ;
118122 fixture . detectChanges ( ) ;
119123
120124 expect ( sliderNativeElement . classList ) . toContain ( 'md-slider-active' ) ;
121125 } ) ;
122126
123127 it ( 'should remove the md-slider-active class on blur' , ( ) => {
124- dispatchClickEventSequence ( sliderTrackElement , sliderNativeElement , 0.95 ) ;
128+ dispatchClickEventSequence ( sliderNativeElement , 0.95 ) ;
125129 fixture . detectChanges ( ) ;
126130
127131 expect ( sliderNativeElement . classList ) . toContain ( 'md-slider-active' ) ;
@@ -136,12 +140,12 @@ describe('MdSlider', () => {
136140 it ( 'should add and remove the md-slider-sliding class when sliding' , ( ) => {
137141 expect ( sliderNativeElement . classList ) . not . toContain ( 'md-slider-sliding' ) ;
138142
139- dispatchSlideStartEvent ( sliderTrackElement , sliderNativeElement , 0 , gestureConfig ) ;
143+ dispatchSlideStartEvent ( sliderNativeElement , 0 , gestureConfig ) ;
140144 fixture . detectChanges ( ) ;
141145
142146 expect ( sliderNativeElement . classList ) . toContain ( 'md-slider-sliding' ) ;
143147
144- dispatchSlideEndEvent ( sliderTrackElement , sliderNativeElement , 0.34 , gestureConfig ) ;
148+ dispatchSlideEndEvent ( sliderNativeElement , 0.34 , gestureConfig ) ;
145149 fixture . detectChanges ( ) ;
146150
147151 expect ( sliderNativeElement . classList ) . not . toContain ( 'md-slider-sliding' ) ;
@@ -172,23 +176,23 @@ describe('MdSlider', () => {
172176 it ( 'should not change the value on click when disabled' , ( ) => {
173177 expect ( sliderInstance . value ) . toBe ( 0 ) ;
174178
175- dispatchClickEventSequence ( sliderTrackElement , sliderNativeElement , 0.63 ) ;
179+ dispatchClickEventSequence ( sliderNativeElement , 0.63 ) ;
176180
177181 expect ( sliderInstance . value ) . toBe ( 0 ) ;
178182 } ) ;
179183
180184 it ( 'should not change the value on slide when disabled' , ( ) => {
181185 expect ( sliderInstance . value ) . toBe ( 0 ) ;
182186
183- dispatchSlideEventSequence ( sliderNativeElement , sliderNativeElement , 0 , 0.5 , gestureConfig ) ;
187+ dispatchSlideEventSequence ( sliderNativeElement , 0 , 0.5 , gestureConfig ) ;
184188
185189 expect ( sliderInstance . value ) . toBe ( 0 ) ;
186190 } ) ;
187191
188192 it ( 'should not add the md-slider-active class on click when disabled' , ( ) => {
189193 expect ( sliderNativeElement . classList ) . not . toContain ( 'md-slider-active' ) ;
190194
191- dispatchClickEventSequence ( sliderTrackElement , sliderNativeElement , 0.43 ) ;
195+ dispatchClickEventSequence ( sliderNativeElement , 0.43 ) ;
192196 fixture . detectChanges ( ) ;
193197
194198 expect ( sliderNativeElement . classList ) . not . toContain ( 'md-slider-active' ) ;
@@ -197,7 +201,7 @@ describe('MdSlider', () => {
197201 it ( 'should not add the md-slider-sliding class on slide when disabled' , ( ) => {
198202 expect ( sliderNativeElement . classList ) . not . toContain ( 'md-slider-sliding' ) ;
199203
200- dispatchSlideStartEvent ( sliderTrackElement , sliderNativeElement , 0.46 , gestureConfig ) ;
204+ dispatchSlideStartEvent ( sliderNativeElement , 0.46 , gestureConfig ) ;
201205 fixture . detectChanges ( ) ;
202206
203207 expect ( sliderNativeElement . classList ) . not . toContain ( 'md-slider-sliding' ) ;
@@ -237,7 +241,7 @@ describe('MdSlider', () => {
237241 } ) ;
238242
239243 it ( 'should set the correct value on click' , ( ) => {
240- dispatchClickEventSequence ( sliderTrackElement , sliderNativeElement , 0.09 ) ;
244+ dispatchClickEventSequence ( sliderNativeElement , 0.09 ) ;
241245 fixture . detectChanges ( ) ;
242246
243247 // Computed by multiplying the difference between the min and the max by the percentage from
@@ -247,7 +251,7 @@ describe('MdSlider', () => {
247251 } ) ;
248252
249253 it ( 'should set the correct value on slide' , ( ) => {
250- dispatchSlideEventSequence ( sliderTrackElement , sliderNativeElement , 0 , 0.62 , gestureConfig ) ;
254+ dispatchSlideEventSequence ( sliderNativeElement , 0 , 0.62 , gestureConfig ) ;
251255 fixture . detectChanges ( ) ;
252256
253257 // Computed by multiplying the difference between the min and the max by the percentage from
@@ -257,15 +261,15 @@ describe('MdSlider', () => {
257261 } ) ;
258262
259263 it ( 'should snap the fill to the nearest value on click' , ( ) => {
260- dispatchClickEventSequence ( sliderTrackElement , sliderNativeElement , 0.68 ) ;
264+ dispatchClickEventSequence ( sliderNativeElement , 0.68 ) ;
261265 fixture . detectChanges ( ) ;
262266
263267 // The closest snap is halfway on the slider.
264268 expect ( trackFillElement . style . flexBasis ) . toBe ( '50%' ) ;
265269 } ) ;
266270
267271 it ( 'should snap the fill to the nearest value on slide' , ( ) => {
268- dispatchSlideEventSequence ( sliderTrackElement , sliderNativeElement , 0 , 0.74 , gestureConfig ) ;
272+ dispatchSlideEventSequence ( sliderNativeElement , 0 , 0.74 , gestureConfig ) ;
269273 fixture . detectChanges ( ) ;
270274
271275 // The closest snap is at the halfway point on the slider.
@@ -326,7 +330,7 @@ describe('MdSlider', () => {
326330 } ) ;
327331
328332 it ( 'should set the correct value on click' , ( ) => {
329- dispatchClickEventSequence ( sliderTrackElement , sliderNativeElement , 0.92 ) ;
333+ dispatchClickEventSequence ( sliderNativeElement , 0.92 ) ;
330334 fixture . detectChanges ( ) ;
331335
332336 // On a slider with default max and min the value should be approximately equal to the
@@ -335,7 +339,7 @@ describe('MdSlider', () => {
335339 } ) ;
336340
337341 it ( 'should set the correct value on slide' , ( ) => {
338- dispatchSlideEventSequence ( sliderTrackElement , sliderNativeElement , 0 , 0.32 , gestureConfig ) ;
342+ dispatchSlideEventSequence ( sliderNativeElement , 0 , 0.32 , gestureConfig ) ;
339343 fixture . detectChanges ( ) ;
340344
341345 expect ( sliderInstance . value ) . toBe ( 32 ) ;
@@ -364,29 +368,29 @@ describe('MdSlider', () => {
364368 it ( 'should set the correct step value on click' , ( ) => {
365369 expect ( sliderInstance . value ) . toBe ( 0 ) ;
366370
367- dispatchClickEventSequence ( sliderTrackElement , sliderNativeElement , 0.13 ) ;
371+ dispatchClickEventSequence ( sliderNativeElement , 0.13 ) ;
368372 fixture . detectChanges ( ) ;
369373
370374 expect ( sliderInstance . value ) . toBe ( 25 ) ;
371375 } ) ;
372376
373377 it ( 'should snap the fill to a step on click' , ( ) => {
374- dispatchClickEventSequence ( sliderTrackElement , sliderNativeElement , 0.66 ) ;
378+ dispatchClickEventSequence ( sliderNativeElement , 0.66 ) ;
375379 fixture . detectChanges ( ) ;
376380
377381 // The closest step is at 75% of the slider.
378382 expect ( trackFillElement . style . flexBasis ) . toBe ( '75%' ) ;
379383 } ) ;
380384
381385 it ( 'should set the correct step value on slide' , ( ) => {
382- dispatchSlideEventSequence ( sliderTrackElement , sliderNativeElement , 0 , 0.07 , gestureConfig ) ;
386+ dispatchSlideEventSequence ( sliderNativeElement , 0 , 0.07 , gestureConfig ) ;
383387 fixture . detectChanges ( ) ;
384388
385389 expect ( sliderInstance . value ) . toBe ( 0 ) ;
386390 } ) ;
387391
388392 it ( 'should snap the thumb and fill to a step on slide' , ( ) => {
389- dispatchSlideEventSequence ( sliderTrackElement , sliderNativeElement , 0 , 0.88 , gestureConfig ) ;
393+ dispatchSlideEventSequence ( sliderNativeElement , 0 , 0.88 , gestureConfig ) ;
390394 fixture . detectChanges ( ) ;
391395
392396 // The closest snap is at the end of the slider.
@@ -481,7 +485,7 @@ describe('MdSlider', () => {
481485 it ( 'should update the thumb label text on click' , ( ) => {
482486 expect ( thumbLabelTextElement . textContent ) . toBe ( '0' ) ;
483487
484- dispatchClickEventSequence ( sliderTrackElement , sliderNativeElement , 0.13 ) ;
488+ dispatchClickEventSequence ( sliderNativeElement , 0.13 ) ;
485489 fixture . detectChanges ( ) ;
486490
487491 // The thumb label text is set to the slider's value. These should always be the same.
@@ -491,7 +495,7 @@ describe('MdSlider', () => {
491495 it ( 'should update the thumb label text on slide' , ( ) => {
492496 expect ( thumbLabelTextElement . textContent ) . toBe ( '0' ) ;
493497
494- dispatchSlideEventSequence ( sliderTrackElement , sliderNativeElement , 0 , 0.56 , gestureConfig ) ;
498+ dispatchSlideEventSequence ( sliderNativeElement , 0 , 0.56 , gestureConfig ) ;
495499 fixture . detectChanges ( ) ;
496500
497501 // The thumb label text is set to the slider's value. These should always be the same.
@@ -502,7 +506,7 @@ describe('MdSlider', () => {
502506 expect ( sliderNativeElement . classList ) . not . toContain ( 'md-slider-active' ) ;
503507 expect ( sliderNativeElement . classList ) . toContain ( 'md-slider-thumb-label-showing' ) ;
504508
505- dispatchClickEventSequence ( sliderTrackElement , sliderNativeElement , 0.49 ) ;
509+ dispatchClickEventSequence ( sliderNativeElement , 0.49 ) ;
506510 fixture . detectChanges ( ) ;
507511
508512 // The thumb label appears when the slider is active and the 'md-slider-thumb-label-showing'
@@ -514,7 +518,7 @@ describe('MdSlider', () => {
514518 it ( 'should show the thumb label on slide' , ( ) => {
515519 expect ( sliderNativeElement . classList ) . not . toContain ( 'md-slider-active' ) ;
516520
517- dispatchSlideEventSequence ( sliderTrackElement , sliderNativeElement , 0 , 0.91 , gestureConfig ) ;
521+ dispatchSlideEventSequence ( sliderNativeElement , 0 , 0.91 , gestureConfig ) ;
518522 fixture . detectChanges ( ) ;
519523
520524 expect ( sliderNativeElement . classList ) . toContain ( 'md-slider-thumb-label-showing' ) ;
@@ -554,7 +558,7 @@ describe('MdSlider', () => {
554558 it ( 'should update the control on click' , ( ) => {
555559 expect ( testComponent . control . value ) . toBe ( 0 ) ;
556560
557- dispatchClickEventSequence ( sliderTrackElement , sliderNativeElement , 0.76 ) ;
561+ dispatchClickEventSequence ( sliderNativeElement , 0.76 ) ;
558562 fixture . detectChanges ( ) ;
559563
560564 expect ( testComponent . control . value ) . toBe ( 76 ) ;
@@ -563,7 +567,7 @@ describe('MdSlider', () => {
563567 it ( 'should update the control on slide' , ( ) => {
564568 expect ( testComponent . control . value ) . toBe ( 0 ) ;
565569
566- dispatchSlideEventSequence ( sliderTrackElement , sliderNativeElement , 0 , 0.19 , gestureConfig ) ;
570+ dispatchSlideEventSequence ( sliderNativeElement , 0 , 0.19 , gestureConfig ) ;
567571 fixture . detectChanges ( ) ;
568572
569573 expect ( testComponent . control . value ) . toBe ( 19 ) ;
@@ -839,95 +843,91 @@ class SliderWithChangeHandler {
839843}
840844
841845/**
842- * Dispatches a click event sequence (consisting of moueseenter, click) from an element.
846+ * Dispatches a click event from an element.
843847 * Note: The mouse event truncates the position for the click.
844- * @param trackElement The track element from which the event location will be calculated.
845- * @param containerElement The container element from which the event will be dispatched.
848+ * @param sliderElement The md-slider element from which the event will be dispatched.
846849 * @param percentage The percentage of the slider where the click should occur. Used to find the
847850 * physical location of the click.
848851 */
849- function dispatchClickEventSequence ( trackElement : HTMLElement , containerElement : HTMLElement ,
850- percentage : number ) : void {
852+ function dispatchClickEventSequence ( sliderElement : HTMLElement , percentage : number ) : void {
853+ let trackElement = sliderElement . querySelector ( '.md-slider-track' ) ;
851854 let dimensions = trackElement . getBoundingClientRect ( ) ;
852855 let y = dimensions . top ;
853856 let x = dimensions . left + ( dimensions . width * percentage ) ;
854857
855- dispatchMouseenterEvent ( containerElement ) ;
858+ dispatchMouseenterEvent ( sliderElement ) ;
856859
857860 let event = document . createEvent ( 'MouseEvent' ) ;
858861 event . initMouseEvent (
859862 'click' , true , true , window , 0 , x , y , x , y , false , false , false , false , 0 , null ) ;
860- containerElement . dispatchEvent ( event ) ;
863+ sliderElement . dispatchEvent ( event ) ;
861864}
862865
863866/**
864867 * Dispatches a slide event sequence (consisting of slidestart, slide, slideend) from an element.
865- * @param trackElement The track element from which the event location will be calculated.
866- * @param containerElement The container element from which the event will be dispatched.
868+ * @param sliderElement The md-slider element from which the event will be dispatched.
867869 * @param startPercent The percentage of the slider where the slide will begin.
868870 * @param endPercent The percentage of the slider where the slide will end.
869871 * @param gestureConfig The gesture config for the test to handle emitting the slide events.
870872 */
871- function dispatchSlideEventSequence ( trackElement : HTMLElement , containerElement : HTMLElement ,
872- startPercent : number , endPercent : number ,
873- gestureConfig : TestGestureConfig ) : void {
874- dispatchSlideStartEvent ( trackElement , containerElement , startPercent , gestureConfig ) ;
875- dispatchSlideEvent ( trackElement , containerElement , startPercent , gestureConfig ) ;
876- dispatchSlideEvent ( trackElement , containerElement , endPercent , gestureConfig ) ;
877- dispatchSlideEndEvent ( trackElement , containerElement , endPercent , gestureConfig ) ;
873+ function dispatchSlideEventSequence ( sliderElement : HTMLElement , startPercent : number ,
874+ endPercent : number , gestureConfig : TestGestureConfig ) : void {
875+ dispatchMouseenterEvent ( sliderElement ) ;
876+ dispatchSlideStartEvent ( sliderElement , startPercent , gestureConfig ) ;
877+ dispatchSlideEvent ( sliderElement , startPercent , gestureConfig ) ;
878+ dispatchSlideEvent ( sliderElement , endPercent , gestureConfig ) ;
879+ dispatchSlideEndEvent ( sliderElement , endPercent , gestureConfig ) ;
878880}
879881
880882/**
881883 * Dispatches a slide event from an element.
882- * @param trackElement The track element from which the event location will be calculated.
883- * @param containerElement The container element from which the event will be dispatched.
884+ * @param sliderElement The md-slider element from which the event will be dispatched.
884885 * @param percent The percentage of the slider where the slide will happen.
885886 * @param gestureConfig The gesture config for the test to handle emitting the slide events.
886887 */
887- function dispatchSlideEvent ( trackElement : HTMLElement , containerElement : HTMLElement ,
888- percent : number , gestureConfig : TestGestureConfig ) : void {
888+ function dispatchSlideEvent ( sliderElement : HTMLElement , percent : number ,
889+ gestureConfig : TestGestureConfig ) : void {
890+ let trackElement = sliderElement . querySelector ( '.md-slider-track' ) ;
889891 let dimensions = trackElement . getBoundingClientRect ( ) ;
890892 let x = dimensions . left + ( dimensions . width * percent ) ;
891893
892- gestureConfig . emitEventForElement ( 'slide' , containerElement , {
894+ gestureConfig . emitEventForElement ( 'slide' , sliderElement , {
893895 center : { x : x } ,
894896 srcEvent : { preventDefault : jasmine . createSpy ( 'preventDefault' ) }
895897 } ) ;
896898}
897899
898900/**
899901 * Dispatches a slidestart event from an element.
900- * @param trackElement The track element from which the event location will be calculated.
901- * @param containerElement The container element from which the event will be dispatched.
902+ * @param sliderElement The md-slider element from which the event will be dispatched.
902903 * @param percent The percentage of the slider where the slide will begin.
903904 * @param gestureConfig The gesture config for the test to handle emitting the slide events.
904905 */
905- function dispatchSlideStartEvent ( trackElement : HTMLElement , containerElement : HTMLElement ,
906- percent : number , gestureConfig : TestGestureConfig ) : void {
906+ function dispatchSlideStartEvent ( sliderElement : HTMLElement , percent : number ,
907+ gestureConfig : TestGestureConfig ) : void {
908+ let trackElement = sliderElement . querySelector ( '.md-slider-track' ) ;
907909 let dimensions = trackElement . getBoundingClientRect ( ) ;
908910 let x = dimensions . left + ( dimensions . width * percent ) ;
909911
910- dispatchMouseenterEvent ( containerElement ) ;
911-
912- gestureConfig . emitEventForElement ( 'slidestart' , containerElement , {
912+ gestureConfig . emitEventForElement ( 'slidestart' , sliderElement , {
913913 center : { x : x } ,
914914 srcEvent : { preventDefault : jasmine . createSpy ( 'preventDefault' ) }
915915 } ) ;
916916}
917917
918918/**
919919 * Dispatches a slideend event from an element.
920- * @param trackElement The track element from which the event location will be calculated.
921- * @param containerElement The container element from which the event will be dispatched.
920+ * @param sliderElement The md-slider element from which the event will be dispatched.
922921 * @param percent The percentage of the slider where the slide will end.
923922 * @param gestureConfig The gesture config for the test to handle emitting the slide events.
924923 */
925- function dispatchSlideEndEvent ( trackElement : HTMLElement , containerElement : HTMLElement ,
926- percent : number , gestureConfig : TestGestureConfig ) : void {
924+ function dispatchSlideEndEvent ( sliderElement : HTMLElement , percent : number ,
925+ gestureConfig : TestGestureConfig ) : void {
926+ let trackElement = sliderElement . querySelector ( '.md-slider-track' ) ;
927927 let dimensions = trackElement . getBoundingClientRect ( ) ;
928928 let x = dimensions . left + ( dimensions . width * percent ) ;
929929
930- gestureConfig . emitEventForElement ( 'slideend' , containerElement , {
930+ gestureConfig . emitEventForElement ( 'slideend' , sliderElement , {
931931 center : { x : x } ,
932932 srcEvent : { preventDefault : jasmine . createSpy ( 'preventDefault' ) }
933933 } ) ;
@@ -951,4 +951,3 @@ function dispatchMouseenterEvent(element: HTMLElement): void {
951951 'mouseenter' , true , true , window , 0 , x , y , x , y , false , false , false , false , 0 , null ) ;
952952 element . dispatchEvent ( event ) ;
953953}
954-
0 commit comments