Skip to content

feat(igxGrid): Row pinning + MRL integration (Adding tests) #6924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions projects/igniteui-angular/src/lib/grids/grid/row-pinning.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { configureTestSuite } from '../../test-utils/configure-suite';
import { ColumnPinningPosition, RowPinningPosition } from '../common/enums';
import { IPinningConfig } from '../common/grid.interface';
import { SampleTestData } from '../../test-utils/sample-test-data.spec';
import { verifyLayoutHeadersAreAligned, verifyDOMMatchesLayoutSettings } from '../../test-utils/helper-utils.spec';
import { GridFunctions } from '../../test-utils/grid-functions.spec';
import { SortingDirection } from '../../data-operations/sorting-expression.interface';
import { IgxGridTransaction } from '../tree-grid';
Expand All @@ -24,6 +25,7 @@ describe('Row Pinning #grid', () => {
TestBed.configureTestingModule({
declarations: [
GridRowPinningComponent,
GridRowPinningWithMRLComponent,
GridRowPinningWithMDVComponent,
GridRowPinningWithTransactionsComponent
],
Expand Down Expand Up @@ -389,6 +391,92 @@ describe('Row Pinning #grid', () => {
});

});
describe('Row pinning with MRL', () => {
beforeEach(fakeAsync(() => {
fix = TestBed.createComponent(GridRowPinningWithMRLComponent);
fix.detectChanges();
grid = fix.componentInstance.instance;
tick();
fix.detectChanges();
}));

it('should pin/unpin correctly to top', () => {
// pin
grid.pinRow(fix.componentInstance.data[1]);
fix.detectChanges();

expect(grid.pinnedRows.length).toBe(1);
const pinRowContainer = fix.debugElement.queryAll(By.css(FIXED_ROW_CONTAINER));
expect(pinRowContainer.length).toBe(1);
expect(pinRowContainer[0].children.length).toBe(1);
expect(pinRowContainer[0].children[0].context.rowID).toBe(fix.componentInstance.data[1]);
expect(pinRowContainer[0].children[0].nativeElement).toBe(grid.getRowByIndex(0).nativeElement);

expect(grid.getRowByIndex(0).pinned).toBeTruthy();
const gridPinnedRow = grid.pinnedRows[0];
const pinnedRowCells = gridPinnedRow.cells.toArray();
const headerCells = grid.headerGroups.first.children.toArray();

// headers are aligned to cells
verifyLayoutHeadersAreAligned(headerCells, pinnedRowCells);
verifyDOMMatchesLayoutSettings(gridPinnedRow, fix.componentInstance.colGroups);

// unpin
const row = grid.pinnedRows[0];
row.pinned = false;
fix.detectChanges();

expect(grid.pinnedRows.length).toBe(0);
expect(row.pinned).toBeFalsy();

const gridUnpinnedRow = grid.getRowByIndex(1);
const unpinnedRowCells = gridUnpinnedRow.cells.toArray();

verifyLayoutHeadersAreAligned(headerCells, unpinnedRowCells);
verifyDOMMatchesLayoutSettings(gridUnpinnedRow, fix.componentInstance.colGroups);
});

it('should pin/unpin correctly to bottom', () => {

fix.componentInstance.pinningConfig = { columns: ColumnPinningPosition.Start, rows: RowPinningPosition.Bottom };
fix.detectChanges();

// pin
grid.pinRow(fix.componentInstance.data[1]);
fix.detectChanges();

expect(grid.pinnedRows.length).toBe(1);
const pinRowContainer = fix.debugElement.queryAll(By.css(FIXED_ROW_CONTAINER));
expect(pinRowContainer.length).toBe(1);
expect(pinRowContainer[0].children.length).toBe(1);
expect(pinRowContainer[0].children[0].context.rowID).toBe(fix.componentInstance.data[1]);
expect(pinRowContainer[0].children[0].nativeElement)
.toBe(grid.getRowByIndex(fix.componentInstance.data.length - 1).nativeElement);

expect(grid.getRowByIndex(fix.componentInstance.data.length - 1).pinned).toBeTruthy();
const gridPinnedRow = grid.pinnedRows[0];
const pinnedRowCells = gridPinnedRow.cells.toArray();
const headerCells = grid.headerGroups.first.children.toArray();

// headers are aligned to cells
verifyLayoutHeadersAreAligned(headerCells, pinnedRowCells);
verifyDOMMatchesLayoutSettings(gridPinnedRow, fix.componentInstance.colGroups);

// unpin
const row = grid.pinnedRows[0];
row.pinned = false;
fix.detectChanges();

expect(grid.pinnedRows.length).toBe(0);
expect(row.pinned).toBeFalsy();

const gridUnpinnedRow = grid.getRowByIndex(1);
const unpinnedRowCells = gridUnpinnedRow.cells.toArray();

verifyLayoutHeadersAreAligned(headerCells, unpinnedRowCells);
verifyDOMMatchesLayoutSettings(gridUnpinnedRow, fix.componentInstance.colGroups);
});
});
});

@Component({
Expand All @@ -410,6 +498,32 @@ export class GridRowPinningComponent {
public instance: IgxGridComponent;
}

@Component({
template: `
<igx-grid [data]="data" height="500px" [pinning]='pinningConfig'>
<igx-column-layout *ngFor='let group of colGroups'>
<igx-column *ngFor='let col of group.columns'
[rowStart]="col.rowStart" [colStart]="col.colStart" [width]='col.width'
[colEnd]="col.colEnd" [rowEnd]="col.rowEnd" [field]='col.field'></igx-column>
</igx-column-layout>
</igx-grid>
`
})
export class GridRowPinningWithMRLComponent extends GridRowPinningComponent {
cols: Array<any> = [
{ field: 'ID', rowStart: 1, colStart: 1 },
{ field: 'CompanyName', rowStart: 1, colStart: 2 },
{ field: 'ContactName', rowStart: 1, colStart: 3 },
{ field: 'ContactTitle', rowStart: 2, colStart: 1, rowEnd: 4, colEnd: 4 },
];
colGroups = [
{
group: 'group1',
columns: this.cols
}
];
}

@Component({
template: `
<igx-grid
Expand Down