Skip to content

Commit 787d1c4

Browse files
committed
Merge branch 'master' of https://github.com/IgniteUI/igniteui-angular into nrobakova/refactor-tests-helpers
2 parents 5906030 + 4f5c2c2 commit 787d1c4

File tree

4 files changed

+179
-49
lines changed

4 files changed

+179
-49
lines changed

projects/igniteui-angular/src/lib/grids/grid/row-pinning.spec.ts renamed to projects/igniteui-angular/src/lib/grids/grid/grid-row-pinning.spec.ts

Lines changed: 69 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DebugElement, ViewChild, Component } from '@angular/core';
1+
import { ViewChild, Component } from '@angular/core';
22
import { TestBed, async, fakeAsync, tick } from '@angular/core/testing';
33
import { By } from '@angular/platform-browser';
44
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
@@ -364,7 +364,7 @@ describe('Row Pinning #grid', () => {
364364
let pinRowContainer = fix.debugElement.queryAll(By.css(FIXED_ROW_CONTAINER));
365365
expect(pinRowContainer.length).toBe(1);
366366

367-
let expectedHeight = parseInt(grid.height, 10) - grid.pinnedRowHeight - 18 - grid.theadRow.nativeElement.offsetHeight;
367+
let expectedHeight = parseInt(grid.height, 10) - grid.pinnedRowHeight - 18 - grid.theadRow.nativeElement.offsetHeight;
368368
expect(grid.calcHeight - expectedHeight).toBeLessThanOrEqual(1);
369369

370370
grid.filter('ID', 'B', IgxStringFilteringOperand.instance().condition('startsWith'), false);
@@ -374,7 +374,7 @@ describe('Row Pinning #grid', () => {
374374
expect(pinRowContainer.length).toBe(0);
375375

376376
expect(grid.pinnedRowHeight).toBe(0);
377-
expectedHeight = parseInt(grid.height, 10) - grid.pinnedRowHeight - 18 - grid.theadRow.nativeElement.offsetHeight;
377+
expectedHeight = parseInt(grid.height, 10) - grid.pinnedRowHeight - 18 - grid.theadRow.nativeElement.offsetHeight;
378378
expect(grid.calcHeight - expectedHeight).toBeLessThanOrEqual(1);
379379
});
380380

@@ -401,47 +401,6 @@ describe('Row Pinning #grid', () => {
401401
expect(gridFilterData[1].ID).toBe('BERGS');
402402
});
403403

404-
it('should page through unpinned collection with modified pageSize = pageSize - pinnedRows.lenght.', () => {
405-
// pin 2nd row
406-
grid.paging = true;
407-
grid.perPage = 5;
408-
fix.detectChanges();
409-
const paginator = fix.debugElement.query(By.directive(IgxPaginatorComponent));
410-
expect(paginator.componentInstance.totalPages).toEqual(6);
411-
412-
grid.getRowByIndex(1).pin();
413-
fix.detectChanges();
414-
415-
expect(grid.pinnedRows.length).toBe(1);
416-
let pinRowContainer = fix.debugElement.queryAll(By.css(FIXED_ROW_CONTAINER));
417-
expect(pinRowContainer.length).toBe(1);
418-
expect(grid.dataView.length).toBe(5);
419-
expect(paginator.componentInstance.totalPages).toEqual(6);
420-
421-
grid.getRowByIndex(3).pin();
422-
fix.detectChanges();
423-
424-
expect(grid.pinnedRows.length).toBe(2);
425-
pinRowContainer = fix.debugElement.queryAll(By.css(FIXED_ROW_CONTAINER));
426-
expect(pinRowContainer.length).toBe(1);
427-
expect(grid.dataView.length).toBe(5);
428-
expect(paginator.componentInstance.totalPages).toEqual(6);
429-
430-
// unpin
431-
grid.getRowByIndex(0).unpin();
432-
fix.detectChanges();
433-
434-
grid.getRowByIndex(0).unpin();
435-
fix.detectChanges();
436-
437-
expect(grid.pinnedRows.length).toBe(0);
438-
pinRowContainer = fix.debugElement.queryAll(By.css(FIXED_ROW_CONTAINER));
439-
expect(pinRowContainer.length).toBe(0);
440-
441-
expect(grid.dataView.length).toBe(5);
442-
expect(paginator.componentInstance.totalPages).toEqual(6);
443-
});
444-
445404
it('should apply sorting to both pinned and unpinned rows.', () => {
446405
grid.getRowByIndex(1).pin();
447406
grid.getRowByIndex(5).pin();
@@ -462,6 +421,7 @@ describe('Row Pinning #grid', () => {
462421
expect(grid.getRowByIndex(2).rowID).toBe(fix.componentInstance.data[lastIndex]);
463422
});
464423
});
424+
465425
describe('Row pinning with Master Detail View', () => {
466426
beforeEach(fakeAsync(() => {
467427
fix = TestBed.createComponent(GridRowPinningWithMDVComponent);
@@ -563,6 +523,62 @@ describe('Row Pinning #grid', () => {
563523
});
564524
});
565525

526+
describe('Paging', () => {
527+
let paginator: IgxPaginatorComponent;
528+
529+
beforeEach(fakeAsync(() => {
530+
fix = TestBed.createComponent(GridRowPinningComponent);
531+
fix.componentInstance.createSimpleData(12);
532+
grid = fix.componentInstance.instance;
533+
grid.paging = true;
534+
grid.perPage = 5;
535+
536+
fix.detectChanges();
537+
tick();
538+
539+
paginator = fix.debugElement.query(By.directive(IgxPaginatorComponent)).componentInstance;
540+
}));
541+
542+
it('should correctly apply paging state for grid and paginator when there are pinned rows.', () => {
543+
// pin the first row
544+
grid.getRowByIndex(0).pin();
545+
fix.detectChanges();
546+
547+
expect(grid.rowList.length).toEqual(6);
548+
expect(grid.perPage).toEqual(5);
549+
expect(paginator.perPage).toEqual(5);
550+
expect(paginator.totalRecords).toEqual(12);
551+
expect(paginator.totalPages).toEqual(3);
552+
553+
// pin the second row
554+
grid.getRowByIndex(2).pin();
555+
fix.detectChanges();
556+
557+
expect(grid.rowList.length).toEqual(7);
558+
expect(grid.perPage).toEqual(5);
559+
expect(paginator.perPage).toEqual(5);
560+
expect(paginator.totalRecords).toEqual(12);
561+
expect(paginator.totalPages).toEqual(3);
562+
});
563+
564+
it('should have the correct records shown for pages with pinned rows', () => {
565+
grid.getRowByIndex(0).pin();
566+
grid.getRowByIndex(1).pin();
567+
fix.detectChanges();
568+
569+
let rows = grid.rowList.toArray();
570+
571+
[1, 2, 1, 2, 3, 4, 5].forEach((x, index) => expect(rows[index].cells.first.value).toEqual(x));
572+
573+
grid.paginate(2);
574+
fix.detectChanges();
575+
576+
rows = grid.rowList.toArray();
577+
578+
[1, 2, 11, 12].forEach((x, index) => expect(rows[index].cells.first.value).toEqual(x));
579+
});
580+
});
581+
566582
describe(' Editing ', () => {
567583
beforeEach(fakeAsync(() => {
568584
fix = TestBed.createComponent(GridRowPinningWithTransactionsComponent);
@@ -641,6 +657,7 @@ describe('Row Pinning #grid', () => {
641657
});
642658

643659
});
660+
644661
describe('Row pinning with MRL', () => {
645662
beforeEach(fakeAsync(() => {
646663
fix = TestBed.createComponent(GridRowPinningWithMRLComponent);
@@ -727,6 +744,7 @@ describe('Row Pinning #grid', () => {
727744
GridFunctions.verifyDOMMatchesLayoutSettings(gridUnpinnedRow, fix.componentInstance.colGroups);
728745
});
729746
});
747+
730748
describe(' Hiding', () => {
731749
beforeEach(fakeAsync(() => {
732750
fix = TestBed.createComponent(GridRowPinningComponent);
@@ -788,11 +806,15 @@ describe('Row Pinning #grid', () => {
788806
`
789807
})
790808
export class GridRowPinningComponent {
791-
public data = SampleTestData.contactInfoDataFull();
809+
public data: any[] = SampleTestData.contactInfoDataFull();
792810
public pinningConfig: IPinningConfig = { columns: ColumnPinningPosition.Start, rows: RowPinningPosition.Top };
793811

794812
@ViewChild(IgxGridComponent, { read: IgxGridComponent, static: true })
795813
public instance: IgxGridComponent;
814+
815+
public createSimpleData(count: number) {
816+
this.data = Array(count).fill({}).map((x, idx) => x = { 'idx': idx + 1 });
817+
}
796818
}
797819

798820
@Component({
@@ -838,7 +860,7 @@ export class GridRowPinningWithMRLComponent extends GridRowPinningComponent {
838860
</ng-template>
839861
</igx-grid>`
840862
})
841-
export class GridRowPinningWithMDVComponent extends GridRowPinningComponent {}
863+
export class GridRowPinningWithMDVComponent extends GridRowPinningComponent { }
842864

843865

844866
@Component({
@@ -854,4 +876,4 @@ export class GridRowPinningWithMDVComponent extends GridRowPinningComponent {}
854876
`,
855877
providers: [{ provide: IgxGridTransaction, useClass: IgxTransactionService }]
856878
})
857-
export class GridRowPinningWithTransactionsComponent extends GridRowPinningComponent {}
879+
export class GridRowPinningWithTransactionsComponent extends GridRowPinningComponent { }

projects/igniteui-angular/src/lib/grids/grid/grid.pipes.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class IgxGridSortingPipe implements PipeTransform {
2929
}
3030

3131
public transform(collection: any[], expressions: ISortingExpression[], sorting: IGridSortingStrategy,
32-
id: string, pipeTrigger: number, pinned?): any[] {
32+
id: string, pipeTrigger: number, pinned?): any[] {
3333
const grid = this.gridAPI.grid;
3434
let result: any[];
3535

@@ -151,4 +151,3 @@ export class IgxGridFilteringPipe implements PipeTransform {
151151
return result;
152152
}
153153
}
154-

projects/igniteui-angular/src/lib/grids/hierarchical-grid/hierarchical-grid.integration.spec.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,5 +990,65 @@ describe('IgxHierarchicalGrid Integration #hGrid', () => {
990990
expect(gridFilterData[1].ID).toBe('11');
991991
expect(gridFilterData[2].ID).toBe('1');
992992
});
993+
994+
it('should correctly apply paging state for grid and paginator when there are pinned rows.', fakeAsync(() => {
995+
hierarchicalGrid.paging = true;
996+
hierarchicalGrid.perPage = 5;
997+
hierarchicalGrid.height = '700px';
998+
fixture.detectChanges();
999+
const paginator = fixture.debugElement.query(By.directive(IgxPaginatorComponent)).componentInstance;
1000+
// pin the first row
1001+
hierarchicalGrid.getRowByIndex(0).pin();
1002+
fixture.detectChanges();
1003+
1004+
expect(hierarchicalGrid.rowList.length).toEqual(6);
1005+
expect(hierarchicalGrid.perPage).toEqual(5);
1006+
expect(paginator.perPage).toEqual(5);
1007+
expect(paginator.totalRecords).toEqual(40);
1008+
expect(paginator.totalPages).toEqual(8);
1009+
1010+
// pin the second row
1011+
hierarchicalGrid.getRowByIndex(2).pin();
1012+
fixture.detectChanges();
1013+
1014+
expect(hierarchicalGrid.rowList.length).toEqual(7);
1015+
expect(hierarchicalGrid.perPage).toEqual(5);
1016+
expect(paginator.perPage).toEqual(5);
1017+
expect(paginator.totalRecords).toEqual(40);
1018+
expect(paginator.totalPages).toEqual(8);
1019+
1020+
// expand the first row
1021+
hierarchicalGrid.expandRow(hierarchicalGrid.dataRowList.first.rowID);
1022+
1023+
expect(hierarchicalGrid.rowList.length).toEqual(8);
1024+
expect(hierarchicalGrid.perPage).toEqual(5);
1025+
expect(paginator.perPage).toEqual(5);
1026+
expect(paginator.totalRecords).toEqual(40);
1027+
expect(paginator.totalPages).toEqual(8);
1028+
1029+
expect(hierarchicalGrid.rowList.toArray()[1] instanceof IgxChildGridRowComponent).toBeFalsy();
1030+
expect(hierarchicalGrid.rowList.toArray()[3] instanceof IgxChildGridRowComponent).toBeTruthy();
1031+
}));
1032+
1033+
it('should have the correct records shown for pages with pinned rows', () => {
1034+
hierarchicalGrid.paging = true;
1035+
hierarchicalGrid.perPage = 6;
1036+
hierarchicalGrid.height = '700px';
1037+
fixture.detectChanges();
1038+
hierarchicalGrid.getRowByIndex(0).pin();
1039+
hierarchicalGrid.getRowByIndex(1).pin();
1040+
fixture.detectChanges();
1041+
1042+
let rows = hierarchicalGrid.rowList.toArray();
1043+
1044+
[0, 1, 0, 1, 2, 3, 4].forEach((x, index) => expect(parseInt(rows[index].cells.first.value, 10)).toEqual(x));
1045+
1046+
hierarchicalGrid.paginate(6);
1047+
fixture.detectChanges();
1048+
1049+
rows = hierarchicalGrid.rowList.toArray();
1050+
1051+
[0, 1, 36, 37, 38, 39].forEach((x, index) => expect(parseInt(rows[index].cells.first.value, 10)).toEqual(x));
1052+
});
9931053
});
9941054
});

projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid-integration.spec.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { IgxNumberFilteringOperand, IgxStringFilteringOperand } from '../../data
2121
import { IgxHierarchicalTransactionService } from '../../services/transaction/igx-hierarchical-transaction';
2222
import { IgxGridTransaction } from '../grid-base.directive';
2323
import { IgxGridCellComponent } from '../grid';
24+
import { IgxPaginatorComponent } from '../../paginator/paginator.component';
2425

2526
const CSS_CLASS_BANNER = 'igx-banner';
2627
const CSS_CLASS_ROW_EDITED = 'igx-grid__tr--edited';
@@ -1572,6 +1573,54 @@ describe('IgxTreeGrid - Integration #tGrid', () => {
15721573
expect(treeGrid.dataView.length).toBe(10);
15731574
});
15741575

1576+
it('should correctly apply paging state for grid and paginator when there are pinned rows.', fakeAsync(() => {
1577+
treeGrid.paging = true;
1578+
treeGrid.perPage = 3;
1579+
treeGrid.height = '700px';
1580+
fix.detectChanges();
1581+
const paginator = fix.debugElement.query(By.directive(IgxPaginatorComponent)).componentInstance;
1582+
// pin the first row
1583+
treeGrid.getRowByIndex(0).pin();
1584+
fix.detectChanges();
1585+
1586+
expect(treeGrid.rowList.length).toEqual(4);
1587+
expect(treeGrid.perPage).toEqual(3);
1588+
expect(paginator.perPage).toEqual(3);
1589+
expect(paginator.totalRecords).toEqual(10);
1590+
expect(paginator.totalPages).toEqual(4);
1591+
1592+
// pin the second row
1593+
treeGrid.getRowByIndex(2).pin();
1594+
fix.detectChanges();
1595+
1596+
expect(treeGrid.rowList.length).toEqual(5);
1597+
expect(treeGrid.perPage).toEqual(3);
1598+
expect(paginator.perPage).toEqual(3);
1599+
expect(paginator.totalRecords).toEqual(10);
1600+
expect(paginator.totalPages).toEqual(4);
1601+
}));
1602+
1603+
it('should have the correct records shown for pages with pinned rows', () => {
1604+
treeGrid.paging = true;
1605+
treeGrid.perPage = 6;
1606+
treeGrid.height = '700px';
1607+
fix.detectChanges();
1608+
treeGrid.getRowByIndex(0).pin();
1609+
treeGrid.getRowByIndex(1).pin();
1610+
fix.detectChanges();
1611+
1612+
let rows = treeGrid.rowList.toArray();
1613+
1614+
[147, 475, 147, 475, 957, 317, 711, 998].forEach((x, index) => expect(parseInt(rows[index].cells.first.value, 10)).toEqual(x));
1615+
1616+
treeGrid.paginate(1);
1617+
fix.detectChanges();
1618+
1619+
rows = treeGrid.rowList.toArray();
1620+
1621+
[147, 475, 299, 19, 847, 663].forEach((x, index) => expect(parseInt(rows[index].cells.first.value, 10)).toEqual(x));
1622+
});
1623+
15751624
it('should make a correct selection', () => {
15761625
treeGrid.pinRow(147);
15771626
fix.detectChanges();

0 commit comments

Comments
 (0)