@@ -4013,9 +4013,11 @@ describe('CdkDrag', () => {
40134013 const groups = fixture . componentInstance . groupedDragItems . slice ( ) ;
40144014 const element = groups [ 0 ] [ 1 ] . element . nativeElement ;
40154015 const dropInstances = fixture . componentInstance . dropInstances . toArray ( ) ;
4016- const targetRect = groups [ 1 ] [ 2 ] . element . nativeElement . getBoundingClientRect ( ) ;
4016+ const targetRect = groups [ 1 ] [ 1 ] . element . nativeElement . getBoundingClientRect ( ) ;
40174017
4018- dragElementViaMouse ( fixture , element , targetRect . left + 1 , targetRect . top + 1 ) ;
4018+ // Use coordinates of [1] item corresponding to [2] item
4019+ // after dragged item is removed from first container
4020+ dragElementViaMouse ( fixture , element , targetRect . left + 1 , targetRect . top ) ;
40194021 flush ( ) ;
40204022 fixture . detectChanges ( ) ;
40214023
@@ -4024,7 +4026,7 @@ describe('CdkDrag', () => {
40244026 expect ( event ) . toBeTruthy ( ) ;
40254027 expect ( event ) . toEqual ( {
40264028 previousIndex : 1 ,
4027- currentIndex : 3 ,
4029+ currentIndex : 2 , // dragged item should replace the [2] item (see comment above)
40284030 item : groups [ 0 ] [ 1 ] ,
40294031 container : dropInstances [ 1 ] ,
40304032 previousContainer : dropInstances [ 0 ] ,
@@ -4203,6 +4205,132 @@ describe('CdkDrag', () => {
42034205 expect ( fixture . componentInstance . droppedSpy ) . not . toHaveBeenCalled ( ) ;
42044206 } ) ) ;
42054207
4208+ it ( 'should update drop zone after element has entered' , fakeAsync ( ( ) => {
4209+ const fixture = createComponent ( ConnectedDropZones ) ;
4210+
4211+ // Make sure there's only one item in the first list.
4212+ fixture . componentInstance . todo = [ 'things' ] ;
4213+ fixture . detectChanges ( ) ;
4214+
4215+ const dropInstances = fixture . componentInstance . dropInstances . toArray ( ) ;
4216+ const groups = fixture . componentInstance . groupedDragItems ;
4217+ const dropZones = dropInstances . map ( d => d . element . nativeElement ) ;
4218+ const item = groups [ 0 ] [ 0 ] ;
4219+ const initialTargetZoneRect = dropZones [ 1 ] . getBoundingClientRect ( ) ;
4220+ const targetElement = groups [ 1 ] [ groups [ 1 ] . length - 1 ] . element . nativeElement ;
4221+ let targetRect = targetElement . getBoundingClientRect ( ) ;
4222+
4223+ startDraggingViaMouse ( fixture , item . element . nativeElement ) ;
4224+
4225+ const placeholder = dropZones [ 0 ] . querySelector ( '.cdk-drag-placeholder' ) ! ;
4226+
4227+ expect ( placeholder ) . toBeTruthy ( ) ;
4228+
4229+ dispatchMouseEvent ( document , 'mousemove' , targetRect . left + 1 , targetRect . top + 1 ) ;
4230+ fixture . detectChanges ( ) ;
4231+
4232+ expect ( targetElement . previousSibling === placeholder )
4233+ . toBe ( true , 'Expected placeholder to be inside second container before last item.' ) ;
4234+
4235+ // Update target rect
4236+ targetRect = targetElement . getBoundingClientRect ( ) ;
4237+ expect ( initialTargetZoneRect . bottom <= targetRect . top )
4238+ . toBe ( true , 'Expected target rect to be outside of initial target zone rect' ) ;
4239+
4240+ // Swap with target
4241+ dispatchMouseEvent ( document , 'mousemove' , targetRect . left + 1 , targetRect . bottom - 1 ) ;
4242+ fixture . detectChanges ( ) ;
4243+
4244+ // Drop and verify item drop positon and coontainer
4245+ dispatchMouseEvent ( document , 'mouseup' , targetRect . left + 1 , targetRect . bottom - 1 ) ;
4246+ flush ( ) ;
4247+ fixture . detectChanges ( ) ;
4248+
4249+ const event = fixture . componentInstance . droppedSpy . calls . mostRecent ( ) . args [ 0 ] ;
4250+
4251+ expect ( event ) . toBeTruthy ( ) ;
4252+ expect ( event ) . toEqual ( {
4253+ previousIndex : 0 ,
4254+ currentIndex : 3 ,
4255+ item : item ,
4256+ container : dropInstances [ 1 ] ,
4257+ previousContainer : dropInstances [ 0 ] ,
4258+ isPointerOverContainer : true ,
4259+ distance : { x : jasmine . any ( Number ) , y : jasmine . any ( Number ) }
4260+ } ) ;
4261+ } ) ) ;
4262+
4263+ it ( 'should enter as first child if entering from top' , fakeAsync ( ( ) => {
4264+ const fixture = createComponent ( ConnectedDropZones ) ;
4265+
4266+ // Make sure there's only one item in the first list.
4267+ fixture . componentInstance . todo = [ 'things' ] ;
4268+ fixture . detectChanges ( ) ;
4269+
4270+ const groups = fixture . componentInstance . groupedDragItems ;
4271+ const dropZones = fixture . componentInstance . dropInstances . map ( d => d . element . nativeElement ) ;
4272+ const item = groups [ 0 ] [ 0 ] ;
4273+
4274+ // Add some initial padding as the target drop zone
4275+ dropZones [ 1 ] . style . paddingTop = '10px' ;
4276+
4277+ const targetRect = dropZones [ 1 ] . getBoundingClientRect ( ) ;
4278+
4279+ startDraggingViaMouse ( fixture , item . element . nativeElement ) ;
4280+
4281+ const placeholder = dropZones [ 0 ] . querySelector ( '.cdk-drag-placeholder' ) ! ;
4282+
4283+ expect ( placeholder ) . toBeTruthy ( ) ;
4284+
4285+ expect ( dropZones [ 0 ] . contains ( placeholder ) )
4286+ . toBe ( true , 'Expected placeholder to be inside the first container.' ) ;
4287+
4288+ dispatchMouseEvent ( document , 'mousemove' , targetRect . left , targetRect . top ) ;
4289+ fixture . detectChanges ( ) ;
4290+
4291+ expect ( dropZones [ 1 ] . firstElementChild === placeholder )
4292+ . toBe ( true , 'Expected placeholder to be first child inside second container.' ) ;
4293+
4294+ dispatchMouseEvent ( document , 'mouseup' ) ;
4295+ } ) ) ;
4296+
4297+ it ( 'should enter as last child if entering from top in reversed container' , fakeAsync ( ( ) => {
4298+ const fixture = createComponent ( ConnectedDropZones ) ;
4299+
4300+ // Make sure there's only one item in the first list.
4301+ fixture . componentInstance . todo = [ 'things' ] ;
4302+ fixture . detectChanges ( ) ;
4303+
4304+ const groups = fixture . componentInstance . groupedDragItems ;
4305+ const dropZones = fixture . componentInstance . dropInstances . map ( d => d . element . nativeElement ) ;
4306+ const item = groups [ 0 ] [ 0 ] ;
4307+
4308+ // Add some initial padding as the target drop zone
4309+ const targetDropZoneStyle = dropZones [ 1 ] . style ;
4310+ targetDropZoneStyle . paddingTop = '10px' ;
4311+ targetDropZoneStyle . display = 'flex' ;
4312+ targetDropZoneStyle . flexDirection = 'column-reverse' ;
4313+
4314+ const targetRect = dropZones [ 1 ] . getBoundingClientRect ( ) ;
4315+
4316+ startDraggingViaMouse ( fixture , item . element . nativeElement ) ;
4317+
4318+ const placeholder = dropZones [ 0 ] . querySelector ( '.cdk-drag-placeholder' ) ! ;
4319+
4320+ expect ( placeholder ) . toBeTruthy ( ) ;
4321+
4322+ expect ( dropZones [ 0 ] . contains ( placeholder ) )
4323+ . toBe ( true , 'Expected placeholder to be inside the first container.' ) ;
4324+
4325+ dispatchMouseEvent ( document , 'mousemove' , targetRect . left , targetRect . top ) ;
4326+ fixture . detectChanges ( ) ;
4327+
4328+ expect ( dropZones [ 1 ] . lastChild === placeholder )
4329+ . toBe ( true , 'Expected placeholder to be last child inside second container.' ) ;
4330+
4331+ dispatchMouseEvent ( document , 'mouseup' ) ;
4332+ } ) ) ;
4333+
42064334 it ( 'should assign a default id on each drop zone' , fakeAsync ( ( ) => {
42074335 const fixture = createComponent ( ConnectedDropZones ) ;
42084336 fixture . detectChanges ( ) ;
0 commit comments