Skip to content

Commit 0938774

Browse files
committed
Merge remote-tracking branch 'origin/master' into mdragnev/row-pinning-summaries
2 parents f2bce44 + 383f9bf commit 0938774

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed

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

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { configureTestSuite } from '../../test-utils/configure-suite';
88
import { ColumnPinningPosition, RowPinningPosition } from '../common/enums';
99
import { IPinningConfig } from '../common/grid.interface';
1010
import { SampleTestData } from '../../test-utils/sample-test-data.spec';
11+
import { verifyLayoutHeadersAreAligned, verifyDOMMatchesLayoutSettings } from '../../test-utils/helper-utils.spec';
1112
import { GridFunctions } from '../../test-utils/grid-functions.spec';
1213
import { SortingDirection } from '../../data-operations/sorting-expression.interface';
1314
import { IgxGridTransaction } from '../tree-grid';
@@ -26,6 +27,7 @@ describe('Row Pinning #grid', () => {
2627
TestBed.configureTestingModule({
2728
declarations: [
2829
GridRowPinningComponent,
30+
GridRowPinningWithMRLComponent,
2931
GridRowPinningWithMDVComponent,
3032
GridRowPinningWithTransactionsComponent
3133
],
@@ -448,6 +450,92 @@ describe('Row Pinning #grid', () => {
448450
});
449451

450452
});
453+
describe('Row pinning with MRL', () => {
454+
beforeEach(fakeAsync(() => {
455+
fix = TestBed.createComponent(GridRowPinningWithMRLComponent);
456+
fix.detectChanges();
457+
grid = fix.componentInstance.instance;
458+
tick();
459+
fix.detectChanges();
460+
}));
461+
462+
it('should pin/unpin correctly to top', () => {
463+
// pin
464+
grid.pinRow(fix.componentInstance.data[1]);
465+
fix.detectChanges();
466+
467+
expect(grid.pinnedRows.length).toBe(1);
468+
const pinRowContainer = fix.debugElement.queryAll(By.css(FIXED_ROW_CONTAINER));
469+
expect(pinRowContainer.length).toBe(1);
470+
expect(pinRowContainer[0].children.length).toBe(1);
471+
expect(pinRowContainer[0].children[0].context.rowID).toBe(fix.componentInstance.data[1]);
472+
expect(pinRowContainer[0].children[0].nativeElement).toBe(grid.getRowByIndex(0).nativeElement);
473+
474+
expect(grid.getRowByIndex(0).pinned).toBeTruthy();
475+
const gridPinnedRow = grid.pinnedRows[0];
476+
const pinnedRowCells = gridPinnedRow.cells.toArray();
477+
const headerCells = grid.headerGroups.first.children.toArray();
478+
479+
// headers are aligned to cells
480+
verifyLayoutHeadersAreAligned(headerCells, pinnedRowCells);
481+
verifyDOMMatchesLayoutSettings(gridPinnedRow, fix.componentInstance.colGroups);
482+
483+
// unpin
484+
const row = grid.pinnedRows[0];
485+
row.pinned = false;
486+
fix.detectChanges();
487+
488+
expect(grid.pinnedRows.length).toBe(0);
489+
expect(row.pinned).toBeFalsy();
490+
491+
const gridUnpinnedRow = grid.getRowByIndex(1);
492+
const unpinnedRowCells = gridUnpinnedRow.cells.toArray();
493+
494+
verifyLayoutHeadersAreAligned(headerCells, unpinnedRowCells);
495+
verifyDOMMatchesLayoutSettings(gridUnpinnedRow, fix.componentInstance.colGroups);
496+
});
497+
498+
it('should pin/unpin correctly to bottom', () => {
499+
500+
fix.componentInstance.pinningConfig = { columns: ColumnPinningPosition.Start, rows: RowPinningPosition.Bottom };
501+
fix.detectChanges();
502+
503+
// pin
504+
grid.pinRow(fix.componentInstance.data[1]);
505+
fix.detectChanges();
506+
507+
expect(grid.pinnedRows.length).toBe(1);
508+
const pinRowContainer = fix.debugElement.queryAll(By.css(FIXED_ROW_CONTAINER));
509+
expect(pinRowContainer.length).toBe(1);
510+
expect(pinRowContainer[0].children.length).toBe(1);
511+
expect(pinRowContainer[0].children[0].context.rowID).toBe(fix.componentInstance.data[1]);
512+
expect(pinRowContainer[0].children[0].nativeElement)
513+
.toBe(grid.getRowByIndex(fix.componentInstance.data.length - 1).nativeElement);
514+
515+
expect(grid.getRowByIndex(fix.componentInstance.data.length - 1).pinned).toBeTruthy();
516+
const gridPinnedRow = grid.pinnedRows[0];
517+
const pinnedRowCells = gridPinnedRow.cells.toArray();
518+
const headerCells = grid.headerGroups.first.children.toArray();
519+
520+
// headers are aligned to cells
521+
verifyLayoutHeadersAreAligned(headerCells, pinnedRowCells);
522+
verifyDOMMatchesLayoutSettings(gridPinnedRow, fix.componentInstance.colGroups);
523+
524+
// unpin
525+
const row = grid.pinnedRows[0];
526+
row.pinned = false;
527+
fix.detectChanges();
528+
529+
expect(grid.pinnedRows.length).toBe(0);
530+
expect(row.pinned).toBeFalsy();
531+
532+
const gridUnpinnedRow = grid.getRowByIndex(1);
533+
const unpinnedRowCells = gridUnpinnedRow.cells.toArray();
534+
535+
verifyLayoutHeadersAreAligned(headerCells, unpinnedRowCells);
536+
verifyDOMMatchesLayoutSettings(gridUnpinnedRow, fix.componentInstance.colGroups);
537+
});
538+
});
451539
});
452540

453541
@Component({
@@ -469,6 +557,32 @@ export class GridRowPinningComponent {
469557
public instance: IgxGridComponent;
470558
}
471559

560+
@Component({
561+
template: `
562+
<igx-grid [data]="data" height="500px" [pinning]='pinningConfig'>
563+
<igx-column-layout *ngFor='let group of colGroups'>
564+
<igx-column *ngFor='let col of group.columns'
565+
[rowStart]="col.rowStart" [colStart]="col.colStart" [width]='col.width'
566+
[colEnd]="col.colEnd" [rowEnd]="col.rowEnd" [field]='col.field'></igx-column>
567+
</igx-column-layout>
568+
</igx-grid>
569+
`
570+
})
571+
export class GridRowPinningWithMRLComponent extends GridRowPinningComponent {
572+
cols: Array<any> = [
573+
{ field: 'ID', rowStart: 1, colStart: 1 },
574+
{ field: 'CompanyName', rowStart: 1, colStart: 2 },
575+
{ field: 'ContactName', rowStart: 1, colStart: 3 },
576+
{ field: 'ContactTitle', rowStart: 2, colStart: 1, rowEnd: 4, colEnd: 4 },
577+
];
578+
colGroups = [
579+
{
580+
group: 'group1',
581+
columns: this.cols
582+
}
583+
];
584+
}
585+
472586
@Component({
473587
template: `
474588
<igx-grid

0 commit comments

Comments
 (0)