@@ -22,7 +22,6 @@ import {
22
22
ViewEncapsulation ,
23
23
} from '@angular/core' ;
24
24
import { TestBed , ComponentFixture , fakeAsync , flush , tick } from '@angular/core/testing' ;
25
- import { DOCUMENT } from '@angular/common' ;
26
25
import { ViewportRuler , CdkScrollableModule } from '@angular/cdk/scrolling' ;
27
26
import { _supportsShadowDom } from '@angular/cdk/platform' ;
28
27
import { of as observableOf } from 'rxjs' ;
@@ -2483,7 +2482,6 @@ describe('CdkDrag', () => {
2483
2482
startDraggingViaMouse ( fixture , item ) ;
2484
2483
2485
2484
const preview = document . querySelector ( '.cdk-drag-preview' ) as HTMLElement ;
2486
- const previewContainer = document . querySelector ( '.cdk-drag-preview-container' ) as HTMLElement ;
2487
2485
const previewRect = preview . getBoundingClientRect ( ) ;
2488
2486
const zeroPxRegex = / ^ 0 ( p x ) ? $ / ;
2489
2487
@@ -2505,23 +2503,18 @@ describe('CdkDrag', () => {
2505
2503
. withContext ( 'Expected element to be removed from layout' )
2506
2504
. toBe ( '-999em' ) ;
2507
2505
expect ( item . style . opacity ) . withContext ( 'Expected element to be invisible' ) . toBe ( '0' ) ;
2508
- expect ( previewContainer )
2509
- . withContext ( 'Expected preview container to be in the DOM' )
2510
- . toBeTruthy ( ) ;
2511
- expect ( previewContainer . style . color )
2512
- . withContext ( 'Expected preview container to reset user agent color' )
2513
- . toBe ( 'inherit' ) ;
2514
- expect ( previewContainer . style . margin )
2515
- . withContext ( 'Expected preview container to reset user agent margin' )
2516
- . toMatch ( zeroPxRegex ) ;
2517
- expect ( previewContainer . style . padding )
2518
- . withContext ( 'Expected preview container to reset user agent padding' )
2506
+ expect ( preview ) . withContext ( 'Expected preview to be in the DOM' ) . toBeTruthy ( ) ;
2507
+ expect ( preview . getAttribute ( 'popover' ) )
2508
+ . withContext ( 'Expected preview to be a popover' )
2509
+ . toBe ( 'manual' ) ;
2510
+ expect ( preview . style . margin )
2511
+ . withContext ( 'Expected preview to reset the margin' )
2519
2512
. toMatch ( zeroPxRegex ) ;
2520
2513
expect ( preview . textContent ! . trim ( ) )
2521
2514
. withContext ( 'Expected preview content to match element' )
2522
2515
. toContain ( 'One' ) ;
2523
- expect ( previewContainer . getAttribute ( 'dir' ) )
2524
- . withContext ( 'Expected preview container element to inherit the directionality.' )
2516
+ expect ( preview . getAttribute ( 'dir' ) )
2517
+ . withContext ( 'Expected preview element to inherit the directionality.' )
2525
2518
. toBe ( 'ltr' ) ;
2526
2519
expect ( previewRect . width )
2527
2520
. withContext ( 'Expected preview width to match element' )
@@ -2532,8 +2525,8 @@ describe('CdkDrag', () => {
2532
2525
expect ( preview . style . pointerEvents )
2533
2526
. withContext ( 'Expected pointer events to be disabled on the preview' )
2534
2527
. toBe ( 'none' ) ;
2535
- expect ( previewContainer . style . zIndex )
2536
- . withContext ( 'Expected preview container to have a high default zIndex.' )
2528
+ expect ( preview . style . zIndex )
2529
+ . withContext ( 'Expected preview to have a high default zIndex.' )
2537
2530
. toBe ( '1000' ) ;
2538
2531
// Use a regex here since some browsers normalize 0 to 0px, but others don't.
2539
2532
// Use a regex here since some browsers normalize 0 to 0px, but others don't.
@@ -2554,8 +2547,8 @@ describe('CdkDrag', () => {
2554
2547
expect ( item . style . top ) . withContext ( 'Expected element to be within the layout' ) . toBeFalsy ( ) ;
2555
2548
expect ( item . style . left ) . withContext ( 'Expected element to be within the layout' ) . toBeFalsy ( ) ;
2556
2549
expect ( item . style . opacity ) . withContext ( 'Expected element to be visible' ) . toBeFalsy ( ) ;
2557
- expect ( previewContainer . parentNode )
2558
- . withContext ( 'Expected preview container to be removed from the DOM' )
2550
+ expect ( preview . parentNode )
2551
+ . withContext ( 'Expected preview to be removed from the DOM' )
2559
2552
. toBeFalsy ( ) ;
2560
2553
} ) ) ;
2561
2554
@@ -2573,59 +2566,10 @@ describe('CdkDrag', () => {
2573
2566
const item = fixture . componentInstance . dragItems . toArray ( ) [ 1 ] . element . nativeElement ;
2574
2567
startDraggingViaMouse ( fixture , item ) ;
2575
2568
2576
- const preview = document . querySelector ( '.cdk-drag-preview-container ' ) ! as HTMLElement ;
2569
+ const preview = document . querySelector ( '.cdk-drag-preview' ) ! as HTMLElement ;
2577
2570
expect ( preview . style . zIndex ) . toBe ( '3000' ) ;
2578
2571
} ) ) ;
2579
2572
2580
- it ( 'should create the preview inside the fullscreen element when in fullscreen mode' , fakeAsync ( ( ) => {
2581
- // Provide a limited stub of the document since we can't trigger fullscreen
2582
- // mode in unit tests and there are some issues with doing it in e2e tests.
2583
- const fakeDocument = {
2584
- body : document . body ,
2585
- documentElement : document . documentElement ,
2586
- fullscreenElement : document . createElement ( 'div' ) ,
2587
- ELEMENT_NODE : Node . ELEMENT_NODE ,
2588
- querySelectorAll : ( ...args : [ string ] ) => document . querySelectorAll ( ...args ) ,
2589
- querySelector : ( ...args : [ string ] ) => document . querySelector ( ...args ) ,
2590
- createElement : ( ...args : [ string ] ) => document . createElement ( ...args ) ,
2591
- createTextNode : ( ...args : [ string ] ) => document . createTextNode ( ...args ) ,
2592
- addEventListener : (
2593
- ...args : [
2594
- string ,
2595
- EventListenerOrEventListenerObject ,
2596
- ( boolean | AddEventListenerOptions | undefined ) ?,
2597
- ]
2598
- ) => document . addEventListener ( ...args ) ,
2599
- removeEventListener : (
2600
- ...args : [
2601
- string ,
2602
- EventListenerOrEventListenerObject ,
2603
- ( boolean | AddEventListenerOptions | undefined ) ?,
2604
- ]
2605
- ) => document . addEventListener ( ...args ) ,
2606
- createComment : ( text : string ) => document . createComment ( text ) ,
2607
- } ;
2608
- const fixture = createComponent ( DraggableInDropZone , [
2609
- {
2610
- provide : DOCUMENT ,
2611
- useFactory : ( ) => fakeDocument ,
2612
- } ,
2613
- ] ) ;
2614
- fixture . detectChanges ( ) ;
2615
- const item = fixture . componentInstance . dragItems . toArray ( ) [ 1 ] . element . nativeElement ;
2616
-
2617
- document . body . appendChild ( fakeDocument . fullscreenElement ) ;
2618
- startDraggingViaMouse ( fixture , item ) ;
2619
- flush ( ) ;
2620
-
2621
- const previewContainer = document . querySelector (
2622
- '.cdk-drag-preview-container' ,
2623
- ) ! as HTMLElement ;
2624
-
2625
- expect ( previewContainer . parentNode ) . toBe ( fakeDocument . fullscreenElement ) ;
2626
- fakeDocument . fullscreenElement . remove ( ) ;
2627
- } ) ) ;
2628
-
2629
2573
it ( 'should be able to constrain the preview position' , fakeAsync ( ( ) => {
2630
2574
const fixture = createComponent ( DraggableInDropZone ) ;
2631
2575
fixture . componentInstance . boundarySelector = '.cdk-drop-list' ;
@@ -2921,8 +2865,8 @@ describe('CdkDrag', () => {
2921
2865
const item = fixture . componentInstance . dragItems . toArray ( ) [ 1 ] . element . nativeElement ;
2922
2866
startDraggingViaMouse ( fixture , item ) ;
2923
2867
2924
- expect ( document . querySelector ( '.cdk-drag-preview-container ' ) ! . getAttribute ( 'dir' ) )
2925
- . withContext ( 'Expected preview container to inherit the directionality.' )
2868
+ expect ( document . querySelector ( '.cdk-drag-preview' ) ! . getAttribute ( 'dir' ) )
2869
+ . withContext ( 'Expected preview to inherit the directionality.' )
2926
2870
. toBe ( 'rtl' ) ;
2927
2871
} ) ) ;
2928
2872
@@ -2934,7 +2878,6 @@ describe('CdkDrag', () => {
2934
2878
startDraggingViaMouse ( fixture , item ) ;
2935
2879
2936
2880
const preview = document . querySelector ( '.cdk-drag-preview' ) as HTMLElement ;
2937
- const previewContainer = document . querySelector ( '.cdk-drag-preview-container' ) as HTMLElement ;
2938
2881
2939
2882
// Add a duration since the tests won't include one.
2940
2883
preview . style . transitionDuration = '500ms' ;
@@ -2947,13 +2890,13 @@ describe('CdkDrag', () => {
2947
2890
fixture . detectChanges ( ) ;
2948
2891
tick ( 250 ) ;
2949
2892
2950
- expect ( previewContainer . parentNode )
2893
+ expect ( preview . parentNode )
2951
2894
. withContext ( 'Expected preview to be in the DOM mid-way through the transition' )
2952
2895
. toBeTruthy ( ) ;
2953
2896
2954
2897
tick ( 500 ) ;
2955
2898
2956
- expect ( previewContainer . parentNode )
2899
+ expect ( preview . parentNode )
2957
2900
. withContext ( 'Expected preview to be removed from the DOM if the transition timed out' )
2958
2901
. toBeFalsy ( ) ;
2959
2902
} ) ) ;
@@ -3057,7 +3000,6 @@ describe('CdkDrag', () => {
3057
3000
startDraggingViaMouse ( fixture , item ) ;
3058
3001
3059
3002
const preview = document . querySelector ( '.cdk-drag-preview' ) ! as HTMLElement ;
3060
- const previewContainer = document . querySelector ( '.cdk-drag-preview-container' ) as HTMLElement ;
3061
3003
preview . style . transition = 'opacity 500ms ease' ;
3062
3004
3063
3005
dispatchMouseEvent ( document , 'mousemove' , 50 , 50 ) ;
@@ -3067,8 +3009,8 @@ describe('CdkDrag', () => {
3067
3009
fixture . detectChanges ( ) ;
3068
3010
tick ( 0 ) ;
3069
3011
3070
- expect ( previewContainer . parentNode )
3071
- . withContext ( 'Expected preview container to be removed from the DOM immediately' )
3012
+ expect ( preview . parentNode )
3013
+ . withContext ( 'Expected preview to be removed from the DOM immediately' )
3072
3014
. toBeFalsy ( ) ;
3073
3015
} ) ) ;
3074
3016
@@ -3080,7 +3022,6 @@ describe('CdkDrag', () => {
3080
3022
startDraggingViaMouse ( fixture , item ) ;
3081
3023
3082
3024
const preview = document . querySelector ( '.cdk-drag-preview' ) ! as HTMLElement ;
3083
- const previewContainer = document . querySelector ( '.cdk-drag-preview-container' ) as HTMLElement ;
3084
3025
preview . style . transition = 'opacity 500ms ease, transform 1000ms ease' ;
3085
3026
3086
3027
dispatchMouseEvent ( document , 'mousemove' , 50 , 50 ) ;
@@ -3090,17 +3031,15 @@ describe('CdkDrag', () => {
3090
3031
fixture . detectChanges ( ) ;
3091
3032
tick ( 500 ) ;
3092
3033
3093
- expect ( previewContainer . parentNode )
3094
- . withContext (
3095
- 'Expected preview container to be in the DOM at the end of the opacity transition' ,
3096
- )
3034
+ expect ( preview . parentNode )
3035
+ . withContext ( 'Expected preview to be in the DOM at the end of the opacity transition' )
3097
3036
. toBeTruthy ( ) ;
3098
3037
3099
3038
tick ( 1000 ) ;
3100
3039
3101
- expect ( previewContainer . parentNode )
3040
+ expect ( preview . parentNode )
3102
3041
. withContext (
3103
- 'Expected preview container to be removed from the DOM at the end of the transform transition' ,
3042
+ 'Expected preview to be removed from the DOM at the end of the transform transition' ,
3104
3043
)
3105
3044
. toBeFalsy ( ) ;
3106
3045
} ) ) ;
@@ -3142,8 +3081,8 @@ describe('CdkDrag', () => {
3142
3081
const item = fixture . componentInstance . dragItems . toArray ( ) [ 1 ] . element . nativeElement ;
3143
3082
3144
3083
startDraggingViaMouse ( fixture , item ) ;
3145
- const previewContainer = document . querySelector ( '.cdk-drag-preview-container ' ) as HTMLElement ;
3146
- expect ( previewContainer . parentNode ) . toBe ( document . body ) ;
3084
+ const preview = document . querySelector ( '.cdk-drag-preview' ) as HTMLElement ;
3085
+ expect ( preview . parentNode ) . toBe ( document . body ) ;
3147
3086
} ) ) ;
3148
3087
3149
3088
it ( 'should insert the preview into the parent node if previewContainer is set to `parent`' , fakeAsync ( ( ) => {
@@ -3154,9 +3093,9 @@ describe('CdkDrag', () => {
3154
3093
const list = fixture . nativeElement . querySelector ( '.drop-list' ) ;
3155
3094
3156
3095
startDraggingViaMouse ( fixture , item ) ;
3157
- const previewContainer = document . querySelector ( '.cdk-drag-preview-container ' ) as HTMLElement ;
3096
+ const preview = document . querySelector ( '.cdk-drag-preview' ) as HTMLElement ;
3158
3097
expect ( list ) . toBeTruthy ( ) ;
3159
- expect ( previewContainer . parentNode ) . toBe ( list ) ;
3098
+ expect ( preview . parentNode ) . toBe ( list ) ;
3160
3099
} ) ) ;
3161
3100
3162
3101
it ( 'should insert the preview into a particular element, if specified' , fakeAsync ( ( ) => {
@@ -3170,10 +3109,8 @@ describe('CdkDrag', () => {
3170
3109
fixture . detectChanges ( ) ;
3171
3110
3172
3111
startDraggingViaMouse ( fixture , item ) ;
3173
- const previewContainerElement = document . querySelector (
3174
- '.cdk-drag-preview-container' ,
3175
- ) as HTMLElement ;
3176
- expect ( previewContainerElement . parentNode ) . toBe ( previewContainer . nativeElement ) ;
3112
+ const preview = document . querySelector ( '.cdk-drag-preview' ) as HTMLElement ;
3113
+ expect ( preview . parentNode ) . toBe ( previewContainer . nativeElement ) ;
3177
3114
} ) ) ;
3178
3115
3179
3116
it ( 'should remove the id from the placeholder' , fakeAsync ( ( ) => {
@@ -3685,17 +3622,15 @@ describe('CdkDrag', () => {
3685
3622
3686
3623
startDraggingViaMouse ( fixture , item ) ;
3687
3624
3688
- const previewContainer = document . querySelector ( '.cdk-drag-preview-container ' ) as HTMLElement ;
3625
+ const preview = document . querySelector ( '.cdk-drag-preview' ) as HTMLElement ;
3689
3626
3690
- expect ( previewContainer . parentNode )
3691
- . withContext ( 'Expected preview container to be in the DOM' )
3692
- . toBeTruthy ( ) ;
3627
+ expect ( preview . parentNode ) . withContext ( 'Expected preview to be in the DOM' ) . toBeTruthy ( ) ;
3693
3628
expect ( item . parentNode ) . withContext ( 'Expected drag item to be in the DOM' ) . toBeTruthy ( ) ;
3694
3629
3695
3630
fixture . destroy ( ) ;
3696
3631
3697
- expect ( previewContainer . parentNode )
3698
- . withContext ( 'Expected preview container to be removed from the DOM' )
3632
+ expect ( preview . parentNode )
3633
+ . withContext ( 'Expected preview to be removed from the DOM' )
3699
3634
. toBeFalsy ( ) ;
3700
3635
expect ( item . parentNode )
3701
3636
. withContext ( 'Expected drag item to be removed from the DOM' )
0 commit comments