@@ -197,34 +197,6 @@ describe('IgxForOf directive -', () => {
197197 horizontalScroller = fix . nativeElement . querySelector ( 'igx-horizontal-virtual-helper' ) ;
198198 } ) ;
199199
200- it ( 'should reset scroll position if component is destroyed and recreated.' , async ( ) => {
201- let scrollComponent = fix . debugElement . query ( By . css ( VERTICAL_SCROLLER ) ) . componentInstance ;
202- expect ( scrollComponent . scrollAmount ) . toBe ( 0 ) ;
203- expect ( scrollComponent . destroyed ) . toBeFalsy ( ) ;
204-
205- fix . componentInstance . scrollTop ( 500 ) ;
206- fix . detectChanges ( ) ;
207- await wait ( ) ;
208- expect ( scrollComponent . scrollAmount ) . toBe ( 500 ) ;
209-
210- fix . componentInstance . exists = false ;
211- fix . detectChanges ( ) ;
212- await wait ( ) ;
213-
214- expect ( scrollComponent . destroyed ) . toBeTruthy ( ) ;
215-
216- fix . componentInstance . exists = true ;
217- fix . detectChanges ( ) ;
218- await wait ( ) ;
219-
220- scrollComponent = fix . debugElement . query ( By . css ( VERTICAL_SCROLLER ) ) . componentInstance ;
221- expect ( scrollComponent . scrollAmount ) . toBe ( 0 ) ;
222- expect ( scrollComponent . destroyed ) . toBeFalsy ( ) ;
223-
224- displayContainer = fix . nativeElement . querySelector ( DISPLAY_CONTAINER ) ;
225- const firstInnerDisplayContainer = displayContainer . children [ 0 ] ;
226- expect ( firstInnerDisplayContainer . children [ 0 ] . textContent ) . toBe ( '0' ) ;
227- } ) ;
228200
229201 it ( 'should initialize directive with vertical virtualization' , async ( ) => {
230202 expect ( displayContainer ) . not . toBeNull ( ) ;
@@ -1117,6 +1089,57 @@ describe('IgxForOf directive -', () => {
11171089 }
11181090 } ) ;
11191091 } ) ;
1092+
1093+ describe ( 'on destroy' , ( ) => {
1094+ let fix : ComponentFixture < VerticalVirtualDestroyComponent > ;
1095+
1096+ configureTestSuite ( ) ;
1097+ beforeAll ( async ( ( ) => {
1098+ TestBed . configureTestingModule ( {
1099+ declarations : [
1100+ TestIgxForOfDirective ,
1101+ VerticalVirtualDestroyComponent
1102+ ] ,
1103+ imports : [ IgxForOfModule ] ,
1104+ providers : [ { provide : NgZone , useFactory : ( ) => zone = new TestNgZone ( ) } ]
1105+ } ) . compileComponents ( ) ;
1106+ } ) ) ;
1107+
1108+ beforeEach ( ( ) => {
1109+ fix = TestBed . createComponent ( VerticalVirtualDestroyComponent ) ;
1110+ fix . componentInstance . data = dg . generateVerticalData ( fix . componentInstance . cols ) ;
1111+ fix . componentRef . hostView . detectChanges ( ) ;
1112+ fix . detectChanges ( ) ;
1113+ } ) ;
1114+ it ( 'should reset scroll position if component is destroyed and recreated.' , async ( ) => {
1115+ let scrollComponent = fix . debugElement . query ( By . css ( VERTICAL_SCROLLER ) ) . componentInstance ;
1116+ expect ( scrollComponent . scrollAmount ) . toBe ( 0 ) ;
1117+ expect ( scrollComponent . destroyed ) . toBeFalsy ( ) ;
1118+
1119+ scrollComponent . nativeElement . scrollTop = 500 ;
1120+ fix . detectChanges ( ) ;
1121+ await wait ( ) ;
1122+ expect ( scrollComponent . scrollAmount ) . toBe ( 500 ) ;
1123+
1124+ fix . componentInstance . exists = false ;
1125+ fix . detectChanges ( ) ;
1126+ await wait ( ) ;
1127+
1128+ expect ( scrollComponent . destroyed ) . toBeTruthy ( ) ;
1129+
1130+ fix . componentInstance . exists = true ;
1131+ fix . detectChanges ( ) ;
1132+ await wait ( ) ;
1133+
1134+ scrollComponent = fix . debugElement . query ( By . css ( VERTICAL_SCROLLER ) ) . componentInstance ;
1135+ expect ( scrollComponent . scrollAmount ) . toBe ( 0 ) ;
1136+ expect ( scrollComponent . destroyed ) . toBeFalsy ( ) ;
1137+
1138+ displayContainer = fix . nativeElement . querySelector ( DISPLAY_CONTAINER ) ;
1139+ const firstInnerDisplayContainer = displayContainer . children [ 0 ] ;
1140+ expect ( firstInnerDisplayContainer . children [ 0 ] . textContent ) . toBe ( '0' ) ;
1141+ } ) ;
1142+ } ) ;
11201143} ) ;
11211144
11221145class DataGenerator {
@@ -1281,10 +1304,10 @@ export class VirtualComponent {
12811304 public cols = [ ] ;
12821305 public data = [ ] ;
12831306
1284- @ViewChild ( 'container' , { read : ViewContainerRef , static : false } )
1307+ @ViewChild ( 'container' , { read : ViewContainerRef , static : true } )
12851308 public container : ViewContainerRef ;
12861309
1287- @ViewChild ( 'scrollContainer' , { read : TestIgxForOfDirective , static : false } )
1310+ @ViewChild ( 'scrollContainer' , { read : TestIgxForOfDirective , static : true } )
12881311 public parentVirtDir : TestIgxForOfDirective < any > ;
12891312
12901313 @ViewChildren ( 'childContainer' , { read : TestIgxForOfDirective } )
@@ -1328,7 +1351,7 @@ export class VirtualComponent {
13281351/** Only vertically virtualized component */
13291352@Component ( {
13301353 template : `
1331- <div *ngIf='exists' #container [style.width]='width' [style.height]='height'>
1354+ <div #container [style.width]='width' [style.height]='height'>
13321355 <ng-template #scrollContainer igxForTest let-rowData [igxForOf]="data"
13331356 [igxForScrollOrientation]="'vertical'"
13341357 [igxForContainerSize]='height'
@@ -1356,6 +1379,27 @@ export class VerticalVirtualComponent extends VirtualComponent {
13561379 ] ;
13571380 public data = [ ] ;
13581381 public itemSize = '50px' ;
1382+ }
1383+
1384+ @Component ( {
1385+ template : `
1386+ <div *ngIf='exists' #container [style.width]='width' [style.height]='height'>
1387+ <ng-template #scrollContainer igxForTest let-rowData [igxForOf]="data"
1388+ [igxForScrollOrientation]="'vertical'"
1389+ [igxForContainerSize]='height'
1390+ [igxForItemSize]='itemSize'>
1391+ <div [style.display]="'flex'" [style.height]="rowData.height || itemSize || '50px'">
1392+ <div [style.min-width]=cols[0].width>{{rowData['1']}}</div>
1393+ <div [style.min-width]=cols[1].width>{{rowData['2']}}</div>
1394+ <div [style.min-width]=cols[2].width>{{rowData['3']}}</div>
1395+ <div [style.min-width]=cols[3].width>{{rowData['4']}}</div>
1396+ <div [style.min-width]=cols[4].width>{{rowData['5']}}</div>
1397+ </div>
1398+ </ng-template>
1399+ </div>
1400+ `
1401+ } )
1402+ export class VerticalVirtualDestroyComponent extends VerticalVirtualComponent {
13591403 public exists = true ;
13601404}
13611405
0 commit comments