@@ -425,6 +425,149 @@ describe('IgxGrid - Deferred Column Resizing #grid', () => {
425
425
} ) ) ;
426
426
} ) ;
427
427
428
+ describe ( 'Percentage tests: ' , ( ) => {
429
+ let fixture : ComponentFixture < any > ;
430
+ let grid : IgxGridComponent ;
431
+
432
+ beforeEach ( fakeAsync ( ( ) => {
433
+ fixture = TestBed . createComponent ( ColPercentageGridComponent ) ;
434
+ fixture . detectChanges ( ) ;
435
+ grid = fixture . componentInstance . grid ;
436
+ } ) ) ;
437
+
438
+ it ( 'should resize columns with % width.' , fakeAsync ( ( ) => {
439
+ grid . height = null ;
440
+ fixture . detectChanges ( ) ;
441
+ const headers = GridFunctions . getColumnHeaders ( fixture ) ;
442
+ expect ( grid . columns [ 0 ] . width ) . toBe ( '25%' ) ;
443
+
444
+ const headerResArea = headers [ 0 ] . parent . children [ 2 ] . nativeElement ;
445
+ const startPos = headerResArea . getBoundingClientRect ( ) . x ;
446
+ UIInteractions . simulateMouseEvent ( 'mousedown' , headerResArea , startPos , 5 ) ;
447
+ tick ( 200 ) ;
448
+ fixture . detectChanges ( ) ;
449
+
450
+ const resizer = GridFunctions . getResizer ( fixture ) . nativeElement ;
451
+ expect ( resizer ) . toBeDefined ( ) ;
452
+ // resize with 100px, which is 25%
453
+ UIInteractions . simulateMouseEvent ( 'mousemove' , resizer , startPos + 100 , 5 ) ;
454
+ UIInteractions . simulateMouseEvent ( 'mouseup' , resizer , startPos + 100 , 5 ) ;
455
+ fixture . detectChanges ( ) ;
456
+ expect ( grid . columns [ 0 ] . width ) . toBe ( '50%' ) ;
457
+ } ) ) ;
458
+
459
+ it ( 'should resize columns with % width and % maxWidth.' , fakeAsync ( ( ) => {
460
+ grid . height = null ;
461
+ fixture . detectChanges ( ) ;
462
+ const headers = GridFunctions . getColumnHeaders ( fixture ) ;
463
+ grid . columns [ 0 ] . maxWidth = '30%' ;
464
+ expect ( grid . columns [ 0 ] . width ) . toBe ( '25%' ) ;
465
+
466
+ const headerResArea = headers [ 0 ] . parent . children [ 2 ] . nativeElement ;
467
+ const startPos = headerResArea . getBoundingClientRect ( ) . x ;
468
+ UIInteractions . simulateMouseEvent ( 'mousedown' , headerResArea , startPos , 5 ) ;
469
+ tick ( 200 ) ;
470
+ fixture . detectChanges ( ) ;
471
+
472
+ const resizer = GridFunctions . getResizer ( fixture ) . nativeElement ;
473
+ expect ( resizer ) . toBeDefined ( ) ;
474
+ // resize with +100px, which is 25%
475
+ UIInteractions . simulateMouseEvent ( 'mousemove' , resizer , startPos + 100 , 5 ) ;
476
+ UIInteractions . simulateMouseEvent ( 'mouseup' , resizer , startPos + 100 , 5 ) ;
477
+ fixture . detectChanges ( ) ;
478
+
479
+ expect ( grid . columns [ 0 ] . width ) . toBe ( grid . columns [ 0 ] . maxWidth ) ;
480
+ } ) ) ;
481
+
482
+ it ( 'should resize columns with % width and % minWidth.' , fakeAsync ( ( ) => {
483
+ grid . height = null ;
484
+ fixture . detectChanges ( ) ;
485
+ const headers = GridFunctions . getColumnHeaders ( fixture ) ;
486
+ grid . columns [ 0 ] . minWidth = '10%' ;
487
+ expect ( grid . columns [ 0 ] . width ) . toBe ( '25%' ) ;
488
+
489
+ const headerResArea = headers [ 0 ] . parent . children [ 2 ] . nativeElement ;
490
+ const startPos = headerResArea . getBoundingClientRect ( ) . x ;
491
+ UIInteractions . simulateMouseEvent ( 'mousedown' , headerResArea , startPos , 5 ) ;
492
+ tick ( 200 ) ;
493
+ fixture . detectChanges ( ) ;
494
+
495
+ const resizer = GridFunctions . getResizer ( fixture ) . nativeElement ;
496
+ // resize with -100px
497
+ UIInteractions . simulateMouseEvent ( 'mousemove' , resizer , startPos - 100 , 5 ) ;
498
+ UIInteractions . simulateMouseEvent ( 'mouseup' , resizer , startPos - 100 , 5 ) ;
499
+ fixture . detectChanges ( ) ;
500
+
501
+ expect ( grid . columns [ 0 ] . width ) . toBe ( grid . columns [ 0 ] . minWidth ) ;
502
+ } ) ) ;
503
+
504
+ it ( 'should resize columns with % width and pixel maxWidth.' , fakeAsync ( ( ) => {
505
+ grid . height = null ;
506
+ fixture . detectChanges ( ) ;
507
+ const headers = GridFunctions . getColumnHeaders ( fixture ) ;
508
+ grid . columns [ 0 ] . maxWidth = '200px' ;
509
+ expect ( grid . columns [ 0 ] . width ) . toBe ( '25%' ) ;
510
+
511
+ const headerResArea = headers [ 0 ] . parent . children [ 2 ] . nativeElement ;
512
+ const startPos = headerResArea . getBoundingClientRect ( ) . x ;
513
+ UIInteractions . simulateMouseEvent ( 'mousedown' , headerResArea , startPos , 5 ) ;
514
+ tick ( 200 ) ;
515
+ fixture . detectChanges ( ) ;
516
+
517
+ const resizer = GridFunctions . getResizer ( fixture ) . nativeElement ;
518
+ expect ( resizer ) . toBeDefined ( ) ;
519
+ // resize with +200px, which is 50%
520
+ UIInteractions . simulateMouseEvent ( 'mousemove' , resizer , startPos + 200 , 5 ) ;
521
+ UIInteractions . simulateMouseEvent ( 'mouseup' , resizer , startPos + 200 , 5 ) ;
522
+ fixture . detectChanges ( ) ;
523
+ expect ( grid . columns [ 0 ] . width ) . toBe ( '50%' ) ;
524
+ } ) ) ;
525
+
526
+ it ( 'should resize columns with % width and pixel minWidth.' , fakeAsync ( ( ) => {
527
+ grid . height = null ;
528
+ fixture . detectChanges ( ) ;
529
+ const headers = GridFunctions . getColumnHeaders ( fixture ) ;
530
+ // minWidth is 12.5% of the grid width - 400px
531
+ grid . columns [ 0 ] . minWidth = '50px' ;
532
+ expect ( grid . columns [ 0 ] . width ) . toBe ( '25%' ) ;
533
+
534
+ const headerResArea = headers [ 0 ] . parent . children [ 2 ] . nativeElement ;
535
+ const startPos = headerResArea . getBoundingClientRect ( ) . x ;
536
+ UIInteractions . simulateMouseEvent ( 'mousedown' , headerResArea , startPos , 5 ) ;
537
+ tick ( 200 ) ;
538
+ fixture . detectChanges ( ) ;
539
+
540
+ const resizer = GridFunctions . getResizer ( fixture ) . nativeElement ;
541
+ // resize with -100px
542
+ UIInteractions . simulateMouseEvent ( 'mousemove' , resizer , startPos - 100 , 5 ) ;
543
+ UIInteractions . simulateMouseEvent ( 'mouseup' , resizer , startPos - 100 , 5 ) ;
544
+ fixture . detectChanges ( ) ;
545
+
546
+ expect ( grid . columns [ 0 ] . width ) . toBe ( '12.5%' ) ;
547
+ } ) ) ;
548
+
549
+ it ( 'should autosize column with % width programmatically.' , fakeAsync ( ( ) => {
550
+ grid . height = null ;
551
+ fixture . detectChanges ( ) ;
552
+ expect ( grid . columns [ 0 ] . width ) . toBe ( '25%' ) ;
553
+ grid . columns [ 0 ] . autosize ( ) ;
554
+ fixture . detectChanges ( ) ;
555
+ expect ( grid . columns [ 0 ] . width ) . toBe ( '21%' ) ;
556
+ } ) ) ;
557
+
558
+ it ( 'should autosize column with % width on double click.' , fakeAsync ( ( ) => {
559
+ grid . height = null ;
560
+ fixture . detectChanges ( ) ;
561
+ expect ( grid . columns [ 0 ] . width ) . toBe ( '25%' ) ;
562
+ const headers = GridFunctions . getColumnHeaders ( fixture ) ;
563
+ const headerResArea = headers [ 0 ] . parent . children [ 2 ] . nativeElement ;
564
+ UIInteractions . simulateMouseEvent ( 'dblclick' , headerResArea , 0 , 0 ) ;
565
+ tick ( 200 ) ;
566
+ fixture . detectChanges ( ) ;
567
+ expect ( grid . columns [ 0 ] . width ) . toBe ( '21%' ) ;
568
+ } ) ) ;
569
+ } ) ;
570
+
428
571
describe ( 'Integration tests: ' , ( ) => {
429
572
let fixture : ComponentFixture < any > ;
430
573
let grid : IgxGridComponent ;
@@ -453,8 +596,8 @@ describe('IgxGrid - Deferred Column Resizing #grid', () => {
453
596
UIInteractions . simulateMouseEvent ( 'mouseup' , resizer , 550 , 5 ) ;
454
597
fixture . detectChanges ( ) ;
455
598
456
- expect ( grid . columns [ 2 ] . width ) . toEqual ( '250px' ) ;
457
- expect ( grid . columns [ 2 ] . cells [ 0 ] . value ) . toEqual ( 254 ) ;
599
+ // column has maxWidth='150px'
600
+ expect ( grid . columns [ 1 ] . width ) . toEqual ( '150px' ) ;
458
601
459
602
GridFunctions . clickHeaderSortIcon ( headers [ 2 ] ) ;
460
603
GridFunctions . clickHeaderSortIcon ( headers [ 2 ] ) ;
@@ -508,7 +651,7 @@ describe('IgxGrid - Deferred Column Resizing #grid', () => {
508
651
UIInteractions . simulateMouseEvent ( 'mouseup' , resizer , 300 , 5 ) ;
509
652
fixture . detectChanges ( ) ;
510
653
511
- let resizingArgs : IColumnResizeEventArgs = { column : grid . columns [ 0 ] , prevWidth : '150 ' , newWidth : '300px' } ;
654
+ let resizingArgs : IColumnResizeEventArgs = { column : grid . columns [ 0 ] , prevWidth : '150px ' , newWidth : '300px' } ;
512
655
expect ( grid . columns [ 0 ] . width ) . toEqual ( '300px' ) ;
513
656
expect ( resizingSpy ) . toHaveBeenCalledTimes ( 1 ) ;
514
657
expect ( resizingSpy ) . toHaveBeenCalledWith ( resizingArgs ) ;
@@ -805,7 +948,7 @@ export class ColGridComponent implements OnInit {
805
948
806
949
@Component ( {
807
950
template : GridTemplateStrings . declareGrid ( `width="400px" height="600px" [allowFiltering]="true"` , `` ,
808
- `<igx-column [field]="'Items'" [width]="'25%'" dataType="string" [filterable]="true"></igx-column>
951
+ `<igx-column [field]="'Items'" [width]="'25%'" dataType="string" [filterable]="true" [resizable]="true" ></igx-column>
809
952
<igx-column [field]="'ID'" [width]="'25%'" [header]="'ID'" [filterable]="true"></igx-column>
810
953
<igx-column [field]="'ProductName'" [width]="'25%'" dataType="string" [filterable]="true"></igx-column>
811
954
<igx-column [field]="'Test'"[width]="'25%'" dataType="string" [resizable]="true"></igx-column>`
0 commit comments