Skip to content

Commit 46ece50

Browse files
committed
test(row-drag): Adding ghostContext tests #6081
1 parent 3269511 commit 46ece50

File tree

1 file changed

+93
-2
lines changed

1 file changed

+93
-2
lines changed

Diff for: projects/igniteui-angular/src/lib/grids/grid/row-drag.directive.spec.ts

+93-2
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ describe('IgxGrid - Row Drag Tests #grid', () => {
392392
fixture.detectChanges();
393393
dragIndicatorElements = fixture.debugElement.queryAll(By.css('.' + CSS_CLASS_DRAG_INDICATOR));
394394
dragRows = fixture.debugElement.queryAll(By.directive(IgxRowDragDirective));
395+
const rowDragDirective = dragRows[1].injector.get(IgxRowDragDirective) as any;
395396
const dragIndicatorElement = dragIndicatorElements[2].nativeElement;
396397
const startPoint: Point = UIInteractions.getPointFromElement(dragIndicatorElement);
397398
const movePoint: Point = UIInteractions.getPointFromElement(rows[4].nativeElement);
@@ -404,6 +405,10 @@ describe('IgxGrid - Row Drag Tests #grid', () => {
404405
ghostElements = document.getElementsByClassName(CSS_CLASS_GHOST_ROW);
405406
expect(ghostElements.length).toEqual(1);
406407

408+
expect(rowDragDirective.ghostContext.data.ProductName).toEqual('NetAdvantage');
409+
expect(rowDragDirective.ghostContext.data.ID).toEqual(2);
410+
expect(rowDragDirective.ghostContext.grid).toEqual(grid);
411+
407412
const ghostText = document.getElementsByClassName(CSS_CLASS_GHOST_ROW)[0].textContent;
408413
expect(ghostText).toEqual(' Moving a row! ');
409414
}));
@@ -810,7 +815,7 @@ describe('IgxGrid - Row Drag Tests #grid', () => {
810815
dragRows = fixture.debugElement.queryAll(By.directive(IgxRowDragDirective));
811816
}));
812817

