@@ -261,7 +261,8 @@ describe('IgxGrid - multi-column headers #grid', () => {
261
261
fixture . detectChanges ( ) ;
262
262
263
263
const locationColGroup = getColGroup ( grid , 'Location' ) ;
264
- expect ( locationColGroup . width ) . toBe ( gridColWidth ) ;
264
+ const expectedWidth = ( grid . calcWidth / 2 ) + 'px' ;
265
+ expect ( locationColGroup . width ) . toBe ( expectedWidth ) ;
265
266
const cityColumn = grid . getColumnByName ( 'City' ) ;
266
267
expect ( cityColumn . width ) . toBe ( gridColWidth ) ;
267
268
} ) ) ;
@@ -293,7 +294,8 @@ describe('IgxGrid - multi-column headers #grid', () => {
293
294
fixture . detectChanges ( ) ;
294
295
295
296
const locationColGroup = getColGroup ( grid , 'Location' ) ;
296
- expect ( locationColGroup . width ) . toBe ( columnWidth ) ;
297
+ const expectedWidth = ( grid . calcWidth / 2 ) + 'px' ;
298
+ expect ( locationColGroup . width ) . toBe ( expectedWidth ) ;
297
299
const cityColumn = grid . getColumnByName ( 'City' ) ;
298
300
expect ( cityColumn . width ) . toBe ( columnWidth ) ;
299
301
} ) ) ;
@@ -345,6 +347,96 @@ describe('IgxGrid - multi-column headers #grid', () => {
345
347
expect ( cityColumn . width ) . toBe ( colWidthPx ) ;
346
348
} ) ) ;
347
349
350
+ it ( 'Width should be correct. Column group with three columns. Columns with mixed width - px and percent.' , async ( ) => {
351
+ const fixture = TestBed . createComponent ( OneGroupThreeColsGridComponent ) ;
352
+ fixture . detectChanges ( ) ;
353
+ const componentInstance = fixture . componentInstance ;
354
+ const grid = componentInstance . grid ;
355
+ const col1 = grid . getColumnByName ( 'Country' ) ;
356
+ const col2 = grid . getColumnByName ( 'Region' ) ;
357
+ const col3 = grid . getColumnByName ( 'City' ) ;
358
+
359
+
360
+ col1 . width = '200px' ;
361
+ col2 . width = '20%' ;
362
+ col3 . width = '50%' ;
363
+
364
+ fixture . detectChanges ( ) ;
365
+
366
+ // check group has correct size.
367
+ let locationColGroup = getColGroup ( grid , 'Location' ) ;
368
+ let expectedWidth = ( 200 + Math . floor ( grid . calcWidth * 0.7 ) ) + 'px' ;
369
+ expect ( locationColGroup . width ) . toBe ( expectedWidth ) ;
370
+
371
+ // check header and content have same size.
372
+ const col1Header = grid . getColumnByName ( 'Country' ) . headerCell . elementRef . nativeElement ;
373
+ const cell1 = grid . getRowByIndex ( 0 ) . cells . toArray ( ) [ 0 ] . nativeElement ;
374
+ expect ( col1Header . offsetWidth ) . toEqual ( cell1 . offsetWidth ) ;
375
+
376
+ let col2Header = grid . getColumnByName ( 'Region' ) . headerCell . elementRef . nativeElement ;
377
+ let cell2 = grid . getRowByIndex ( 0 ) . cells . toArray ( ) [ 1 ] . nativeElement ;
378
+ expect ( col2Header . offsetWidth - cell2 . offsetWidth ) . toBeLessThanOrEqual ( 1 ) ;
379
+
380
+ let col3Header = grid . getColumnByName ( 'City' ) . headerCell . elementRef . nativeElement ;
381
+ let cell3 = grid . getRowByIndex ( 0 ) . cells . toArray ( ) [ 2 ] . nativeElement ;
382
+ expect ( col3Header . offsetWidth ) . toEqual ( cell3 . offsetWidth ) ;
383
+
384
+ // check that if grid is resized, group size is updated.
385
+
386
+ componentInstance . gridWrapperWidthPx = '500' ;
387
+ fixture . detectChanges ( ) ;
388
+
389
+ await wait ( 100 ) ;
390
+ fixture . detectChanges ( ) ;
391
+
392
+ locationColGroup = getColGroup ( grid , 'Location' ) ;
393
+ expectedWidth = ( 200 + Math . floor ( grid . calcWidth * 0.7 ) ) + 'px' ;
394
+ expect ( locationColGroup . width ) . toBe ( expectedWidth ) ;
395
+
396
+ col2Header = grid . getColumnByName ( 'Region' ) . headerCell . elementRef . nativeElement ;
397
+ cell2 = grid . getRowByIndex ( 0 ) . cells . toArray ( ) [ 1 ] . nativeElement ;
398
+ expect ( col2Header . offsetWidth - cell2 . offsetWidth ) . toBeLessThanOrEqual ( 1 ) ;
399
+
400
+ col3Header = grid . getColumnByName ( 'City' ) . headerCell . elementRef . nativeElement ;
401
+ cell3 = grid . getRowByIndex ( 0 ) . cells . toArray ( ) [ 2 ] . nativeElement ;
402
+ expect ( col3Header . offsetWidth ) . toEqual ( cell3 . offsetWidth ) ;
403
+ } ) ;
404
+
405
+ it ( 'Width should be correct. Column group with three columns. Columns with mixed width - px, percent and null.' , ( ) => {
406
+ const fixture = TestBed . createComponent ( OneGroupThreeColsGridComponent ) ;
407
+ fixture . detectChanges ( ) ;
408
+ const componentInstance = fixture . componentInstance ;
409
+ const grid = componentInstance . grid ;
410
+ const col1 = grid . getColumnByName ( 'Country' ) ;
411
+ const col2 = grid . getColumnByName ( 'Region' ) ;
412
+ const col3 = grid . getColumnByName ( 'City' ) ;
413
+
414
+
415
+ col1 . width = '200px' ;
416
+ col2 . width = '20%' ;
417
+ col3 . width = null ;
418
+
419
+ fixture . detectChanges ( ) ;
420
+
421
+ // check group has correct size. Should fill available space in grid since one column has no width.
422
+ const locationColGroup = getColGroup ( grid , 'Location' ) ;
423
+ const expectedWidth = grid . calcWidth - 1 + 'px' ;
424
+ expect ( locationColGroup . width ) . toBe ( expectedWidth ) ;
425
+
426
+ // check header and content have same size.
427
+ const col1Header = grid . getColumnByName ( 'Country' ) . headerCell . elementRef . nativeElement ;
428
+ const cell1 = grid . getRowByIndex ( 0 ) . cells . toArray ( ) [ 0 ] . nativeElement ;
429
+ expect ( col1Header . offsetWidth ) . toEqual ( cell1 . offsetWidth ) ;
430
+
431
+ const col2Header = grid . getColumnByName ( 'Region' ) . headerCell . elementRef . nativeElement ;
432
+ const cell2 = grid . getRowByIndex ( 0 ) . cells . toArray ( ) [ 1 ] . nativeElement ;
433
+ expect ( col2Header . offsetWidth - cell2 . offsetWidth ) . toBeLessThanOrEqual ( 1 ) ;
434
+
435
+ const col3Header = grid . getColumnByName ( 'City' ) . headerCell . elementRef . nativeElement ;
436
+ const cell3 = grid . getRowByIndex ( 0 ) . cells . toArray ( ) [ 2 ] . nativeElement ;
437
+ expect ( col3Header . offsetWidth ) . toEqual ( cell3 . offsetWidth ) ;
438
+ } ) ;
439
+
348
440
it ( 'Width should be correct. Column group with three columns. Width in percent.' , fakeAsync ( ( ) => {
349
441
const fixture = TestBed . createComponent ( OneGroupThreeColsGridComponent ) ;
350
442
fixture . detectChanges ( ) ;
@@ -397,15 +489,15 @@ describe('IgxGrid - multi-column headers #grid', () => {
397
489
const fixture = TestBed . createComponent ( OneGroupThreeColsGridComponent ) ;
398
490
fixture . detectChanges ( ) ;
399
491
const gridColWidth = '20%' ;
400
- const groupWidth = '60%' ;
401
492
const componentInstance = fixture . componentInstance ;
402
493
const grid = componentInstance . grid ;
403
494
grid . ngAfterViewInit ( ) ;
404
495
grid . columnWidth = gridColWidth ;
405
496
fixture . detectChanges ( ) ;
406
497
407
498
const locationColGroup = getColGroup ( grid , 'Location' ) ;
408
- expect ( locationColGroup . width ) . toBe ( groupWidth ) ;
499
+ const expectedWidth = ( Math . floor ( grid . calcWidth * 0.2 ) * 3 ) + 'px' ;
500
+ expect ( locationColGroup . width ) . toBe ( expectedWidth ) ;
409
501
const countryColumn = grid . getColumnByName ( 'Country' ) ;
410
502
expect ( countryColumn . width ) . toBe ( gridColWidth ) ;
411
503
const regionColumn = grid . getColumnByName ( 'Region' ) ;
@@ -437,26 +529,26 @@ describe('IgxGrid - multi-column headers #grid', () => {
437
529
} ) ) ;
438
530
439
531
it ( 'Width should be correct. Column group with three columns. Columns with width in percent.' ,
440
- fakeAsync ( /** height/width setter rAF */ ( ) => {
441
- const fixture = TestBed . createComponent ( OneGroupThreeColsGridComponent ) ;
442
- fixture . detectChanges ( ) ;
443
- const columnWidth = '20%' ;
444
- const groupWidth = '60%' ;
445
- const componentInstance = fixture . componentInstance ;
446
- const grid = componentInstance . grid ;
447
- grid . ngAfterViewInit ( ) ;
448
- componentInstance . columnWidth = columnWidth ;
449
- fixture . detectChanges ( ) ;
532
+ fakeAsync ( /** height/width setter rAF */ ( ) => {
533
+ const fixture = TestBed . createComponent ( OneGroupThreeColsGridComponent ) ;
534
+ fixture . detectChanges ( ) ;
535
+ const columnWidth = '20%' ;
536
+ const componentInstance = fixture . componentInstance ;
537
+ const grid = componentInstance . grid ;
538
+ grid . ngAfterViewInit ( ) ;
539
+ componentInstance . columnWidth = columnWidth ;
540
+ fixture . detectChanges ( ) ;
450
541
451
- const locationColGroup = getColGroup ( grid , 'Location' ) ;
452
- expect ( locationColGroup . width ) . toBe ( groupWidth ) ;
453
- const countryColumn = grid . getColumnByName ( 'Country' ) ;
454
- expect ( countryColumn . width ) . toBe ( columnWidth ) ;
455
- const regionColumn = grid . getColumnByName ( 'Region' ) ;
456
- expect ( regionColumn . width ) . toBe ( columnWidth ) ;
457
- const cityColumn = grid . getColumnByName ( 'City' ) ;
458
- expect ( cityColumn . width ) . toBe ( columnWidth ) ;
459
- } ) ) ;
542
+ const locationColGroup = getColGroup ( grid , 'Location' ) ;
543
+ const expectedWidth = ( Math . floor ( grid . calcWidth * 0.2 ) * 3 ) + 'px' ;
544
+ expect ( locationColGroup . width ) . toBe ( expectedWidth ) ;
545
+ const countryColumn = grid . getColumnByName ( 'Country' ) ;
546
+ expect ( countryColumn . width ) . toBe ( columnWidth ) ;
547
+ const regionColumn = grid . getColumnByName ( 'Region' ) ;
548
+ expect ( regionColumn . width ) . toBe ( columnWidth ) ;
549
+ const cityColumn = grid . getColumnByName ( 'City' ) ;
550
+ expect ( cityColumn . width ) . toBe ( columnWidth ) ;
551
+ } ) ) ;
460
552
461
553
it ( 'API method level should return correct values' , fakeAsync ( ( ) => {
462
554
const fixture = TestBed . createComponent ( ColumnGroupFourLevelTestComponent ) ;
0 commit comments