@@ -360,55 +360,56 @@ describe('CdkVirtualScrollViewport', () => {
360
360
361
361
it ( 'should trackBy value by default' , fakeAsync ( ( ) => {
362
362
testComponent . items = [ ] ;
363
- spyOn ( testComponent . cdkForOfViewContainer , 'detach' ) . and . callThrough ( ) ;
363
+ spyOn ( testComponent . virtualForViewContainer , 'detach' ) . and . callThrough ( ) ;
364
364
finishInit ( fixture ) ;
365
365
366
366
testComponent . items = [ 0 ] ;
367
367
fixture . detectChanges ( ) ;
368
368
369
- expect ( testComponent . cdkForOfViewContainer . detach ) . not . toHaveBeenCalled ( ) ;
369
+ expect ( testComponent . virtualForViewContainer . detach ) . not . toHaveBeenCalled ( ) ;
370
370
371
371
testComponent . items = [ 1 ] ;
372
372
fixture . detectChanges ( ) ;
373
373
374
- expect ( testComponent . cdkForOfViewContainer . detach ) . toHaveBeenCalled ( ) ;
374
+ expect ( testComponent . virtualForViewContainer . detach ) . toHaveBeenCalled ( ) ;
375
375
} ) ) ;
376
376
377
377
it ( 'should trackBy index when specified' , fakeAsync ( ( ) => {
378
378
testComponent . trackBy = i => i ;
379
379
testComponent . items = [ ] ;
380
- spyOn ( testComponent . cdkForOfViewContainer , 'detach' ) . and . callThrough ( ) ;
380
+ spyOn ( testComponent . virtualForViewContainer , 'detach' ) . and . callThrough ( ) ;
381
381
finishInit ( fixture ) ;
382
382
383
383
testComponent . items = [ 0 ] ;
384
384
fixture . detectChanges ( ) ;
385
385
386
- expect ( testComponent . cdkForOfViewContainer . detach ) . not . toHaveBeenCalled ( ) ;
386
+ expect ( testComponent . virtualForViewContainer . detach ) . not . toHaveBeenCalled ( ) ;
387
387
388
388
testComponent . items = [ 1 ] ;
389
389
fixture . detectChanges ( ) ;
390
390
391
- expect ( testComponent . cdkForOfViewContainer . detach ) . not . toHaveBeenCalled ( ) ;
391
+ expect ( testComponent . virtualForViewContainer . detach ) . not . toHaveBeenCalled ( ) ;
392
392
} ) ) ;
393
393
394
394
it ( 'should recycle views when template cache is large enough to accommodate' , fakeAsync ( ( ) => {
395
395
testComponent . trackBy = i => i ;
396
- spyOn ( testComponent . cdkForOfViewContainer , 'createEmbeddedView' ) . and . callThrough ( ) ;
396
+ const spy =
397
+ spyOn ( testComponent . virtualForViewContainer , 'createEmbeddedView' ) . and . callThrough ( ) ;
397
398
finishInit ( fixture ) ;
398
399
399
400
// Should create views for the initial rendered items.
400
- expect ( testComponent . cdkForOfViewContainer . createEmbeddedView ) . toHaveBeenCalledTimes ( 4 ) ;
401
+ expect ( testComponent . virtualForViewContainer . createEmbeddedView ) . toHaveBeenCalledTimes ( 4 ) ;
401
402
402
- ( testComponent . cdkForOfViewContainer . createEmbeddedView as any ) . calls . reset ( ) ;
403
+ spy . calls . reset ( ) ;
403
404
triggerScroll ( viewport , 10 ) ;
404
405
fixture . detectChanges ( ) ;
405
406
406
407
// As we first start to scroll we need to create one more item. This is because the first item
407
408
// is still partially on screen and therefore can't be removed yet. At the same time a new
408
409
// item is now partially on the screen at the bottom and so a new view is needed.
409
- expect ( testComponent . cdkForOfViewContainer . createEmbeddedView ) . toHaveBeenCalledTimes ( 1 ) ;
410
+ expect ( testComponent . virtualForViewContainer . createEmbeddedView ) . toHaveBeenCalledTimes ( 1 ) ;
410
411
411
- ( testComponent . cdkForOfViewContainer . createEmbeddedView as any ) . calls . reset ( ) ;
412
+ spy . calls . reset ( ) ;
412
413
const maxOffset =
413
414
testComponent . itemSize * testComponent . items . length - testComponent . viewportSize ;
414
415
for ( let offset = 10 ; offset <= maxOffset ; offset += 10 ) {
@@ -418,28 +419,29 @@ describe('CdkVirtualScrollViewport', () => {
418
419
419
420
// As we scroll through the rest of the items, no new views should be created, our existing 5
420
421
// can just be recycled as appropriate.
421
- expect ( testComponent . cdkForOfViewContainer . createEmbeddedView ) . not . toHaveBeenCalled ( ) ;
422
+ expect ( testComponent . virtualForViewContainer . createEmbeddedView ) . not . toHaveBeenCalled ( ) ;
422
423
} ) ) ;
423
424
424
425
it ( 'should not recycle views when template cache is full' , fakeAsync ( ( ) => {
425
426
testComponent . trackBy = i => i ;
426
427
testComponent . templateCacheSize = 0 ;
427
- spyOn ( testComponent . cdkForOfViewContainer , 'createEmbeddedView' ) . and . callThrough ( ) ;
428
+ const spy =
429
+ spyOn ( testComponent . virtualForViewContainer , 'createEmbeddedView' ) . and . callThrough ( ) ;
428
430
finishInit ( fixture ) ;
429
431
430
432
// Should create views for the initial rendered items.
431
- expect ( testComponent . cdkForOfViewContainer . createEmbeddedView ) . toHaveBeenCalledTimes ( 4 ) ;
433
+ expect ( testComponent . virtualForViewContainer . createEmbeddedView ) . toHaveBeenCalledTimes ( 4 ) ;
432
434
433
- ( testComponent . cdkForOfViewContainer . createEmbeddedView as any ) . calls . reset ( ) ;
435
+ spy . calls . reset ( ) ;
434
436
triggerScroll ( viewport , 10 ) ;
435
437
fixture . detectChanges ( ) ;
436
438
437
439
// As we first start to scroll we need to create one more item. This is because the first item
438
440
// is still partially on screen and therefore can't be removed yet. At the same time a new
439
441
// item is now partially on the screen at the bottom and so a new view is needed.
440
- expect ( testComponent . cdkForOfViewContainer . createEmbeddedView ) . toHaveBeenCalledTimes ( 1 ) ;
442
+ expect ( testComponent . virtualForViewContainer . createEmbeddedView ) . toHaveBeenCalledTimes ( 1 ) ;
441
443
442
- ( testComponent . cdkForOfViewContainer . createEmbeddedView as any ) . calls . reset ( ) ;
444
+ spy . calls . reset ( ) ;
443
445
const maxOffset =
444
446
testComponent . itemSize * testComponent . items . length - testComponent . viewportSize ;
445
447
for ( let offset = 10 ; offset <= maxOffset ; offset += 10 ) {
@@ -449,7 +451,7 @@ describe('CdkVirtualScrollViewport', () => {
449
451
450
452
// Since our template cache size is 0, as we scroll through the rest of the items, we need to
451
453
// create a new view for each one.
452
- expect ( testComponent . cdkForOfViewContainer . createEmbeddedView ) . toHaveBeenCalledTimes ( 5 ) ;
454
+ expect ( testComponent . virtualForViewContainer . createEmbeddedView ) . toHaveBeenCalledTimes ( 5 ) ;
453
455
} ) ) ;
454
456
} ) ;
455
457
} ) ;
@@ -506,7 +508,7 @@ function triggerScroll(viewport: CdkVirtualScrollViewport, offset?: number) {
506
508
} )
507
509
class FixedVirtualScroll {
508
510
@ViewChild ( CdkVirtualScrollViewport ) viewport : CdkVirtualScrollViewport ;
509
- @ViewChild ( CdkVirtualForOf , { read : ViewContainerRef } ) cdkForOfViewContainer : ViewContainerRef ;
511
+ @ViewChild ( CdkVirtualForOf , { read : ViewContainerRef } ) virtualForViewContainer : ViewContainerRef ;
510
512
511
513
@Input ( ) orientation = 'vertical' ;
512
514
@Input ( ) viewportSize = 200 ;
0 commit comments