@@ -15,7 +15,8 @@ describe('IgxGrid - multi-column headers', () => {
15
15
declarations : [
16
16
OneGroupOneColGridComponent ,
17
17
OneGroupThreeColsGridComponent ,
18
- ColumnGroupTestComponent
18
+ ColumnGroupTestComponent ,
19
+ ColumnGroupFourLevelTestComponent
19
20
] ,
20
21
imports : [
21
22
NoopAnimationsModule ,
@@ -301,6 +302,141 @@ describe('IgxGrid - multi-column headers', () => {
301
302
const cityColumn = grid . getColumnByName ( 'City' ) ;
302
303
expect ( cityColumn . width ) . toBe ( columnWidth ) ;
303
304
} ) ;
305
+
306
+ it ( 'API method level should return correct values' , ( ) => {
307
+ const fixture = TestBed . createComponent ( ColumnGroupFourLevelTestComponent ) ;
308
+ fixture . detectChanges ( ) ;
309
+ const grid = fixture . componentInstance . grid ;
310
+
311
+ expect ( grid . columnList . filter ( col => col . columnGroup ) . length ) . toEqual ( 7 ) ;
312
+
313
+ // Get level of column
314
+ expect ( grid . getColumnByName ( 'ID' ) . level ) . toEqual ( 0 ) ;
315
+ expect ( grid . getColumnByName ( 'CompanyName' ) . level ) . toEqual ( 1 ) ;
316
+ expect ( grid . getColumnByName ( 'Country' ) . level ) . toEqual ( 2 ) ;
317
+ expect ( grid . getColumnByName ( 'City' ) . level ) . toEqual ( 3 ) ;
318
+ expect ( grid . getColumnByName ( 'PostalCode' ) . level ) . toEqual ( 2 ) ;
319
+ // Get level of hidden column
320
+ expect ( grid . getColumnByName ( 'Fax' ) . level ) . toEqual ( 2 ) ;
321
+ // Get level of column in hidden group
322
+ expect ( grid . getColumnByName ( 'ContactTitle' ) . level ) . toEqual ( 2 ) ;
323
+
324
+ // Get level of grouped column
325
+ expect ( getColGroup ( grid , 'General Information' ) . level ) . toEqual ( 0 ) ;
326
+ expect ( getColGroup ( grid , 'Location' ) . level ) . toEqual ( 1 ) ;
327
+ expect ( getColGroup ( grid , 'Location City' ) . level ) . toEqual ( 2 ) ;
328
+ expect ( getColGroup ( grid , 'Contact Information' ) . level ) . toEqual ( 1 ) ;
329
+ expect ( getColGroup ( grid , 'Postal Code' ) . level ) . toEqual ( 1 ) ;
330
+ // Get level of hidden group
331
+ expect ( getColGroup ( grid , 'Person Details' ) . level ) . toEqual ( 1 ) ;
332
+ } ) ;
333
+
334
+ it ( 'API method columnGroup should return correct values' , ( ) => {
335
+ const fixture = TestBed . createComponent ( ColumnGroupFourLevelTestComponent ) ;
336
+ fixture . detectChanges ( ) ;
337
+ const grid = fixture . componentInstance . grid ;
338
+
339
+ expect ( grid . columnList . filter ( col => col . columnGroup ) . length ) . toEqual ( 7 ) ;
340
+ // Get columnGroup of column
341
+ expect ( grid . getColumnByName ( 'ID' ) . columnGroup ) . toEqual ( false ) ;
342
+ expect ( grid . getColumnByName ( 'Fax' ) . columnGroup ) . toEqual ( false ) ;
343
+ expect ( grid . getColumnByName ( 'ContactTitle' ) . columnGroup ) . toEqual ( false ) ;
344
+
345
+ // Get columnGroup of grouped column
346
+ expect ( getColGroup ( grid , 'General Information' ) . columnGroup ) . toEqual ( true ) ;
347
+ expect ( getColGroup ( grid , 'Location City' ) . columnGroup ) . toEqual ( true ) ;
348
+ expect ( getColGroup ( grid , 'Contact Information' ) . columnGroup ) . toEqual ( true ) ;
349
+ expect ( getColGroup ( grid , 'Postal Code' ) . columnGroup ) . toEqual ( true ) ;
350
+ expect ( getColGroup ( grid , 'Person Details' ) . columnGroup ) . toEqual ( true ) ;
351
+ } ) ;
352
+
353
+ it ( 'API method allChildren should return correct values' , ( ) => {
354
+ const fixture = TestBed . createComponent ( ColumnGroupFourLevelTestComponent ) ;
355
+ fixture . detectChanges ( ) ;
356
+ const grid = fixture . componentInstance . grid ;
357
+
358
+ expect ( grid . columnList . filter ( col => col . columnGroup ) . length ) . toEqual ( 7 ) ;
359
+ // Get allChildren of column
360
+ expect ( grid . getColumnByName ( 'ID' ) . allChildren . length ) . toEqual ( 0 ) ;
361
+ expect ( grid . getColumnByName ( 'PostalCode' ) . allChildren . length ) . toEqual ( 0 ) ;
362
+ // Get allChildren of hidden column
363
+ expect ( grid . getColumnByName ( 'Fax' ) . allChildren . length ) . toEqual ( 0 ) ;
364
+
365
+ // Get allChildren of group
366
+ const genInfGroupedColumnAllChildren = getColGroup ( grid , 'General Information' ) . allChildren ;
367
+ expect ( genInfGroupedColumnAllChildren . length ) . toEqual ( 4 ) ;
368
+ expect ( genInfGroupedColumnAllChildren . indexOf ( getColGroup ( grid , 'Person Details' ) ) ) . toBeGreaterThanOrEqual ( 0 ) ;
369
+
370
+ // Get allChildren of hidden group
371
+ expect ( getColGroup ( grid , 'Person Details' ) . allChildren . length ) . toEqual ( 2 ) ;
372
+
373
+ // Get allChildren of group with one column
374
+ const postCodeGroupedColumnAllChildren = getColGroup ( grid , 'Postal Code' ) . allChildren ;
375
+ expect ( postCodeGroupedColumnAllChildren . length ) . toEqual ( 1 ) ;
376
+ expect ( postCodeGroupedColumnAllChildren . indexOf ( grid . getColumnByName ( 'PostalCode' ) ) ) . toEqual ( 0 ) ;
377
+
378
+ // Get allChildren of group with hidden columns and more levels
379
+ const addressGroupedColumnAllChildren = getColGroup ( grid , 'Address Information' ) . allChildren ;
380
+ expect ( addressGroupedColumnAllChildren . length ) . toEqual ( 11 ) ;
381
+ expect ( addressGroupedColumnAllChildren . indexOf ( getColGroup ( grid , 'Postal Code' ) ) ) . toBeGreaterThanOrEqual ( 0 ) ;
382
+ expect ( addressGroupedColumnAllChildren . indexOf ( grid . getColumnByName ( 'PostalCode' ) ) ) . toBeGreaterThanOrEqual ( 0 ) ;
383
+ expect ( addressGroupedColumnAllChildren . indexOf ( grid . getColumnByName ( 'Address' ) ) ) . toBeGreaterThanOrEqual ( 0 ) ;
384
+ expect ( addressGroupedColumnAllChildren . indexOf ( grid . getColumnByName ( 'Country' ) ) ) . toBeGreaterThanOrEqual ( 0 ) ;
385
+ expect ( addressGroupedColumnAllChildren . indexOf ( grid . getColumnByName ( 'Fax' ) ) ) . toBeGreaterThanOrEqual ( 0 ) ;
386
+ expect ( addressGroupedColumnAllChildren . indexOf ( getColGroup ( grid , 'General Information' ) ) ) . toEqual ( - 1 ) ;
387
+ } ) ;
388
+
389
+ it ( 'API method children should return correct values' , ( ) => {
390
+ const fixture = TestBed . createComponent ( ColumnGroupFourLevelTestComponent ) ;
391
+ fixture . detectChanges ( ) ;
392
+ const grid = fixture . componentInstance . grid ;
393
+
394
+ expect ( grid . columnList . filter ( col => col . columnGroup ) . length ) . toEqual ( 7 ) ;
395
+
396
+ // Get children of grouped column
397
+ expect ( getColGroup ( grid , 'General Information' ) . children . length ) . toEqual ( 2 ) ;
398
+
399
+ // Get children of hidden group
400
+ expect ( getColGroup ( grid , 'Person Details' ) . children . length ) . toEqual ( 2 ) ;
401
+
402
+ // Get children of group with one column
403
+ const postCodeGroupedColumnAllChildren = getColGroup ( grid , 'Postal Code' ) . children ;
404
+ expect ( postCodeGroupedColumnAllChildren . length ) . toEqual ( 1 ) ;
405
+
406
+ // Get children of group with more levels
407
+ const addressGroupedColumnAllChildren = getColGroup ( grid , 'Address Information' ) . children ;
408
+ expect ( addressGroupedColumnAllChildren . length ) . toEqual ( 3 ) ;
409
+ } ) ;
410
+
411
+ it ( 'API method topLevelParent should return correct values' , ( ) => {
412
+ const fixture = TestBed . createComponent ( ColumnGroupFourLevelTestComponent ) ;
413
+ fixture . detectChanges ( ) ;
414
+ const grid = fixture . componentInstance . grid ;
415
+
416
+ expect ( grid . columnList . filter ( col => col . columnGroup ) . length ) . toEqual ( 7 ) ;
417
+
418
+ // Get topLevelParent of column with no group
419
+ expect ( grid . getColumnByName ( 'ID' ) . topLevelParent ) . toBeNull ( ) ;
420
+
421
+ // Get topLevelParent of column
422
+ const addressGroupedColumn = getColGroup ( grid , 'Address Information' ) ;
423
+ expect ( grid . getColumnByName ( 'PostalCode' ) . topLevelParent ) . toEqual ( addressGroupedColumn ) ;
424
+ expect ( grid . getColumnByName ( 'Fax' ) . topLevelParent ) . toEqual ( addressGroupedColumn ) ;
425
+ expect ( grid . getColumnByName ( 'Country' ) . topLevelParent ) . toEqual ( addressGroupedColumn ) ;
426
+
427
+ const genInfGroupedColumn = getColGroup ( grid , 'General Information' ) ;
428
+ expect ( grid . getColumnByName ( 'ContactName' ) . topLevelParent ) . toEqual ( genInfGroupedColumn ) ;
429
+ expect ( grid . getColumnByName ( 'CompanyName' ) . topLevelParent ) . toEqual ( genInfGroupedColumn ) ;
430
+
431
+ // Get topLevelParent of top group
432
+ expect ( genInfGroupedColumn . topLevelParent ) . toBeNull ( ) ;
433
+ expect ( addressGroupedColumn . topLevelParent ) . toBeNull ( ) ;
434
+
435
+ // Get topLevelParent of group
436
+ expect ( getColGroup ( grid , 'Person Details' ) . topLevelParent ) . toEqual ( genInfGroupedColumn ) ;
437
+ expect ( getColGroup ( grid , 'Postal Code' ) . topLevelParent ) . toEqual ( addressGroupedColumn ) ;
438
+ expect ( getColGroup ( grid , 'Location City' ) . topLevelParent ) . toEqual ( addressGroupedColumn ) ;
439
+ } ) ;
304
440
} ) ;
305
441
306
442
@Component ( {
@@ -377,6 +513,44 @@ export class ColumnGroupTestComponent {
377
513
data = DATASOURCE ;
378
514
}
379
515
516
+ @Component ( {
517
+ template : `
518
+ <igx-grid #grid [data]="data" height="600px">
519
+ <igx-column field="ID"></igx-column>
520
+ <igx-column-group header="General Information">
521
+ <igx-column field="CompanyName"></igx-column>
522
+ <igx-column-group header="Person Details" hidden="true">
523
+ <igx-column field="ContactName"></igx-column>
524
+ <igx-column field="ContactTitle"></igx-column>
525
+ </igx-column-group>
526
+ </igx-column-group>
527
+ <igx-column-group header="Address Information">
528
+ <igx-column-group header="Location">
529
+ <igx-column field="Country"></igx-column>
530
+ <igx-column field="Region"></igx-column>
531
+ <igx-column-group header="Location City">
532
+ <igx-column field="City"></igx-column>
533
+ <igx-column field="Address"></igx-column>
534
+ </igx-column-group>
535
+ </igx-column-group>
536
+ <igx-column-group header="Contact Information">
537
+ <igx-column field="Phone"></igx-column>
538
+ <igx-column field="Fax" hidden="true"></igx-column>
539
+ </igx-column-group>
540
+ <igx-column-group header="Postal Code">
541
+ <igx-column field="PostalCode"></igx-column>
542
+ </igx-column-group>
543
+ </igx-column-group>
544
+ </igx-grid>
545
+ `
546
+ } )
547
+ export class ColumnGroupFourLevelTestComponent {
548
+ @ViewChild ( IgxGridComponent , { read : IgxGridComponent } )
549
+ grid : IgxGridComponent ;
550
+
551
+ data = DATASOURCE ;
552
+ }
553
+
380
554
export const DATASOURCE = [
381
555
// tslint:disable:max-line-length
382
556
{ 'ID' : 'ALFKI' , 'CompanyName' : 'Alfreds Futterkiste' , 'ContactName' : 'Maria Anders' , 'ContactTitle' : 'Sales Representative' , 'Address' : 'Obere Str. 57' , 'City' : 'Berlin' , 'Region' : null , 'PostalCode' : '12209' , 'Country' : 'Germany' , 'Phone' : '030-0074321' , 'Fax' : '030-0076545' } ,
0 commit comments