@@ -5,7 +5,8 @@ import { IgxGridComponent } from './grid.component';
55import { IgxGridModule } from './public_api' ;
66import { GridTemplateStrings , ColumnDefinitions } from '../../test-utils/template-strings.spec' ;
77import { SampleTestData } from '../../test-utils/sample-test-data.spec' ;
8- import { ColumnHiddenFromMarkupComponent , ColumnCellFormatterComponent , DynamicColumnsComponent } from '../../test-utils/grid-samples.spec' ;
8+ import { ColumnHiddenFromMarkupComponent , ColumnCellFormatterComponent ,
9+ DynamicColumnsComponent , GridAddColumnComponent } from '../../test-utils/grid-samples.spec' ;
910import { configureTestSuite } from '../../test-utils/configure-suite' ;
1011import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
1112import { IgxStringFilteringOperand } from '../../data-operations/filtering-condition' ;
@@ -27,7 +28,8 @@ describe('IgxGrid - Column properties #grid', () => {
2728 ColumnCellFormatterComponent ,
2829 ColumnHaederClassesComponent ,
2930 ColumnHiddenFromMarkupComponent ,
30- DynamicColumnsComponent
31+ DynamicColumnsComponent ,
32+ GridAddColumnComponent
3133 ] ,
3234 imports : [ IgxGridModule , NoopAnimationsModule ]
3335 } )
@@ -167,6 +169,34 @@ describe('IgxGrid - Column properties #grid', () => {
167169 expect ( grid . columnList . last . field ) . toMatch ( 'Name' ) ;
168170 } ) ) ;
169171
172+ it ( 'should add new column at the correct visible index' , fakeAsync ( ( ) => {
173+ const fix = TestBed . createComponent ( GridAddColumnComponent ) ;
174+ fix . detectChanges ( ) ;
175+ const grid = fix . componentInstance . grid ;
176+ const maxVindex = fix . componentInstance . columns . length - 1 ;
177+
178+ // add to unpinned area
179+ fix . componentInstance . columns . push ( { field : 'City' , width : 150 , movable : true , type : 'string' } ) ;
180+ fix . detectChanges ( ) ;
181+
182+ let cityCol = grid . getColumnByName ( 'City' ) ;
183+ expect ( cityCol . visibleIndex ) . toEqual ( maxVindex + 1 ) ;
184+
185+ // remove the newly added column
186+ fix . componentInstance . columns . pop ( ) ;
187+ fix . detectChanges ( ) ;
188+
189+ cityCol = grid . getColumnByName ( 'City' ) ;
190+ expect ( cityCol ) . not . toBeDefined ( ) ;
191+
192+ // add to pinned area
193+ fix . componentInstance . columns . push ( { field : 'City' , width : 150 , movable : true , type : 'string' , pinned : true } ) ;
194+ fix . detectChanges ( ) ;
195+
196+ cityCol = grid . getColumnByName ( 'City' ) ;
197+ expect ( cityCol . visibleIndex ) . toEqual ( 1 ) ;
198+ } ) ) ;
199+
170200 it ( 'should apply columnWidth on columns that don\'t have explicit width' , ( ) => {
171201 const fix = TestBed . createComponent ( ColumnCellFormatterComponent ) ;
172202 fix . componentInstance . grid . columnWidth = '200px' ;
0 commit comments