Skip to content

Commit b21bca7

Browse files
authored
Merge branch 'master' into mdragnev/row-pinning-mdv
2 parents ea3c0ee + b08a4b7 commit b21bca7

File tree

1 file changed

+61
-29
lines changed

1 file changed

+61
-29
lines changed

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

Lines changed: 61 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('Row Pinning #grid', () => {
3232
IgxGridModule
3333
]
3434
})
35-
.compileComponents();
35+
.compileComponents();
3636
}));
3737

3838
describe('', () => {
@@ -73,7 +73,7 @@ describe('Row Pinning #grid', () => {
7373

7474
// 2 records pinned + 2px border
7575
expect(grid.pinnedRowHeight).toBe(2 * grid.renderedRowHeight + 2);
76-
const expectedHeight = parseInt(grid.height, 10) - grid.pinnedRowHeight - 18 - grid.theadRow.nativeElement.offsetHeight;
76+
const expectedHeight = parseInt(grid.height, 10) - grid.pinnedRowHeight - 18 - grid.theadRow.nativeElement.offsetHeight;
7777
expect(grid.calcHeight - expectedHeight).toBeLessThanOrEqual(1);
7878
});
7979

@@ -112,7 +112,7 @@ describe('Row Pinning #grid', () => {
112112

113113
// 2 records pinned + 2px border
114114
expect(grid.pinnedRowHeight).toBe(2 * grid.renderedRowHeight + 2);
115-
const expectedHeight = parseInt(grid.height, 10) - grid.pinnedRowHeight - 18 - grid.theadRow.nativeElement.offsetHeight;
115+
const expectedHeight = parseInt(grid.height, 10) - grid.pinnedRowHeight - 18 - grid.theadRow.nativeElement.offsetHeight;
116116
expect(grid.calcHeight - expectedHeight).toBeLessThanOrEqual(1);
117117
});
118118

@@ -197,31 +197,63 @@ describe('Row Pinning #grid', () => {
197197
});
198198

199199
it('should pin/unpin via row pinned setter.', () => {
200-
// pin 2nd row
201-
let row = grid.getRowByIndex(1);
202-
row.pinned = true;
203-
fix.detectChanges();
204-
205-
expect(grid.pinnedRows.length).toBe(1);
206-
let pinRowContainer = fix.debugElement.queryAll(By.css(FIXED_ROW_CONTAINER));
207-
expect(pinRowContainer.length).toBe(1);
208-
expect(pinRowContainer[0].children.length).toBe(1);
209-
expect(pinRowContainer[0].children[0].context.rowID).toBe(fix.componentInstance.data[1]);
210-
211-
expect(grid.getRowByIndex(0).rowID).toBe(fix.componentInstance.data[1]);
212-
expect(grid.getRowByIndex(1).rowID).toBe(fix.componentInstance.data[0]);
213-
214-
// unpin
215-
row = grid.getRowByIndex(0);
216-
row.pinned = false;
217-
fix.detectChanges();
218-
219-
expect(grid.pinnedRows.length).toBe(0);
220-
pinRowContainer = fix.debugElement.queryAll(By.css(FIXED_ROW_CONTAINER));
221-
expect(pinRowContainer.length).toBe(0);
222-
223-
expect(grid.getRowByIndex(0).rowID).toBe(fix.componentInstance.data[0]);
224-
expect(grid.getRowByIndex(1).rowID).toBe(fix.componentInstance.data[1]);
200+
// pin 2nd row
201+
let row = grid.getRowByIndex(1);
202+
row.pinned = true;
203+
fix.detectChanges();
204+
205+
expect(grid.pinnedRows.length).toBe(1);
206+
let pinRowContainer = fix.debugElement.queryAll(By.css(FIXED_ROW_CONTAINER));
207+
expect(pinRowContainer.length).toBe(1);
208+
expect(pinRowContainer[0].children.length).toBe(1);
209+
expect(pinRowContainer[0].children[0].context.rowID).toBe(fix.componentInstance.data[1]);
210+
211+
expect(grid.getRowByIndex(0).rowID).toBe(fix.componentInstance.data[1]);
212+
expect(grid.getRowByIndex(1).rowID).toBe(fix.componentInstance.data[0]);
213+
214+
// unpin
215+
row = grid.getRowByIndex(0);
216+
row.pinned = false;
217+
fix.detectChanges();
218+
219+
expect(grid.pinnedRows.length).toBe(0);
220+
pinRowContainer = fix.debugElement.queryAll(By.css(FIXED_ROW_CONTAINER));
221+
expect(pinRowContainer.length).toBe(0);
222+
223+
expect(grid.getRowByIndex(0).rowID).toBe(fix.componentInstance.data[0]);
224+
expect(grid.getRowByIndex(1).rowID).toBe(fix.componentInstance.data[1]);
225+
});
226+
227+
it('should pin rows when columns are grouped.', () => {
228+
// pin 1st and 2nd data row
229+
grid.pinRow(fix.componentInstance.data[0]);
230+
grid.pinRow(fix.componentInstance.data[1]);
231+
fix.detectChanges();
232+
233+
// group by string column
234+
grid.groupBy({
235+
fieldName: 'ContactTitle', dir: SortingDirection.Desc, ignoreCase: false
236+
});
237+
fix.detectChanges();
238+
239+
expect(grid.pinnedRows.length).toBe(2);
240+
241+
// verify rows
242+
const groupRows = grid.groupsRowList.toArray();
243+
const dataRows = grid.dataRowList.toArray();
244+
245+
expect(groupRows.length).toEqual(2);
246+
expect(dataRows.length).toEqual(7);
247+
expect(groupRows[0].groupRow.records[0].ID).toEqual('AROUT');
248+
249+
// pin 4th data row with ID:AROUT
250+
grid.pinRow(fix.componentInstance.data[3]);
251+
fix.detectChanges();
252+
253+
expect(grid.pinnedRows.length).toBe(3);
254+
255+
// make sure the pinned row is out of the first groupBy group
256+
expect(groupRows[0].groupRow.records[0].ID).toEqual('BLAUS');
225257
});
226258

227259
it('should apply sorting to both pinned and unpinned rows.', () => {
@@ -317,7 +349,7 @@ describe('Row Pinning #grid', () => {
317349

318350
it('should allow pinning added row.', () => {
319351

320-
grid.addRow({ 'ID': 'Test', 'CompanyName': 'Test'});
352+
grid.addRow({ 'ID': 'Test', 'CompanyName': 'Test' });
321353
fix.detectChanges();
322354

323355
grid.pinRow('Test');

0 commit comments

Comments
 (0)