@@ -20,6 +20,7 @@ import {
2020import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
2121import { UIInteractions , wait } from '../../../test-utils/ui-interactions.spec' ;
2222import { GridFunctions , GridSummaryFunctions } from '../../../test-utils/grid-functions.spec' ;
23+ import { clearGridSubs , setupGridScrollDetection } from '../../../test-utils/helper-utils.spec' ;
2324import { IgxCellFooterTemplateDirective , IgxCellHeaderTemplateDirective , IgxCellTemplateDirective , IgxColumnComponent , INPUT_DEBOUNCE_TIME_DEFAULT , IgxSummaryTemplateDirective } from 'igniteui-angular/grids/core' ;
2425import { IgxGridRowComponent } from './grid-row.component' ;
2526import { GridColumnDataType , IgxStringFilteringOperand , SortingDirection } from 'igniteui-angular/core' ;
@@ -1539,6 +1540,49 @@ describe('IgxGrid - Column properties #grid', () => {
15391540 expect ( grid . columns . find ( x => x . field === 'Fax' ) . width ) . toBe ( '130px' ) ;
15401541 } ) ) ;
15411542
1543+ it ( 'should auto-size column when scrolled into view.' , ( async ( ) => {
1544+ const fix = TestBed . createComponent ( ResizableColumnsComponent ) ;
1545+ const cols = [ ] ;
1546+ const data = [ ] ;
1547+ for ( let j = 0 ; j < 20 ; j ++ ) {
1548+ cols . push ( {
1549+ field : ( j + 1 ) . toString ( ) ,
1550+ width : 'auto'
1551+ } ) ;
1552+ }
1553+ const obj = { } ;
1554+ for ( let j = 0 ; j < cols . length ; j ++ ) {
1555+ const col = cols [ j ] . field ;
1556+ obj [ col ] = j ;
1557+ }
1558+
1559+ for ( let i = 0 ; i < 100000 ; i ++ ) {
1560+ const newObj = Object . create ( obj ) ;
1561+ newObj [ 'ID' ] = i ;
1562+ data . push ( newObj ) ;
1563+ }
1564+ fix . componentInstance . columns = cols ;
1565+ fix . componentInstance . data = data ;
1566+ fix . detectChanges ( ) ;
1567+ await fix . whenStable ( ) ;
1568+ const grid = fix . componentInstance . instance ;
1569+ let state = grid . headerContainer . state ;
1570+ let visibleColumnSizes = ( grid . headerContainer as any ) . individualSizeCache . slice ( state . startIndex , state . startIndex + state . chunkSize ) ;
1571+ for ( const val of visibleColumnSizes ) {
1572+ expect ( val ) . toBe ( 68 ) ;
1573+ }
1574+
1575+ setupGridScrollDetection ( fix , grid ) ;
1576+ grid . navigateTo ( 0 , fix . componentInstance . columns . length - 1 ) ;
1577+
1578+ state = grid . headerContainer . state ;
1579+ visibleColumnSizes = ( grid . headerContainer as any ) . individualSizeCache . slice ( state . startIndex , state . startIndex + state . chunkSize ) ;
1580+ for ( const val of visibleColumnSizes ) {
1581+ expect ( val ) . toBe ( 68 ) ;
1582+ }
1583+ clearGridSubs ( ) ;
1584+ } ) ) ;
1585+
15421586 it ( 'should auto-size correctly when cell has custom template' , fakeAsync ( ( ) => {
15431587 const fix = TestBed . createComponent ( ResizableColumnsComponent ) ;
15441588 const grid = fix . componentInstance . instance ;
0 commit comments