@@ -22,7 +22,6 @@ import {
2222 ViewEncapsulation ,
2323} from '@angular/core' ;
2424import { TestBed , ComponentFixture , fakeAsync , flush , tick } from '@angular/core/testing' ;
25- import { DOCUMENT } from '@angular/common' ;
2625import { ViewportRuler , CdkScrollableModule } from '@angular/cdk/scrolling' ;
2726import { _supportsShadowDom } from '@angular/cdk/platform' ;
2827import { of as observableOf } from 'rxjs' ;
@@ -2483,7 +2482,6 @@ describe('CdkDrag', () => {
24832482 startDraggingViaMouse ( fixture , item ) ;
24842483
24852484 const preview = document . querySelector ( '.cdk-drag-preview' ) as HTMLElement ;
2486- const previewContainer = document . querySelector ( '.cdk-drag-preview-container' ) as HTMLElement ;
24872485 const previewRect = preview . getBoundingClientRect ( ) ;
24882486 const zeroPxRegex = / ^ 0 ( p x ) ? $ / ;
24892487
@@ -2505,23 +2503,18 @@ describe('CdkDrag', () => {
25052503 . withContext ( 'Expected element to be removed from layout' )
25062504 . toBe ( '-999em' ) ;
25072505 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' )
25192512 . toMatch ( zeroPxRegex ) ;
25202513 expect ( preview . textContent ! . trim ( ) )
25212514 . withContext ( 'Expected preview content to match element' )
25222515 . 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.' )
25252518 . toBe ( 'ltr' ) ;
25262519 expect ( previewRect . width )
25272520 . withContext ( 'Expected preview width to match element' )
@@ -2532,8 +2525,8 @@ describe('CdkDrag', () => {
25322525 expect ( preview . style . pointerEvents )
25332526 . withContext ( 'Expected pointer events to be disabled on the preview' )
25342527 . 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.' )
25372530 . toBe ( '1000' ) ;
25382531 // Use a regex here since some browsers normalize 0 to 0px, but others don't.
25392532 // Use a regex here since some browsers normalize 0 to 0px, but others don't.
@@ -2554,8 +2547,8 @@ describe('CdkDrag', () => {
25542547 expect ( item . style . top ) . withContext ( 'Expected element to be within the layout' ) . toBeFalsy ( ) ;
25552548 expect ( item . style . left ) . withContext ( 'Expected element to be within the layout' ) . toBeFalsy ( ) ;
25562549 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' )
25592552 . toBeFalsy ( ) ;
25602553 } ) ) ;
25612554
@@ -2573,59 +2566,10 @@ describe('CdkDrag', () => {
25732566 const item = fixture . componentInstance . dragItems . toArray ( ) [ 1 ] . element . nativeElement ;
25742567 startDraggingViaMouse ( fixture , item ) ;
25752568
2576- const preview = document . querySelector ( '.cdk-drag-preview-container ' ) ! as HTMLElement ;
2569+ const preview = document . querySelector ( '.cdk-drag-preview' ) ! as HTMLElement ;
25772570 expect ( preview . style . zIndex ) . toBe ( '3000' ) ;
25782571 } ) ) ;
25792572
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-
26292573 it ( 'should be able to constrain the preview position' , fakeAsync ( ( ) => {
26302574 const fixture = createComponent ( DraggableInDropZone ) ;
26312575 fixture . componentInstance . boundarySelector = '.cdk-drop-list' ;
@@ -2921,8 +2865,8 @@ describe('CdkDrag', () => {
29212865 const item = fixture . componentInstance . dragItems . toArray ( ) [ 1 ] . element . nativeElement ;
29222866 startDraggingViaMouse ( fixture , item ) ;
29232867
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.' )
29262870 . toBe ( 'rtl' ) ;
29272871 } ) ) ;
29282872
@@ -2934,7 +2878,6 @@ describe('CdkDrag', () => {
29342878 startDraggingViaMouse ( fixture , item ) ;
29352879
29362880 const preview = document . querySelector ( '.cdk-drag-preview' ) as HTMLElement ;
2937- const previewContainer = document . querySelector ( '.cdk-drag-preview-container' ) as HTMLElement ;
29382881
29392882 // Add a duration since the tests won't include one.
29402883 preview . style . transitionDuration = '500ms' ;
@@ -2947,13 +2890,13 @@ describe('CdkDrag', () => {
29472890 fixture . detectChanges ( ) ;
29482891 tick ( 250 ) ;
29492892
2950- expect ( previewContainer . parentNode )
2893+ expect ( preview . parentNode )
29512894 . withContext ( 'Expected preview to be in the DOM mid-way through the transition' )
29522895 . toBeTruthy ( ) ;
29532896
29542897 tick ( 500 ) ;
29552898
2956- expect ( previewContainer . parentNode )
2899+ expect ( preview . parentNode )
29572900 . withContext ( 'Expected preview to be removed from the DOM if the transition timed out' )
29582901 . toBeFalsy ( ) ;
29592902 } ) ) ;
@@ -3057,7 +3000,6 @@ describe('CdkDrag', () => {
30573000 startDraggingViaMouse ( fixture , item ) ;
30583001
30593002 const preview = document . querySelector ( '.cdk-drag-preview' ) ! as HTMLElement ;
3060- const previewContainer = document . querySelector ( '.cdk-drag-preview-container' ) as HTMLElement ;
30613003 preview . style . transition = 'opacity 500ms ease' ;
30623004
30633005 dispatchMouseEvent ( document , 'mousemove' , 50 , 50 ) ;
@@ -3067,8 +3009,8 @@ describe('CdkDrag', () => {
30673009 fixture . detectChanges ( ) ;
30683010 tick ( 0 ) ;
30693011
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' )
30723014 . toBeFalsy ( ) ;
30733015 } ) ) ;
30743016
@@ -3080,7 +3022,6 @@ describe('CdkDrag', () => {
30803022 startDraggingViaMouse ( fixture , item ) ;
30813023
30823024 const preview = document . querySelector ( '.cdk-drag-preview' ) ! as HTMLElement ;
3083- const previewContainer = document . querySelector ( '.cdk-drag-preview-container' ) as HTMLElement ;
30843025 preview . style . transition = 'opacity 500ms ease, transform 1000ms ease' ;
30853026
30863027 dispatchMouseEvent ( document , 'mousemove' , 50 , 50 ) ;
@@ -3090,17 +3031,15 @@ describe('CdkDrag', () => {
30903031 fixture . detectChanges ( ) ;
30913032 tick ( 500 ) ;
30923033
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' )
30973036 . toBeTruthy ( ) ;
30983037
30993038 tick ( 1000 ) ;
31003039
3101- expect ( previewContainer . parentNode )
3040+ expect ( preview . parentNode )
31023041 . 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' ,
31043043 )
31053044 . toBeFalsy ( ) ;
31063045 } ) ) ;
@@ -3142,8 +3081,8 @@ describe('CdkDrag', () => {
31423081 const item = fixture . componentInstance . dragItems . toArray ( ) [ 1 ] . element . nativeElement ;
31433082
31443083 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 ) ;
31473086 } ) ) ;
31483087
31493088 it ( 'should insert the preview into the parent node if previewContainer is set to `parent`' , fakeAsync ( ( ) => {
@@ -3154,9 +3093,9 @@ describe('CdkDrag', () => {
31543093 const list = fixture . nativeElement . querySelector ( '.drop-list' ) ;
31553094
31563095 startDraggingViaMouse ( fixture , item ) ;
3157- const previewContainer = document . querySelector ( '.cdk-drag-preview-container ' ) as HTMLElement ;
3096+ const preview = document . querySelector ( '.cdk-drag-preview' ) as HTMLElement ;
31583097 expect ( list ) . toBeTruthy ( ) ;
3159- expect ( previewContainer . parentNode ) . toBe ( list ) ;
3098+ expect ( preview . parentNode ) . toBe ( list ) ;
31603099 } ) ) ;
31613100
31623101 it ( 'should insert the preview into a particular element, if specified' , fakeAsync ( ( ) => {
@@ -3170,10 +3109,8 @@ describe('CdkDrag', () => {
31703109 fixture . detectChanges ( ) ;
31713110
31723111 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 ) ;
31773114 } ) ) ;
31783115
31793116 it ( 'should remove the id from the placeholder' , fakeAsync ( ( ) => {
@@ -3685,17 +3622,15 @@ describe('CdkDrag', () => {
36853622
36863623 startDraggingViaMouse ( fixture , item ) ;
36873624
3688- const previewContainer = document . querySelector ( '.cdk-drag-preview-container ' ) as HTMLElement ;
3625+ const preview = document . querySelector ( '.cdk-drag-preview' ) as HTMLElement ;
36893626
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 ( ) ;
36933628 expect ( item . parentNode ) . withContext ( 'Expected drag item to be in the DOM' ) . toBeTruthy ( ) ;
36943629
36953630 fixture . destroy ( ) ;
36963631
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' )
36993634 . toBeFalsy ( ) ;
37003635 expect ( item . parentNode )
37013636 . withContext ( 'Expected drag item to be removed from the DOM' )
0 commit comments