11import { async , TestBed , ComponentFixture , fakeAsync , tick } from '@angular/core/testing' ;
22import { IgxGridModule } from './grid.module' ;
33import { IgxGridComponent } from './grid.component' ;
4- import { Component , ViewChild , DebugElement , OnInit , TemplateRef } from '@angular/core' ;
4+ import { Component , ViewChild , DebugElement , OnInit , TemplateRef , ElementRef } from '@angular/core' ;
5+
56import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
67import { IgxColumnComponent , IgxColumnGroupComponent } from '../column.component' ;
78import { SortingDirection } from '../../data-operations/sorting-expression.interface' ;
@@ -17,7 +18,7 @@ const GRID_COL_GROUP_THEAD_TITLE_CLASS = 'igx-grid__thead-title';
1718const GRID_COL_GROUP_THEAD_GROUP_CLASS = 'igx-grid__thead-group' ;
1819const GRID_COL_THEAD_CLASS = '.igx-grid__th' ;
1920
20- describe ( 'IgxGrid - multi-column headers' , ( ) => {
21+ fdescribe ( 'IgxGrid - multi-column headers' , ( ) => {
2122 configureTestSuite ( ) ;
2223 beforeEach ( async ( ( ) => {
2324 TestBed . configureTestingModule ( {
@@ -38,7 +39,8 @@ describe('IgxGrid - multi-column headers', () => {
3839 NestedColumnGroupsGridComponent ,
3940 DynamicGridComponent ,
4041 NumberColWidthGridComponent ,
41- NestedColGroupsWithTemplatesGridComponent
42+ NestedColGroupsWithTemplatesGridComponent ,
43+ DynamicColGroupsGridComponent
4244 ] ,
4345 imports : [
4446 NoopAnimationsModule ,
@@ -1416,6 +1418,40 @@ describe('IgxGrid - multi-column headers', () => {
14161418 headerSpans = fixture . debugElement . queryAll ( By . css ( '.' + GRID_COL_GROUP_THEAD_TITLE_CLASS ) ) ;
14171419 expect ( headerSpans [ 1 ] . nativeElement . textContent ) . toBe ( 'Location' ) ;
14181420 } ) ) ;
1421+
1422+ it ( 'There shouldn\'t be any errors when dynamically removing a column group with filtering enabled' , ( ) => {
1423+ const fixture = TestBed . createComponent ( DynamicColGroupsGridComponent ) ;
1424+ fixture . detectChanges ( ) ;
1425+
1426+ const grid = fixture . componentInstance . grid ;
1427+ const button = fixture . componentInstance . removeBtn ;
1428+
1429+ let columnLength = grid . columnList . length ;
1430+ let firstColumnGroup = grid . columnList . first ;
1431+ let expectedColumnName = 'First' ;
1432+ let expectedColumnListLength = 10 ;
1433+
1434+ expect ( firstColumnGroup . header ) . toEqual ( expectedColumnName ) ;
1435+ expect ( expectedColumnListLength ) . toEqual ( columnLength ) ;
1436+
1437+ expect ( ( ) => {
1438+ // Delete first column group
1439+ button . nativeElement . dispatchEvent ( new Event ( 'click' ) ) ;
1440+ fixture . detectChanges ( ) ;
1441+
1442+ // Delete first column group
1443+ button . nativeElement . dispatchEvent ( new Event ( 'click' ) ) ;
1444+ fixture . detectChanges ( ) ;
1445+ } ) . not . toThrow ( ) ;
1446+
1447+ firstColumnGroup = grid . columnList . first ;
1448+ expectedColumnName = 'Third' ;
1449+ columnLength = grid . columnList . length ;
1450+ expectedColumnListLength = 3 ;
1451+
1452+ expect ( firstColumnGroup . header ) . toEqual ( expectedColumnName ) ;
1453+ expect ( expectedColumnListLength ) . toEqual ( columnLength ) ;
1454+ } ) ;
14191455} ) ;
14201456
14211457@Component ( {
@@ -1766,6 +1802,54 @@ export class NestedColGroupsGridComponent {
17661802 data = SampleTestData . contactInfoDataFull ( ) ;
17671803}
17681804
1805+ @Component ( {
1806+ template : `
1807+ <igx-grid [data]="data" [allowFiltering]="true">
1808+ <igx-column-group *ngFor="let colGroup of columnGroups" [header]="colGroup.columnHeader">
1809+ <igx-column *ngFor="let column of colGroup.columns" [field]="column.field" [dataType]="column.type"
1810+ [filterable]="true"></igx-column>
1811+ </igx-column-group>
1812+ </igx-grid>
1813+ <article>
1814+ <button #removeFirstColGroup (click)="removeFirstColumnGroup()">Remove first column group</button>
1815+ </article>
1816+ `
1817+ } )
1818+ export class DynamicColGroupsGridComponent {
1819+
1820+ @ViewChild ( IgxGridComponent , { static : true } )
1821+ public grid : IgxGridComponent ;
1822+
1823+ @ViewChild ( 'removeFirstColGroup' , { static : true } )
1824+ public removeBtn : ElementRef ;
1825+
1826+ public columnGroups : Array < any > ;
1827+ public data = SampleTestData . contactInfoDataFull ( ) ;
1828+
1829+ constructor ( ) {
1830+ this . columnGroups = [
1831+ { columnHeader : 'First' , columns : [
1832+ { field : 'ID' , type : 'string' } ,
1833+ { field : 'CompanyName' , type : 'string' } ,
1834+ { field : 'ContactName' , type : 'string' } ,
1835+ ] } ,
1836+ { columnHeader : 'Second' , columns : [
1837+ { field : 'ContactTitle' , type : 'string' } ,
1838+ { field : 'Address' , type : 'string' } ,
1839+ ] } ,
1840+ { columnHeader : 'Third' , columns : [
1841+ { field : 'PostlCode' , type : 'string' } ,
1842+ { field : 'Contry' , type : 'string' } ,
1843+ ] } ,
1844+ ] ;
1845+ }
1846+
1847+ public removeFirstColumnGroup ( ) {
1848+ this . columnGroups = this . columnGroups . splice ( 1 , this . columnGroups . length - 1 ) ;
1849+ }
1850+
1851+ }
1852+
17691853@Component ( {
17701854 template : `
17711855 <igx-grid #grid [data]="data" height="600px" width="1000px" columnWidth="100px">
0 commit comments