Skip to content

Commit e53ca5b

Browse files
committed
test(IgxGrid): new column is added to the correct position #8294
1 parent 524a6a5 commit e53ca5b

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

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

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { IgxGridComponent } from './grid.component';
55
import { IgxGridModule } from './public_api';
66
import { GridTemplateStrings, ColumnDefinitions } from '../../test-utils/template-strings.spec';
77
import { SampleTestData } from '../../test-utils/sample-test-data.spec';
8-
import { ColumnHiddenFromMarkupComponent, ColumnCellFormatterComponent, DynamicColumnsComponent } from '../../test-utils/grid-samples.spec';
8+
import { ColumnHiddenFromMarkupComponent, ColumnCellFormatterComponent, DynamicColumnsComponent, GridAddColumnComponent } from '../../test-utils/grid-samples.spec';
99
import { configureTestSuite } from '../../test-utils/configure-suite';
1010
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
1111
import { IgxStringFilteringOperand } from '../../data-operations/filtering-condition';
@@ -27,7 +27,8 @@ describe('IgxGrid - Column properties #grid', () => {
2727
ColumnCellFormatterComponent,
2828
ColumnHaederClassesComponent,
2929
ColumnHiddenFromMarkupComponent,
30-
DynamicColumnsComponent
30+
DynamicColumnsComponent,
31+
GridAddColumnComponent
3132
],
3233
imports: [IgxGridModule, NoopAnimationsModule]
3334
})
@@ -167,6 +168,36 @@ describe('IgxGrid - Column properties #grid', () => {
167168
expect(grid.columnList.last.field).toMatch('Name');
168169
}));
169170

171+
it('should add new column at the correct visible index', fakeAsync(() => {
172+
const fix = TestBed.createComponent(GridAddColumnComponent);
173+
fix.detectChanges();
174+
const grid = fix.componentInstance.grid;
175+
const maxVindex = fix.componentInstance.columns.length - 1;
176+
177+
// add to unpinned area
178+
fix.componentInstance.columns.push({ field: 'City', width: 150, movable: true, type: 'string' });
179+
fix.detectChanges();
180+
181+
let cityCol = grid.getColumnByName('City');
182+
expect(cityCol.visibleIndex).toEqual(maxVindex + 1);
183+
184+
// remove the newly added column
185+
fix.componentInstance.columns.pop();
186+
fix.detectChanges();
187+
188+
cityCol = grid.getColumnByName('City');
189+
expect(cityCol).not.toBeDefined();
190+
191+
// add to pinned area
192+
fix.componentInstance.columns.push({ field: 'City', width: 150, movable: true, type: 'string', pinned: true });
193+
fix.detectChanges();
194+
195+
fix.detectChanges();
196+
197+
cityCol = grid.getColumnByName('City');
198+
expect(cityCol.visibleIndex).toEqual( 1);
199+
}));
200+
170201
it('should apply columnWidth on columns that don\'t have explicit width', () => {
171202
const fix = TestBed.createComponent(ColumnCellFormatterComponent);
172203
fix.componentInstance.grid.columnWidth = '200px';

projects/igniteui-angular/src/lib/test-utils/grid-samples.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,33 @@ export class ColumnHiddenFromMarkupComponent extends BasicGridComponent {
121121
data = SampleTestData.personIDNameData();
122122
}
123123

124+
@Component({
125+
template: `
126+
<igx-grid #grid1 [data]="data" [columnPinning]='true' [width]="'900px'" [height]="'600px'">
127+
<igx-column *ngFor="let c of columns" [field]="c.field"
128+
[header]="c.field"
129+
[movable]="c.movable"
130+
[width]="c.width"
131+
[editable]="true"
132+
[pinned]="c.pinned"
133+
[dataType]="c.type">
134+
</igx-column>
135+
</igx-grid>
136+
`
137+
})
138+
export class GridAddColumnComponent extends BasicGridComponent implements OnInit {
139+
public columns: Array<any>;
140+
data = SampleTestData.contactInfoDataFull()
141+
public ngOnInit(): void {
142+
this.columns = [
143+
{ field: 'ID', width: 150, movable: true, type: 'string', pinned: true },
144+
{ field: 'CompanyName', width: 150, movable: true, type: 'string'},
145+
{ field: 'ContactName', width: 150, movable: true, type: 'string' },
146+
{ field: 'ContactTitle', width: 150, movable: true, type: 'string' },
147+
{ field: 'Address', width: 150, movable: true, type: 'string' }];
148+
}
149+
}
150+
124151
@Component({
125152
template: GridTemplateStrings.declareGrid('', '',
126153
ColumnDefinitions.idNameFormatter)

0 commit comments

Comments
 (0)