6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
9
+ import { BidiModule , Directionality } from '@angular/cdk/bidi' ;
9
10
import { Platform } from '@angular/cdk/platform' ;
10
11
import {
11
12
dispatchMouseEvent ,
12
13
dispatchPointerEvent ,
13
14
dispatchTouchEvent ,
14
15
} from '@angular/cdk/testing/private' ;
15
- import { Component , QueryList , Type , ViewChild , ViewChildren } from '@angular/core' ;
16
+ import { Component , Provider , QueryList , Type , ViewChild , ViewChildren } from '@angular/core' ;
16
17
import {
17
18
ComponentFixture ,
18
19
fakeAsync ,
@@ -24,6 +25,7 @@ import {
24
25
import { FormControl , FormsModule , ReactiveFormsModule } from '@angular/forms' ;
25
26
import { By } from '@angular/platform-browser' ;
26
27
import { Thumb } from '@material/slider' ;
28
+ import { of } from 'rxjs' ;
27
29
import { MatSliderModule } from './module' ;
28
30
import { MatSlider , MatSliderThumb , MatSliderVisualThumb } from './slider' ;
29
31
@@ -41,10 +43,14 @@ describe('MDC-based MatSlider' , () => {
41
43
spyOn ( Element . prototype , 'setPointerCapture' ) ;
42
44
} ) ;
43
45
44
- function createComponent < T > ( component : Type < T > ) : ComponentFixture < T > {
46
+ function createComponent < T > (
47
+ component : Type < T > ,
48
+ providers : Provider [ ] = [ ] ,
49
+ ) : ComponentFixture < T > {
45
50
TestBed . configureTestingModule ( {
46
- imports : [ FormsModule , MatSliderModule , ReactiveFormsModule ] ,
51
+ imports : [ FormsModule , MatSliderModule , ReactiveFormsModule , BidiModule ] ,
47
52
declarations : [ component ] ,
53
+ providers : [ ...providers ] ,
48
54
} ) . compileComponents ( ) ;
49
55
return TestBed . createComponent < T > ( component ) ;
50
56
}
@@ -1158,6 +1164,53 @@ describe('MDC-based MatSlider' , () => {
1158
1164
} ) ;
1159
1165
} ) ;
1160
1166
1167
+ describe ( 'slider with direction' , ( ) => {
1168
+ let sliderInstance : MatSlider ;
1169
+ let inputInstance : MatSliderThumb ;
1170
+
1171
+ beforeEach ( waitForAsync ( ( ) => {
1172
+ const fixture = createComponent ( StandardSlider , [ {
1173
+ provide : Directionality ,
1174
+ useValue : ( { value : 'rtl' , change : of ( ) } )
1175
+ } ] ) ;
1176
+ fixture . detectChanges ( ) ;
1177
+ const sliderDebugElement = fixture . debugElement . query ( By . directive ( MatSlider ) ) ;
1178
+ sliderInstance = sliderDebugElement . componentInstance ;
1179
+ inputInstance = sliderInstance . _getInput ( Thumb . END ) ;
1180
+ } ) ) ;
1181
+
1182
+ it ( 'works in RTL languages' , ( ) => {
1183
+ setValueByClick ( sliderInstance , 30 , platform . IOS ) ;
1184
+ expect ( inputInstance . value ) . toBe ( 70 ) ;
1185
+ } ) ;
1186
+ } ) ;
1187
+
1188
+ describe ( 'range slider with direction' , ( ) => {
1189
+ let sliderInstance : MatSlider ;
1190
+ let startInputInstance : MatSliderThumb ;
1191
+ let endInputInstance : MatSliderThumb ;
1192
+
1193
+ beforeEach ( waitForAsync ( ( ) => {
1194
+ const fixture = createComponent ( StandardRangeSlider , [ {
1195
+ provide : Directionality ,
1196
+ useValue : ( { value : 'rtl' , change : of ( ) } )
1197
+ } ] ) ;
1198
+ fixture . detectChanges ( ) ;
1199
+ const sliderDebugElement = fixture . debugElement . query ( By . directive ( MatSlider ) ) ;
1200
+ sliderInstance = sliderDebugElement . componentInstance ;
1201
+ startInputInstance = sliderInstance . _getInput ( Thumb . START ) ;
1202
+ endInputInstance = sliderInstance . _getInput ( Thumb . END ) ;
1203
+ } ) ) ;
1204
+
1205
+ it ( 'works in RTL languages' , ( ) => {
1206
+ setValueByClick ( sliderInstance , 90 , platform . IOS ) ;
1207
+ expect ( startInputInstance . value ) . toBe ( 10 ) ;
1208
+
1209
+ setValueByClick ( sliderInstance , 10 , platform . IOS ) ;
1210
+ expect ( endInputInstance . value ) . toBe ( 90 ) ;
1211
+ } ) ;
1212
+ } ) ;
1213
+
1161
1214
describe ( 'slider with ngModel' , ( ) => {
1162
1215
let fixture : ComponentFixture < SliderWithNgModel > ;
1163
1216
let testComponent : SliderWithNgModel ;
0 commit comments