6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
9
- import { LEFT_ARROW , RIGHT_ARROW } from '@angular/cdk/keycodes' ;
10
9
import { Platform } from '@angular/cdk/platform' ;
11
10
import {
12
- dispatchFakeEvent ,
13
11
dispatchMouseEvent ,
14
12
dispatchPointerEvent ,
15
13
dispatchTouchEvent ,
@@ -524,11 +522,12 @@ describe('MDC-based MatSlider' , () => {
524
522
} ) ;
525
523
526
524
describe ( 'slider with set step' , ( ) => {
525
+ let fixture : ComponentFixture < SliderWithStep > ;
527
526
let sliderInstance : MatSlider ;
528
527
let inputInstance : MatSliderThumb ;
529
528
530
529
beforeEach ( waitForAsync ( ( ) => {
531
- const fixture = createComponent ( SliderWithStep ) ;
530
+ fixture = createComponent ( SliderWithStep ) ;
532
531
fixture . detectChanges ( ) ;
533
532
const sliderDebugElement = fixture . debugElement . query ( By . directive ( MatSlider ) ) ;
534
533
sliderInstance = sliderDebugElement . componentInstance ;
@@ -553,28 +552,20 @@ describe('MDC-based MatSlider' , () => {
553
552
} ) ;
554
553
555
554
it ( 'should truncate long decimal values when using a decimal step' , ( ) => {
556
- // TODO(wagnermaciel): Uncomment this test once b/182504575 is resolved.
557
- // sliderInstance.step = 0.1;
558
- // slideToValue(sliderInstance, 33.3333, Thumb.END, platform.IOS);
559
- // expect(inputInstance.value).toBe(33);
560
- } ) ;
561
-
562
- it ( 'should truncate long decimal values when using a decimal step and the arrow keys' , ( ) => {
563
555
sliderInstance . step = 0.1 ;
564
- changeValueUsingArrowKeys ( sliderInstance , RIGHT_ARROW , Thumb . END ) ;
565
- changeValueUsingArrowKeys ( sliderInstance , RIGHT_ARROW , Thumb . END ) ;
566
- changeValueUsingArrowKeys ( sliderInstance , RIGHT_ARROW , Thumb . END ) ;
567
- expect ( inputInstance . value ) . toBe ( 0.3 ) ;
556
+ slideToValue ( sliderInstance , 66.3333 , Thumb . END , platform . IOS ) ;
557
+ expect ( inputInstance . value ) . toBe ( 66.3 ) ;
568
558
} ) ;
569
559
} ) ;
570
560
571
561
describe ( 'range slider with set step' , ( ) => {
562
+ let fixture : ComponentFixture < RangeSliderWithStep > ;
572
563
let sliderInstance : MatSlider ;
573
564
let startInputInstance : MatSliderThumb ;
574
565
let endInputInstance : MatSliderThumb ;
575
566
576
567
beforeEach ( waitForAsync ( ( ) => {
577
- const fixture = createComponent ( RangeSliderWithStep ) ;
568
+ fixture = createComponent ( RangeSliderWithStep ) ;
578
569
fixture . detectChanges ( ) ;
579
570
const sliderDebugElement = fixture . debugElement . query ( By . directive ( MatSlider ) ) ;
580
571
sliderInstance = sliderDebugElement . componentInstance ;
@@ -617,33 +608,23 @@ describe('MDC-based MatSlider' , () => {
617
608
} ) ;
618
609
619
610
it ( 'should truncate long decimal start values when using a decimal step' , ( ) => {
620
- // TODO(wagnermaciel): Uncomment this test once b/182504575 is resolved.
621
- // sliderInstance.step = 0.1;
622
- // slideToValue(sliderInstance, 33.3333, Thumb.START, platform.IOS);
623
- // expect(startInputInstance.value).toBe(33);
611
+ sliderInstance . step = 0.1 ;
612
+ slideToValue ( sliderInstance , 66.3333 , Thumb . START , platform . IOS ) ;
613
+ expect ( startInputInstance . value ) . toBe ( 66.3 ) ;
624
614
} ) ;
625
615
626
616
it ( 'should truncate long decimal end values when using a decimal step' , ( ) => {
627
- // TODO(wagnermaciel): Uncomment this test once b/182504575 is resolved.
628
- // sliderInstance.step = 0.1;
629
- // slideToValue(sliderInstance, 66.6666, Thumb.END, platform.IOS);
630
- // expect(endInputInstance.value).toBe(66);
631
- } ) ;
632
-
633
- it ( 'should truncate long decimal start values when using a decimal step arrow keys' , ( ) => {
634
617
sliderInstance . step = 0.1 ;
635
- changeValueUsingArrowKeys ( sliderInstance , RIGHT_ARROW , Thumb . START ) ;
636
- changeValueUsingArrowKeys ( sliderInstance , RIGHT_ARROW , Thumb . START ) ;
637
- changeValueUsingArrowKeys ( sliderInstance , RIGHT_ARROW , Thumb . START ) ;
638
- expect ( startInputInstance . value ) . toBe ( 0.3 ) ;
639
- } ) ;
618
+ slideToValue ( sliderInstance , 66.3333 , Thumb . END , platform . IOS ) ;
619
+ expect ( endInputInstance . value ) . toBe ( 66.3 ) ;
640
620
641
- it ( 'should truncate long decimal end values when using a decimal step arrow keys' , ( ) => {
642
- sliderInstance . step = 0.1 ;
643
- changeValueUsingArrowKeys ( sliderInstance , LEFT_ARROW , Thumb . END ) ;
644
- changeValueUsingArrowKeys ( sliderInstance , LEFT_ARROW , Thumb . END ) ;
645
- changeValueUsingArrowKeys ( sliderInstance , LEFT_ARROW , Thumb . END ) ;
646
- expect ( endInputInstance . value ) . toBe ( 99.7 ) ;
621
+ // NOTE(wagnermaciel): Different browsers treat the clientX dispatched by us differently.
622
+ // Below is an example of a case that should work but because Firefox rounds the clientX
623
+ // down, the clientX that gets dispatched (1695.998...) is not the same clientX that the MDC
624
+ // Foundation receives (1695). This means the test will pass on chromium but fail on Firefox.
625
+ //
626
+ // slideToValue(sliderInstance, 66.66, Thumb.END, platform.IOS);
627
+ // expect(endInputInstance.value).toBe(66.7);
647
628
} ) ;
648
629
} ) ;
649
630
@@ -979,22 +960,6 @@ function slideToValue(slider: MatSlider, value: number, thumbPosition: Thumb, is
979
960
dispatchPointerOrTouchEvent ( sliderElement , PointerEventType . POINTER_UP , endX , endY , isIOS ) ;
980
961
}
981
962
982
- /**
983
- * Mimics changing the slider value using arrow keys.
984
- *
985
- * Dispatching keydown events on inputs do not trigger value changes. Thus, to mimic this behavior,
986
- * we manually change the slider inputs value and then dispatch a change event (which is what the
987
- * MDC Foundation is listening for & how it handles these updates).
988
- */
989
- function changeValueUsingArrowKeys ( slider : MatSlider , arrow : number , thumbPosition : Thumb ) {
990
- const input = slider . _getInput ( thumbPosition ) ;
991
- const value = arrow === RIGHT_ARROW
992
- ? input . value + slider . step
993
- : input . value - slider . step ;
994
- input . _hostElement . value = value . toString ( ) ;
995
- dispatchFakeEvent ( input . _hostElement , 'change' ) ;
996
- }
997
-
998
963
/** Dispatch a pointerdown or pointerup event if supported, otherwise dispatch the touch event. */
999
964
function dispatchPointerOrTouchEvent (
1000
965
node : Node , type : PointerEventType , x : number , y : number , isIOS : boolean ) {
0 commit comments