813-
it('should be able to drag row on every hiearchical level', (async () => {
818+
it('should be able to drag row on every hierarchical level', (async () => {
814819
// first level row
815820
let dragIndicatorElement: Element = dragIndicatorElements[1].nativeElement;
816821
let rowToDrag = dragGrid.getRowByIndex(0);
@@ -864,6 +869,41 @@ describe('IgxGrid - Row Drag Tests #grid', () => {
864869
await pointerUp(dragIndicatorElement, dropPoint, fixture);
865870
verifyRowDragEndEvent(nestedChildGrid, rowToDrag, rowDragDirective, false, 1);
866871
}));
872+
873+
it('should correctly create custom ghost element', (async () => {
874+
// first level row
875+
let dragIndicatorElement: Element = dragIndicatorElements[1].nativeElement;
876+
let rowToDrag = dragGrid.getRowByIndex(0);
877+
let rowDragDirective = dragRows[0].injector.get(IgxRowDragDirective) as any;
878+
879+
let startPoint: Point = UIInteractions.getPointFromElement(dragIndicatorElement);
880+
const movePoint: Point = UIInteractions.getPointFromElement(dragGrid.getRowByIndex(3).nativeElement);
881+
const dropPoint: Point = UIInteractions.getPointFromElement(dropAreaElement);
882+
883+
await pointerDown(dragIndicatorElement, startPoint, fixture);
884+
await pointerMove(dragIndicatorElement, movePoint, fixture);
885+
await pointerMove(dragIndicatorElement, dropPoint, fixture);
886+
await pointerUp(dragIndicatorElement, dropPoint, fixture);
887+
888+
expect(rowDragDirective.ghostContext.data.ProductName).toEqual('Product: A0');
889+
expect(rowDragDirective.ghostContext.grid).toEqual(dragGrid);
890+
891+
// second level row
892+
dragIndicatorElement = dragIndicatorElements[8].nativeElement;
893+
const childGrid = dragGrid.hgridAPI.getChildGrids(false)[0];
894+
rowToDrag = childGrid.getRowByIndex(0);
895+
rowDragDirective = dragRows[4].injector.get(IgxRowDragDirective);
896+
startPoint = UIInteractions.getPointFromElement(dragIndicatorElement);
897+
898+
await pointerDown(dragIndicatorElement, startPoint, fixture);
899+
await pointerMove(dragIndicatorElement, movePoint, fixture);
900+
await pointerMove(dragIndicatorElement, dropPoint, fixture);
901+
await pointerUp(dragIndicatorElement, dropPoint, fixture);
902+
903+
expect(rowDragDirective.ghostContext.data.ProductName).toEqual('Product: A0');
904+
expect(rowDragDirective.ghostContext.data.ChildLevels).toEqual(2);
905+
expect(rowDragDirective.ghostContext.grid).toEqual(childGrid);
906+
}));
867907
});
868908
describe('Tree Grid Tests', () => {
869909
let dragGrid: IgxTreeGridComponent;
@@ -880,7 +920,7 @@ describe('IgxGrid - Row Drag Tests #grid', () => {
880920
dragRows = fixture.debugElement.queryAll(By.directive(IgxRowDragDirective));
881921
}));
882922

883-
it('should be able to drag row on every hiearchical level', (async () => {
923+
it('should be able to drag row on every hierarchical level', (async () => {
884924
// first level row
885925
let dragIndicatorElement: Element = dragIndicatorElements[1].nativeElement;
886926
let rowToDrag = dragGrid.getRowByIndex(0);
@@ -1138,6 +1178,57 @@ export class IgxHierarchicalGridTestComponent {
11381178
}
11391179
}
11401180

1181+
@Component({
1182+
template: `
1183+
<igx-hierarchical-grid #hierarchicalDragGrid [data]="data"
1184+
[autoGenerate]="true" [height]="'500px'" [width]="'1500px'"
1185+
primaryKey="ID" [expandChildren]='true' [rowDraggable]="true">
1186+
<igx-row-island [key]="'childData'" [expandChildren]='true' [autoGenerate]="true" [rowDraggable]="true" #rowIsland>
1187+
<igx-row-island [key]="'childData2'" [autoGenerate]="true" [rowDraggable]="true" #rowIsland2 >
1188+
</igx-row-island>
1189+
<ng-template let-data igxRowDragGhost>
1190+
<div>
1191+
Moving {{data.ProductName}}!
1192+
</div>
1193+
</ng-template>
1194+
</igx-row-island>
1195+
<ng-template let-data igxRowDragGhost>
1196+
<div>
1197+
Moving {{data.ProductName}}!
1198+
</div>
1199+
</ng-template>
1200+
</igx-hierarchical-grid>`
1201+
})
1202+
export class IgxHierarchicalGridCustomGhostTestComponent {
1203+
public data;
1204+
newData = [];
1205+
@ViewChild('hierarchicalDragGrid', { read: IgxHierarchicalGridComponent, static: true }) public hDragGrid: IgxHierarchicalGridComponent;
1206+
@ViewChild('rowIsland', { read: IgxRowIslandComponent, static: true }) public rowIsland: IgxRowIslandComponent;
1207+
@ViewChild('rowIsland2', { read: IgxRowIslandComponent, static: true }) public rowIsland2: IgxRowIslandComponent;
1208+
1209+
constructor() {
1210+
this.data = this.generateData(2, 3);
1211+
}
1212+
generateData(count: number, level: number) {
1213+
const prods = [];
1214+
const currLevel = level;
1215+
let children;
1216+
for (let i = 0; i < count; i++) {
1217+
const item = {
1218+
ID: i, ChildLevels: currLevel, ProductName: 'Product: A' + i, 'Col1': i,
1219+
'Col2': i, 'Col3': i
1220+
};
1221+
if (currLevel > 1) {
1222+
children = this.generateData(count / 2, currLevel - 1);
1223+
const childProp = currLevel === 3 ? 'childData' : 'childData2';
1224+
item[childProp] = children;
1225+
}
1226+
prods.push(item);
1227+
}
1228+
return prods;
1229+
}
1230+
}
1231+
11411232
@Component({
11421233
template: `
11431234
<igx-tree-grid #treeGrid [data]="data" primaryKey="employeeID" foreignKey="PID" width="900px" height="500px" [rowDraggable]="true">

0 commit comments

Comments
 (0)