@@ -11,49 +11,30 @@ import {
11
11
UP_ARROW ,
12
12
} from '@angular/cdk/keycodes' ;
13
13
import { dispatchFakeEvent , dispatchKeyboardEvent , dispatchMouseEvent } from '@angular/cdk/testing' ;
14
- import { Component , DebugElement , ViewChild } from '@angular/core' ;
15
- import { async , ComponentFixture , TestBed , fakeAsync , flush } from '@angular/core/testing' ;
14
+ import { Component , DebugElement , ViewChild , Type } from '@angular/core' ;
15
+ import { ComponentFixture , TestBed , fakeAsync , flush } from '@angular/core/testing' ;
16
16
import { FormControl , FormsModule , ReactiveFormsModule } from '@angular/forms' ;
17
17
import { By , HAMMER_GESTURE_CONFIG } from '@angular/platform-browser' ;
18
18
import { MatSlider , MatSliderModule } from './index' ;
19
19
import { TestGestureConfig } from './test-gesture-config' ;
20
20
21
-
22
- describe ( 'MatSlider without forms' , ( ) => {
21
+ describe ( 'MatSlider' , ( ) => {
23
22
let gestureConfig : TestGestureConfig ;
24
23
25
- beforeEach ( async ( ( ) = > {
24
+ function createComponent < T > ( component : Type < T > ) : ComponentFixture < T > {
26
25
TestBed . configureTestingModule ( {
27
26
imports : [ MatSliderModule , ReactiveFormsModule , FormsModule , BidiModule ] ,
28
- declarations : [
29
- StandardSlider ,
30
- DisabledSlider ,
31
- SliderWithMinAndMax ,
32
- SliderWithValue ,
33
- SliderWithStep ,
34
- SliderWithAutoTickInterval ,
35
- SliderWithSetTickInterval ,
36
- SliderWithThumbLabel ,
37
- SliderWithOneWayBinding ,
38
- SliderWithValueSmallerThanMin ,
39
- SliderWithValueGreaterThanMax ,
40
- SliderWithChangeHandler ,
41
- SliderWithDirAndInvert ,
42
- SliderWithTabIndexBinding ,
43
- SliderWithNativeTabindexAttr ,
44
- VerticalSlider ,
45
- SliderWithCustomThumbLabelFormatting ,
46
- ] ,
27
+ declarations : [ component ] ,
47
28
providers : [
48
29
{ provide : HAMMER_GESTURE_CONFIG , useFactory : ( ) => {
49
30
gestureConfig = new TestGestureConfig ( ) ;
50
31
return gestureConfig ;
51
32
} }
52
- ] ,
53
- } ) ;
33
+ ]
34
+ } ) . compileComponents ( ) ;
54
35
55
- TestBed . compileComponents ( ) ;
56
- } ) ) ;
36
+ return TestBed . createComponent < T > ( component ) ;
37
+ }
57
38
58
39
describe ( 'standard slider' , ( ) => {
59
40
let fixture : ComponentFixture < StandardSlider > ;
@@ -63,7 +44,7 @@ describe('MatSlider without forms', () => {
63
44
let trackFillElement : HTMLElement ;
64
45
65
46
beforeEach ( ( ) => {
66
- fixture = TestBed . createComponent ( StandardSlider ) ;
47
+ fixture = createComponent ( StandardSlider ) ;
67
48
fixture . detectChanges ( ) ;
68
49
69
50
sliderDebugElement = fixture . debugElement . query ( By . directive ( MatSlider ) ) ;
@@ -229,7 +210,7 @@ describe('MatSlider without forms', () => {
229
210
let trackFillElement : HTMLElement ;
230
211
231
212
beforeEach ( ( ) => {
232
- fixture = TestBed . createComponent ( DisabledSlider ) ;
213
+ fixture = createComponent ( DisabledSlider ) ;
233
214
fixture . detectChanges ( ) ;
234
215
235
216
sliderDebugElement = fixture . debugElement . query ( By . directive ( MatSlider ) ) ;
@@ -305,7 +286,7 @@ describe('MatSlider without forms', () => {
305
286
let testComponent : SliderWithMinAndMax ;
306
287
307
288
beforeEach ( ( ) => {
308
- fixture = TestBed . createComponent ( SliderWithMinAndMax ) ;
289
+ fixture = createComponent ( SliderWithMinAndMax ) ;
309
290
fixture . detectChanges ( ) ;
310
291
311
292
sliderDebugElement = fixture . debugElement . query ( By . directive ( MatSlider ) ) ;
@@ -399,7 +380,7 @@ describe('MatSlider without forms', () => {
399
380
let sliderInstance : MatSlider ;
400
381
401
382
beforeEach ( ( ) => {
402
- fixture = TestBed . createComponent ( SliderWithValue ) ;
383
+ fixture = createComponent ( SliderWithValue ) ;
403
384
fixture . detectChanges ( ) ;
404
385
405
386
sliderDebugElement = fixture . debugElement . query ( By . directive ( MatSlider ) ) ;
@@ -436,7 +417,7 @@ describe('MatSlider without forms', () => {
436
417
let trackFillElement : HTMLElement ;
437
418
438
419
beforeEach ( ( ) => {
439
- fixture = TestBed . createComponent ( SliderWithStep ) ;
420
+ fixture = createComponent ( SliderWithStep ) ;
440
421
fixture . detectChanges ( ) ;
441
422
442
423
sliderDebugElement = fixture . debugElement . query ( By . directive ( MatSlider ) ) ;
@@ -509,7 +490,7 @@ describe('MatSlider without forms', () => {
509
490
let ticksElement : HTMLElement ;
510
491
511
492
beforeEach ( ( ) => {
512
- fixture = TestBed . createComponent ( SliderWithAutoTickInterval ) ;
493
+ fixture = createComponent ( SliderWithAutoTickInterval ) ;
513
494
fixture . detectChanges ( ) ;
514
495
515
496
sliderDebugElement = fixture . debugElement . query ( By . directive ( MatSlider ) ) ;
@@ -539,7 +520,7 @@ describe('MatSlider without forms', () => {
539
520
let ticksElement : HTMLElement ;
540
521
541
522
beforeEach ( ( ) => {
542
- fixture = TestBed . createComponent ( SliderWithSetTickInterval ) ;
523
+ fixture = createComponent ( SliderWithSetTickInterval ) ;
543
524
fixture . detectChanges ( ) ;
544
525
545
526
sliderDebugElement = fixture . debugElement . query ( By . directive ( MatSlider ) ) ;
@@ -581,7 +562,7 @@ describe('MatSlider without forms', () => {
581
562
let thumbLabelTextElement : Element ;
582
563
583
564
beforeEach ( ( ) => {
584
- fixture = TestBed . createComponent ( SliderWithThumbLabel ) ;
565
+ fixture = createComponent ( SliderWithThumbLabel ) ;
585
566
fixture . detectChanges ( ) ;
586
567
587
568
sliderDebugElement = fixture . debugElement . query ( By . directive ( MatSlider ) ) ;
@@ -621,7 +602,7 @@ describe('MatSlider without forms', () => {
621
602
let thumbLabelTextElement : Element ;
622
603
623
604
beforeEach ( ( ) => {
624
- fixture = TestBed . createComponent ( SliderWithCustomThumbLabelFormatting ) ;
605
+ fixture = createComponent ( SliderWithCustomThumbLabelFormatting ) ;
625
606
fixture . detectChanges ( ) ;
626
607
627
608
const sliderDebugElement = fixture . debugElement . query ( By . directive ( MatSlider ) ) ;
@@ -656,7 +637,7 @@ describe('MatSlider without forms', () => {
656
637
let trackFillElement : HTMLElement ;
657
638
658
639
beforeEach ( ( ) => {
659
- fixture = TestBed . createComponent ( SliderWithOneWayBinding ) ;
640
+ fixture = createComponent ( SliderWithOneWayBinding ) ;
660
641
fixture . detectChanges ( ) ;
661
642
662
643
testComponent = fixture . debugElement . componentInstance ;
@@ -689,7 +670,7 @@ describe('MatSlider without forms', () => {
689
670
let trackFillElement : HTMLElement ;
690
671
691
672
beforeEach ( ( ) => {
692
- fixture = TestBed . createComponent ( SliderWithValueSmallerThanMin ) ;
673
+ fixture = createComponent ( SliderWithValueSmallerThanMin ) ;
693
674
fixture . detectChanges ( ) ;
694
675
695
676
sliderDebugElement = fixture . debugElement . query ( By . directive ( MatSlider ) ) ;
@@ -717,7 +698,7 @@ describe('MatSlider without forms', () => {
717
698
let trackFillElement : HTMLElement ;
718
699
719
700
beforeEach ( ( ) => {
720
- fixture = TestBed . createComponent ( SliderWithValueGreaterThanMax ) ;
701
+ fixture = createComponent ( SliderWithValueGreaterThanMax ) ;
721
702
fixture . detectChanges ( ) ;
722
703
723
704
sliderDebugElement = fixture . debugElement . query ( By . directive ( MatSlider ) ) ;
@@ -744,7 +725,7 @@ describe('MatSlider without forms', () => {
744
725
let testComponent : SliderWithChangeHandler ;
745
726
746
727
beforeEach ( ( ) => {
747
- fixture = TestBed . createComponent ( SliderWithChangeHandler ) ;
728
+ fixture = createComponent ( SliderWithChangeHandler ) ;
748
729
fixture . detectChanges ( ) ;
749
730
750
731
testComponent = fixture . debugElement . componentInstance ;
@@ -815,7 +796,7 @@ describe('MatSlider without forms', () => {
815
796
let testComponent : SliderWithChangeHandler ;
816
797
817
798
beforeEach ( ( ) => {
818
- fixture = TestBed . createComponent ( SliderWithChangeHandler ) ;
799
+ fixture = createComponent ( SliderWithChangeHandler ) ;
819
800
fixture . detectChanges ( ) ;
820
801
821
802
testComponent = fixture . debugElement . componentInstance ;
@@ -863,7 +844,7 @@ describe('MatSlider without forms', () => {
863
844
let sliderInstance : MatSlider ;
864
845
865
846
beforeEach ( ( ) => {
866
- fixture = TestBed . createComponent ( SliderWithChangeHandler ) ;
847
+ fixture = createComponent ( SliderWithChangeHandler ) ;
867
848
fixture . detectChanges ( ) ;
868
849
869
850
testComponent = fixture . debugElement . componentInstance ;
@@ -1002,7 +983,7 @@ describe('MatSlider without forms', () => {
1002
983
let testComponent : SliderWithDirAndInvert ;
1003
984
1004
985
beforeEach ( ( ) => {
1005
- fixture = TestBed . createComponent ( SliderWithDirAndInvert ) ;
986
+ fixture = createComponent ( SliderWithDirAndInvert ) ;
1006
987
fixture . detectChanges ( ) ;
1007
988
1008
989
testComponent = fixture . debugElement . componentInstance ;
@@ -1143,7 +1124,7 @@ describe('MatSlider without forms', () => {
1143
1124
let testComponent : VerticalSlider ;
1144
1125
1145
1126
beforeEach ( ( ) => {
1146
- fixture = TestBed . createComponent ( VerticalSlider ) ;
1127
+ fixture = createComponent ( VerticalSlider ) ;
1147
1128
fixture . detectChanges ( ) ;
1148
1129
1149
1130
testComponent = fixture . debugElement . componentInstance ;
@@ -1199,7 +1180,7 @@ describe('MatSlider without forms', () => {
1199
1180
describe ( 'tabindex' , ( ) => {
1200
1181
1201
1182
it ( 'should allow setting the tabIndex through binding' , ( ) => {
1202
- const fixture = TestBed . createComponent ( SliderWithTabIndexBinding ) ;
1183
+ const fixture = createComponent ( SliderWithTabIndexBinding ) ;
1203
1184
fixture . detectChanges ( ) ;
1204
1185
1205
1186
const slider = fixture . debugElement . query ( By . directive ( MatSlider ) ) . componentInstance ;
@@ -1213,7 +1194,7 @@ describe('MatSlider without forms', () => {
1213
1194
} ) ;
1214
1195
1215
1196
it ( 'should detect the native tabindex attribute' , ( ) => {
1216
- const fixture = TestBed . createComponent ( SliderWithNativeTabindexAttr ) ;
1197
+ const fixture = createComponent ( SliderWithNativeTabindexAttr ) ;
1217
1198
fixture . detectChanges ( ) ;
1218
1199
1219
1200
const slider = fixture . debugElement . query ( By . directive ( MatSlider ) ) . componentInstance ;
@@ -1222,28 +1203,6 @@ describe('MatSlider without forms', () => {
1222
1203
. toBe ( 5 , 'Expected the tabIndex to be set to the value of the native attribute.' ) ;
1223
1204
} ) ;
1224
1205
} ) ;
1225
- } ) ;
1226
-
1227
- describe ( 'MatSlider with forms module' , ( ) => {
1228
- let gestureConfig : TestGestureConfig ;
1229
-
1230
- beforeEach ( async ( ( ) => {
1231
- TestBed . configureTestingModule ( {
1232
- imports : [ MatSliderModule , ReactiveFormsModule , FormsModule , BidiModule ] ,
1233
- declarations : [
1234
- SliderWithFormControl ,
1235
- SliderWithNgModel ,
1236
- ] ,
1237
- providers : [
1238
- { provide : HAMMER_GESTURE_CONFIG , useFactory : ( ) => {
1239
- gestureConfig = new TestGestureConfig ( ) ;
1240
- return gestureConfig ;
1241
- } }
1242
- ] ,
1243
- } ) ;
1244
-
1245
- TestBed . compileComponents ( ) ;
1246
- } ) ) ;
1247
1206
1248
1207
describe ( 'slider with ngModel' , ( ) => {
1249
1208
let fixture : ComponentFixture < SliderWithNgModel > ;
@@ -1252,7 +1211,7 @@ describe('MatSlider with forms module', () => {
1252
1211
let testComponent : SliderWithNgModel ;
1253
1212
1254
1213
beforeEach ( ( ) => {
1255
- fixture = TestBed . createComponent ( SliderWithNgModel ) ;
1214
+ fixture = createComponent ( SliderWithNgModel ) ;
1256
1215
fixture . detectChanges ( ) ;
1257
1216
1258
1217
testComponent = fixture . debugElement . componentInstance ;
@@ -1314,7 +1273,7 @@ describe('MatSlider with forms module', () => {
1314
1273
let testComponent : SliderWithFormControl ;
1315
1274
1316
1275
beforeEach ( ( ) => {
1317
- fixture = TestBed . createComponent ( SliderWithFormControl ) ;
1276
+ fixture = createComponent ( SliderWithFormControl ) ;
1318
1277
fixture . detectChanges ( ) ;
1319
1278
1320
1279
testComponent = fixture . debugElement . componentInstance ;
0 commit comments