Skip to content

Commit 6acdfd1

Browse files
MKirovaMKirova
authored andcommitted
chore(*): Add and fix tests.
1 parent 8e3435f commit 6acdfd1

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

projects/igniteui-angular/src/lib/grids/grid-base.directive.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4071,7 +4071,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
40714071
this.cancelAddMode = false;
40724072
const isInPinnedArea = this.isRecordPinnedByViewIndex(index);
40734073
const pinIndex = this.pinnedRecords.findIndex(x => x[this.primaryKey] === rowID);
4074-
const unpinIndex = this.unpinnedRecords.findIndex(x => x[this.primaryKey] === rowID);
4074+
const unpinIndex = this.getUnpinnedIndexById(rowID);
40754075

40764076
if (this.expansionStates.get(rowID)) {
40774077
this.collapseRow(rowID);
@@ -6606,6 +6606,10 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
66066606
return this.dataView.findIndex(data => data === rec);
66076607
}
66086608

6609+
protected getUnpinnedIndexById(id) {
6610+
return this.unpinnedRecords.findIndex(x => x[this.primaryKey] === id);
6611+
}
6612+
66096613
/**
66106614
* @hidden
66116615
*/

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { By } from '@angular/platform-browser';
1212
import { IgxActionStripComponent } from '../../action-strip/action-strip.component';
1313
import { IgxActionStripModule } from '../../action-strip/action-strip.module';
1414
import { UIInteractions } from '../../test-utils/ui-interactions.spec';
15+
import { IgxGridRowComponent } from './grid-row.component';
1516

1617
describe('IgxGrid - Row Adding #grid', () => {
1718
let fixture;
@@ -111,5 +112,50 @@ describe('IgxGrid - Row Adding #grid', () => {
111112
expect(grid.getRowByIndex(1).addRow).toBeFalse();
112113
});
113114

115+
it('Should allow adding row from pinned row.', () => {
116+
let row = grid.getRowByIndex(0);
117+
row.pin();
118+
fixture.detectChanges();
119+
expect(grid.pinnedRecords.length).toBe(1);
120+
121+
row = grid.getRowByIndex(0);
122+
row.beginAddRow();
123+
fixture.detectChanges();
124+
125+
//add row should be pinned
126+
const addRow = grid.getRowByIndex(1) as IgxGridRowComponent;
127+
expect(addRow.addRow).toBe(true);
128+
expect(grid.pinnedRows[1]).toBe(addRow);
129+
130+
grid.endEdit(true);
131+
fixture.detectChanges();
132+
133+
// added record should be pinned.
134+
expect(grid.pinnedRecords.length).toBe(2);
135+
expect(grid.pinnedRecords[1]).toBe(grid.data[grid.data.length - 1]);
136+
137+
});
138+
it('Should allow adding row from ghost row.', () => {
139+
let row = grid.getRowByIndex(0);
140+
row.pin();
141+
fixture.detectChanges();
142+
expect(grid.pinnedRecords.length).toBe(1);
143+
144+
const ghostRow = grid.getRowByIndex(1);
145+
ghostRow.beginAddRow();
146+
fixture.detectChanges();
147+
148+
//add row should be unpinned
149+
const addRow = grid.getRowByIndex(2);
150+
expect(addRow.addRow).toBe(true);
151+
expect(grid.pinnedRows.length).toBe(1);
152+
153+
grid.endEdit(true);
154+
fixture.detectChanges();
155+
156+
// added record should be unpinned.
157+
expect(grid.pinnedRecords.length).toBe(1);
158+
expect(grid.unpinnedRecords[grid.unpinnedRecords.length - 1]).toBe(grid.data[grid.data.length - 1]);
159+
});
114160
});
115161
});

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,10 @@ export class IgxTreeGridComponent extends IgxGridBaseDirective implements GridTy
439439
return this.dataView.findIndex(x => x.data === rec);
440440
}
441441

442+
protected getUnpinnedIndexById(id) {
443+
return this.unpinnedRecords.findIndex(x => x.data[this.primaryKey] === id);
444+
}
445+
442446
private cloneMap(mapIn: Map<any, boolean>): Map<any, boolean> {
443447
const mapCloned: Map<any, boolean> = new Map<any, boolean>();
444448

0 commit comments

Comments
 (0)