@@ -16,20 +16,17 @@ import {
16
16
Component ,
17
17
ElementRef ,
18
18
Input ,
19
- Provider ,
20
19
QueryList ,
21
- Type ,
22
20
ViewChild ,
23
21
ViewChildren ,
24
22
ViewEncapsulation ,
25
23
inject ,
26
24
signal ,
27
25
} from '@angular/core' ;
28
- import { ComponentFixture , TestBed , fakeAsync , flush , tick } from '@angular/core/testing' ;
26
+ import { TestBed , fakeAsync , flush , tick } from '@angular/core/testing' ;
29
27
import { of as observableOf } from 'rxjs' ;
30
28
31
29
import { extendStyles } from '../dom/styling' ;
32
- import { DragDropModule } from '../drag-drop-module' ;
33
30
import { CdkDragDrop , CdkDragEnter , CdkDragStart } from '../drag-events' ;
34
31
import { DragRef , Point , PreviewContainer } from '../drag-ref' ;
35
32
import { moveItemInArray } from '../drag-utils' ;
@@ -39,6 +36,7 @@ import {CdkDrag} from './drag';
39
36
import { CdkDropList } from './drop-list' ;
40
37
import { CdkDropListGroup } from './drop-list-group' ;
41
38
import {
39
+ createComponent ,
42
40
assertDownwardSorting ,
43
41
assertUpwardSorting ,
44
42
continueDraggingViaTouch ,
@@ -56,41 +54,6 @@ const ITEM_HEIGHT = 25;
56
54
const ITEM_WIDTH = 75 ;
57
55
58
56
describe ( 'CdkDrag' , ( ) => {
59
- function createComponent < T > (
60
- componentType : Type < T > ,
61
- providers : Provider [ ] = [ ] ,
62
- dragDistance = 0 ,
63
- extraDeclarations : Type < any > [ ] = [ ] ,
64
- encapsulation ?: ViewEncapsulation ,
65
- ) : ComponentFixture < T > {
66
- TestBed . configureTestingModule ( {
67
- imports : [ DragDropModule , CdkScrollableModule ] ,
68
- providers : [
69
- {
70
- provide : CDK_DRAG_CONFIG ,
71
- useValue : {
72
- // We default the `dragDistance` to zero, because the majority of the tests
73
- // don't care about it and drags are a lot easier to simulate when we don't
74
- // have to deal with thresholds.
75
- dragStartThreshold : dragDistance ,
76
- pointerDirectionChangeThreshold : 5 ,
77
- } as DragDropConfig ,
78
- } ,
79
- ...providers ,
80
- ] ,
81
- declarations : [ componentType , ...extraDeclarations ] ,
82
- } ) ;
83
-
84
- if ( encapsulation != null ) {
85
- TestBed . overrideComponent ( componentType , {
86
- set : { encapsulation} ,
87
- } ) ;
88
- }
89
-
90
- TestBed . compileComponents ( ) ;
91
- return TestBed . createComponent < T > ( componentType ) ;
92
- }
93
-
94
57
describe ( 'in a drop container' , ( ) => {
95
58
it ( 'should be able to attach data to the drop container' , ( ) => {
96
59
const fixture = createComponent ( DraggableInDropZone ) ;
@@ -250,7 +213,7 @@ describe('CdkDrag', () => {
250
213
} ) ) ;
251
214
252
215
it ( 'should not toggle dragging class if the element was not dragged more than the threshold' , fakeAsync ( ( ) => {
253
- const fixture = createComponent ( DraggableInDropZone , [ ] , 5 ) ;
216
+ const fixture = createComponent ( DraggableInDropZone , { dragDistance : 5 } ) ;
254
217
fixture . detectChanges ( ) ;
255
218
const item = fixture . componentInstance . dragItems . toArray ( ) [ 1 ] . element . nativeElement ;
256
219
const dropZone = fixture . componentInstance . dropInstance ;
@@ -565,12 +528,14 @@ describe('CdkDrag', () => {
565
528
} ) ) ;
566
529
567
530
it ( 'should dispatch the correct `dropped` event in RTL horizontal drop zone' , fakeAsync ( ( ) => {
568
- const fixture = createComponent ( DraggableInHorizontalDropZone , [
569
- {
570
- provide : Directionality ,
571
- useValue : { value : 'rtl' , change : observableOf ( ) } ,
572
- } ,
573
- ] ) ;
531
+ const fixture = createComponent ( DraggableInHorizontalDropZone , {
532
+ providers : [
533
+ {
534
+ provide : Directionality ,
535
+ useValue : { value : 'rtl' , change : observableOf ( ) } ,
536
+ } ,
537
+ ] ,
538
+ } ) ;
574
539
575
540
fixture . nativeElement . setAttribute ( 'dir' , 'rtl' ) ;
576
541
fixture . detectChanges ( ) ;
@@ -720,13 +685,9 @@ describe('CdkDrag', () => {
720
685
return ;
721
686
}
722
687
723
- const fixture = createComponent (
724
- DraggableInScrollableVerticalDropZone ,
725
- [ ] ,
726
- undefined ,
727
- [ ] ,
728
- ViewEncapsulation . ShadowDom ,
729
- ) ;
688
+ const fixture = createComponent ( DraggableInScrollableVerticalDropZone , {
689
+ encapsulation : ViewEncapsulation . ShadowDom ,
690
+ } ) ;
730
691
fixture . detectChanges ( ) ;
731
692
const dragItems = fixture . componentInstance . dragItems ;
732
693
const firstItem = dragItems . first ;
@@ -901,15 +862,17 @@ describe('CdkDrag', () => {
901
862
} ) ) ;
902
863
903
864
it ( 'should be able to configure the preview z-index' , fakeAsync ( ( ) => {
904
- const fixture = createComponent ( DraggableInDropZone , [
905
- {
906
- provide : CDK_DRAG_CONFIG ,
907
- useValue : {
908
- dragStartThreshold : 0 ,
909
- zIndex : 3000 ,
865
+ const fixture = createComponent ( DraggableInDropZone , {
866
+ providers : [
867
+ {
868
+ provide : CDK_DRAG_CONFIG ,
869
+ useValue : {
870
+ dragStartThreshold : 0 ,
871
+ zIndex : 3000 ,
872
+ } ,
910
873
} ,
911
- } ,
912
- ] ) ;
874
+ ] ,
875
+ } ) ;
913
876
fixture . detectChanges ( ) ;
914
877
const item = fixture . componentInstance . dragItems . toArray ( ) [ 1 ] . element . nativeElement ;
915
878
startDraggingViaMouse ( fixture , item ) ;
@@ -1017,13 +980,9 @@ describe('CdkDrag', () => {
1017
980
return ;
1018
981
}
1019
982
1020
- const fixture = createComponent (
1021
- DraggableInScrollableParentContainer ,
1022
- [ ] ,
1023
- undefined ,
1024
- [ ] ,
1025
- ViewEncapsulation . ShadowDom ,
1026
- ) ;
983
+ const fixture = createComponent ( DraggableInScrollableParentContainer , {
984
+ encapsulation : ViewEncapsulation . ShadowDom ,
985
+ } ) ;
1027
986
fixture . componentInstance . boundarySelector = '.cdk-drop-list' ;
1028
987
fixture . detectChanges ( ) ;
1029
988
@@ -1191,7 +1150,7 @@ describe('CdkDrag', () => {
1191
1150
} ) ) ;
1192
1151
1193
1152
it ( 'should not create a preview if the element was not dragged far enough' , fakeAsync ( ( ) => {
1194
- const fixture = createComponent ( DraggableInDropZone , [ ] , 5 ) ;
1153
+ const fixture = createComponent ( DraggableInDropZone , { dragDistance : 5 } ) ;
1195
1154
fixture . detectChanges ( ) ;
1196
1155
const item = fixture . componentInstance . dragItems . toArray ( ) [ 1 ] . element . nativeElement ;
1197
1156
@@ -1201,12 +1160,14 @@ describe('CdkDrag', () => {
1201
1160
} ) ) ;
1202
1161
1203
1162
it ( 'should pass the proper direction to the preview in rtl' , fakeAsync ( ( ) => {
1204
- const fixture = createComponent ( DraggableInDropZone , [
1205
- {
1206
- provide : Directionality ,
1207
- useValue : { value : 'rtl' , change : observableOf ( ) } ,
1208
- } ,
1209
- ] ) ;
1163
+ const fixture = createComponent ( DraggableInDropZone , {
1164
+ providers : [
1165
+ {
1166
+ provide : Directionality ,
1167
+ useValue : { value : 'rtl' , change : observableOf ( ) } ,
1168
+ } ,
1169
+ ] ,
1170
+ } ) ;
1210
1171
1211
1172
fixture . detectChanges ( ) ;
1212
1173
@@ -1494,7 +1455,7 @@ describe('CdkDrag', () => {
1494
1455
} ) ) ;
1495
1456
1496
1457
it ( 'should not create placeholder if the element was not dragged far enough' , fakeAsync ( ( ) => {
1497
- const fixture = createComponent ( DraggableInDropZone , [ ] , 5 ) ;
1458
+ const fixture = createComponent ( DraggableInDropZone , { dragDistance : 5 } ) ;
1498
1459
fixture . detectChanges ( ) ;
1499
1460
const item = fixture . componentInstance . dragItems . toArray ( ) [ 1 ] . element . nativeElement ;
1500
1461
@@ -2713,12 +2674,14 @@ describe('CdkDrag', () => {
2713
2674
} ) ) ;
2714
2675
2715
2676
it ( 'should auto-scroll right if the user holds their pointer at right edge in rtl' , fakeAsync ( ( ) => {
2716
- const fixture = createComponent ( DraggableInScrollableHorizontalDropZone , [
2717
- {
2718
- provide : Directionality ,
2719
- useValue : { value : 'rtl' , change : observableOf ( ) } ,
2720
- } ,
2721
- ] ) ;
2677
+ const fixture = createComponent ( DraggableInScrollableHorizontalDropZone , {
2678
+ providers : [
2679
+ {
2680
+ provide : Directionality ,
2681
+ useValue : { value : 'rtl' , change : observableOf ( ) } ,
2682
+ } ,
2683
+ ] ,
2684
+ } ) ;
2722
2685
fixture . nativeElement . setAttribute ( 'dir' , 'rtl' ) ;
2723
2686
fixture . detectChanges ( ) ;
2724
2687
const item = fixture . componentInstance . dragItems . first . element . nativeElement ;
@@ -2740,12 +2703,14 @@ describe('CdkDrag', () => {
2740
2703
} ) ) ;
2741
2704
2742
2705
it ( 'should auto-scroll left if the user holds their pointer at left edge in rtl' , fakeAsync ( ( ) => {
2743
- const fixture = createComponent ( DraggableInScrollableHorizontalDropZone , [
2744
- {
2745
- provide : Directionality ,
2746
- useValue : { value : 'rtl' , change : observableOf ( ) } ,
2747
- } ,
2748
- ] ) ;
2706
+ const fixture = createComponent ( DraggableInScrollableHorizontalDropZone , {
2707
+ providers : [
2708
+ {
2709
+ provide : Directionality ,
2710
+ useValue : { value : 'rtl' , change : observableOf ( ) } ,
2711
+ } ,
2712
+ ] ,
2713
+ } ) ;
2749
2714
fixture . nativeElement . setAttribute ( 'dir' , 'rtl' ) ;
2750
2715
fixture . detectChanges ( ) ;
2751
2716
const item = fixture . componentInstance . dragItems . first . element . nativeElement ;
@@ -3181,12 +3146,14 @@ describe('CdkDrag', () => {
3181
3146
lockAxis : 'y' ,
3182
3147
} ;
3183
3148
3184
- const fixture = createComponent ( PlainStandaloneDropList , [
3185
- {
3186
- provide : CDK_DRAG_CONFIG ,
3187
- useValue : config ,
3188
- } ,
3189
- ] ) ;
3149
+ const fixture = createComponent ( PlainStandaloneDropList , {
3150
+ providers : [
3151
+ {
3152
+ provide : CDK_DRAG_CONFIG ,
3153
+ useValue : config ,
3154
+ } ,
3155
+ ] ,
3156
+ } ) ;
3190
3157
fixture . detectChanges ( ) ;
3191
3158
const list = fixture . componentInstance . dropList ;
3192
3159
expect ( list . disabled ) . toBe ( true ) ;
@@ -4287,9 +4254,9 @@ describe('CdkDrag', () => {
4287
4254
) ;
4288
4255
4289
4256
it ( 'should set the receiving class when the list is wrapped in an OnPush component' , fakeAsync ( ( ) => {
4290
- const fixture = createComponent ( ConnectedDropListsInOnPush , undefined , undefined , [
4291
- DraggableInOnPushDropZone ,
4292
- ] ) ;
4257
+ const fixture = createComponent ( ConnectedDropListsInOnPush , {
4258
+ extraDeclarations : [ DraggableInOnPushDropZone ] ,
4259
+ } ) ;
4293
4260
fixture . detectChanges ( ) ;
4294
4261
4295
4262
const dropZones = Array . from < HTMLElement > (
@@ -4630,9 +4597,9 @@ describe('CdkDrag', () => {
4630
4597
'should toggle a class when dragging an item inside a wrapper component component ' +
4631
4598
'with OnPush change detection' ,
4632
4599
fakeAsync ( ( ) => {
4633
- const fixture = createComponent ( ConnectedWrappedDropZones , [ ] , 0 , [
4634
- WrappedDropContainerComponent ,
4635
- ] ) ;
4600
+ const fixture = createComponent ( ConnectedWrappedDropZones , {
4601
+ extraDeclarations : [ WrappedDropContainerComponent ] ,
4602
+ } ) ;
4636
4603
fixture . detectChanges ( ) ;
4637
4604
4638
4605
const [ startZone , targetZone ] = fixture . nativeElement . querySelectorAll ( '.cdk-drop-list' ) ;
@@ -4773,13 +4740,9 @@ describe('CdkDrag', () => {
4773
4740
return ;
4774
4741
}
4775
4742
4776
- const fixture = createComponent (
4777
- ConnectedDropZones ,
4778
- [ ] ,
4779
- undefined ,
4780
- [ ] ,
4781
- ViewEncapsulation . ShadowDom ,
4782
- ) ;
4743
+ const fixture = createComponent ( ConnectedDropZones , {
4744
+ encapsulation : ViewEncapsulation . ShadowDom ,
4745
+ } ) ;
4783
4746
fixture . detectChanges ( ) ;
4784
4747
4785
4748
const groups = fixture . componentInstance . groupedDragItems ;
@@ -4857,13 +4820,9 @@ describe('CdkDrag', () => {
4857
4820
return ;
4858
4821
}
4859
4822
4860
- const fixture = createComponent (
4861
- ConnectedDropZones ,
4862
- [ ] ,
4863
- undefined ,
4864
- [ ] ,
4865
- ViewEncapsulation . ShadowDom ,
4866
- ) ;
4823
+ const fixture = createComponent ( ConnectedDropZones , {
4824
+ encapsulation : ViewEncapsulation . ShadowDom ,
4825
+ } ) ;
4867
4826
fixture . detectChanges ( ) ;
4868
4827
4869
4828
const shadowRoot = fixture . nativeElement . shadowRoot ;
@@ -4959,13 +4918,9 @@ describe('CdkDrag', () => {
4959
4918
return ;
4960
4919
}
4961
4920
4962
- const fixture = createComponent (
4963
- ConnectedDropZones ,
4964
- [ ] ,
4965
- undefined ,
4966
- [ ] ,
4967
- ViewEncapsulation . ShadowDom ,
4968
- ) ;
4921
+ const fixture = createComponent ( ConnectedDropZones , {
4922
+ encapsulation : ViewEncapsulation . ShadowDom ,
4923
+ } ) ;
4969
4924
fixture . detectChanges ( ) ;
4970
4925
const item = fixture . componentInstance . groupedDragItems [ 0 ] [ 1 ] ;
4971
4926
@@ -4980,7 +4935,7 @@ describe('CdkDrag', () => {
4980
4935
4981
4936
describe ( 'with nested drags' , ( ) => {
4982
4937
it ( 'should not move draggable container when dragging child (multitouch)' , fakeAsync ( ( ) => {
4983
- const fixture = createComponent ( NestedDragsComponent , [ ] , 10 ) ;
4938
+ const fixture = createComponent ( NestedDragsComponent , { dragDistance : 10 } ) ;
4984
4939
fixture . detectChanges ( ) ;
4985
4940
4986
4941
// First finger drags container (less then threshold)
0 commit comments