1- import { Component , ViewChild , DebugElement , QueryList } from '@angular/core' ;
1+ import { Component , ViewChild , DebugElement , QueryList , TemplateRef } from '@angular/core' ;
22import { TestBed , ComponentFixture , fakeAsync , tick } from '@angular/core/testing' ;
33import { FormsModule } from '@angular/forms' ;
44import { By } from '@angular/platform-browser' ;
@@ -420,10 +420,12 @@ describe('Row Drag Tests #grid', () => {
420420 ]
421421 } ) ;
422422 } ) ) ;
423- it ( 'should correctly create custom ghost element' , ( ) => {
423+ beforeEach ( fakeAsync ( ( ) => {
424424 fixture = TestBed . createComponent ( IgxGridRowCustomGhostDraggableComponent ) ;
425425 grid = fixture . componentInstance . instance ;
426426 fixture . detectChanges ( ) ;
427+ } ) ) ;
428+ it ( 'should correctly create custom ghost element' , ( ) => {
427429 dropAreaElement = fixture . debugElement . query ( By . css ( CSS_CLASS_DROPPABLE_AREA ) ) . nativeElement ;
428430 rows = grid . rowList . toArray ( ) ;
429431 dragIndicatorElements = fixture . debugElement . queryAll ( By . css ( CSS_CLASS_DRAG_INDICATOR ) ) ;
@@ -449,6 +451,42 @@ describe('Row Drag Tests #grid', () => {
449451
450452 const ghostText = document . getElementsByClassName ( CSS_CLASS_GHOST_ROW ) [ 0 ] . textContent ;
451453 expect ( ghostText ) . toEqual ( ' Moving a row! ' ) ;
454+ pointerUpEvent = UIInteractions . createPointerEvent ( 'pointerup' , dropPoint ) ;
455+ rowDragDirective . onPointerUp ( pointerUpEvent ) ;
456+ } ) ;
457+
458+ it ( 'should allow setting custom drag icon and ghost element via Input.' , ( ) => {
459+ dropAreaElement = fixture . debugElement . query ( By . css ( CSS_CLASS_DROPPABLE_AREA ) ) . nativeElement ;
460+ grid . dragIndicatorIconTemplate = fixture . componentInstance . rowDragTemplate ;
461+ grid . dragGhostCustomTemplate = fixture . componentInstance . rowDragGhostTemplate ;
462+ fixture . detectChanges ( ) ;
463+ rows = grid . rowList . toArray ( ) ;
464+ dragIndicatorElements = fixture . debugElement . queryAll ( By . css ( CSS_CLASS_DRAG_INDICATOR ) ) ;
465+ dragIndicatorElement = dragIndicatorElements [ 2 ] . nativeElement ;
466+ dragRows = fixture . debugElement . queryAll ( By . directive ( IgxRowDragDirective ) ) ;
467+ rowDragDirective = dragRows [ 1 ] . injector . get ( IgxRowDragDirective ) ;
468+
469+ expect ( dragIndicatorElement . textContent . trim ( ) ) . toBe ( 'expand_less' ) ;
470+
471+ startPoint = UIInteractions . getPointFromElement ( dragIndicatorElement ) ;
472+ movePoint = UIInteractions . getPointFromElement ( rows [ 4 ] . nativeElement ) ;
473+ dropPoint = UIInteractions . getPointFromElement ( dropAreaElement ) ;
474+ pointerDownEvent = UIInteractions . createPointerEvent ( 'pointerdown' , startPoint ) ;
475+ pointerMoveEvent = UIInteractions . createPointerEvent ( 'pointermove' , movePoint ) ;
476+
477+ rowDragDirective . onPointerDown ( pointerDownEvent ) ;
478+ rowDragDirective . onPointerMove ( pointerMoveEvent ) ;
479+ pointerMoveEvent = UIInteractions . createPointerEvent ( 'pointermove' , dropPoint ) ;
480+ rowDragDirective . onPointerMove ( pointerMoveEvent ) ;
481+ const ghostElements : HTMLCollection = document . getElementsByClassName ( CSS_CLASS_GHOST_ROW ) ;
482+ expect ( ghostElements . length ) . toEqual ( 1 ) ;
483+
484+ const ghostText = document . getElementsByClassName ( CSS_CLASS_GHOST_ROW ) [ 0 ] . textContent ;
485+ expect ( ghostText . trim ( ) ) . toEqual ( 'CUSTOM' ) ;
486+
487+ pointerUpEvent = UIInteractions . createPointerEvent ( 'pointerup' , dropPoint ) ;
488+ rowDragDirective . onPointerUp ( pointerUpEvent ) ;
489+
452490 } ) ;
453491 } ) ;
454492 } ) ;
@@ -751,7 +789,7 @@ describe('Row Drag Tests #grid', () => {
751789
752790 const ghostElements = document . getElementsByClassName ( CSS_CLASS_GHOST_ROW ) ;
753791 const ghostElement = ghostElements [ 0 ] ;
754- expect ( ghostElements . length ) . toEqual ( 2 ) ;
792+ expect ( ghostElements . length ) . toEqual ( 1 ) ;
755793 expect ( ghostElement . classList . contains ( CSS_CLASS_SELECTED_ROW ) ) . toBeFalsy ( ) ;
756794
757795 pointerMoveEvent = UIInteractions . createPointerEvent ( 'pointermove' , dropPoint ) ;
@@ -1228,12 +1266,27 @@ export class IgxGridRowDraggableComponent extends DataParent {
12281266 <div #nonDroppableArea class="non-droppable-area"
12291267 [ngStyle]="{width:'100px', height:'100px', backgroundColor:'yellow'}">
12301268 </div>
1269+
1270+ <ng-template #rowDragGhostTemplate let-data igxRowDragGhost>
1271+ <div class="dragGhost">
1272+ CUSTOM
1273+ </div>
1274+ </ng-template>
1275+ <ng-template #rowDragTemplate let-data igxDragIndicatorIcon>
1276+ <igx-icon>expand_less</igx-icon>
1277+ </ng-template>
12311278 `
12321279} )
12331280export class IgxGridRowCustomGhostDraggableComponent extends DataParent {
12341281 @ViewChild ( IgxGridComponent , { read : IgxGridComponent , static : true } )
12351282 public instance : IgxGridComponent ;
12361283
1284+ @ViewChild ( 'rowDragGhostTemplate' , { read : TemplateRef , static : true } )
1285+ public rowDragGhostTemplate : TemplateRef < any > ;
1286+
1287+ @ViewChild ( 'rowDragTemplate' , { read : TemplateRef , static : true } )
1288+ public rowDragTemplate : TemplateRef < any > ;
1289+
12371290 @ViewChild ( 'dropArea' , { read : IgxDropDirective , static : true } )
12381291 public dropArea : IgxDropDirective ;
12391292
0 commit comments