@@ -12,7 +12,6 @@ import {
12
12
NgZone ,
13
13
TrackByFunction ,
14
14
ViewChild ,
15
- ViewContainerRef ,
16
15
ViewEncapsulation
17
16
} from '@angular/core' ;
18
17
import { ComponentFixture , fakeAsync , flush , inject , TestBed } from '@angular/core/testing' ;
@@ -486,49 +485,51 @@ describe('CdkVirtualScrollViewport', () => {
486
485
487
486
it ( 'should trackBy value by default' , fakeAsync ( ( ) => {
488
487
testComponent . items = [ ] ;
489
- spyOn ( testComponent . virtualForViewContainer , 'detach ' ) . and . callThrough ( ) ;
488
+ spyOn < any > ( testComponent . virtualForOf , '_detachView ' ) . and . callThrough ( ) ;
490
489
finishInit ( fixture ) ;
491
490
492
491
testComponent . items = [ 0 ] ;
493
492
fixture . detectChanges ( ) ;
494
493
flush ( ) ;
495
494
496
- expect ( testComponent . virtualForViewContainer . detach ) . not . toHaveBeenCalled ( ) ;
495
+ expect ( ( testComponent . virtualForOf as any ) . _detachView ) . not . toHaveBeenCalled ( ) ;
497
496
498
497
testComponent . items = [ 1 ] ;
499
498
fixture . detectChanges ( ) ;
500
499
flush ( ) ;
501
500
502
- expect ( testComponent . virtualForViewContainer . detach ) . toHaveBeenCalled ( ) ;
501
+ expect ( ( testComponent . virtualForOf as any ) . _detachView ) . toHaveBeenCalled ( ) ;
503
502
} ) ) ;
504
503
505
504
it ( 'should trackBy index when specified' , fakeAsync ( ( ) => {
506
505
testComponent . trackBy = i => i ;
507
506
testComponent . items = [ ] ;
508
- spyOn ( testComponent . virtualForViewContainer , 'detach ' ) . and . callThrough ( ) ;
507
+ spyOn < any > ( testComponent . virtualForOf , '_detachView ' ) . and . callThrough ( ) ;
509
508
finishInit ( fixture ) ;
510
509
511
510
testComponent . items = [ 0 ] ;
512
511
fixture . detectChanges ( ) ;
513
512
flush ( ) ;
514
513
515
- expect ( testComponent . virtualForViewContainer . detach ) . not . toHaveBeenCalled ( ) ;
514
+ expect ( ( testComponent . virtualForOf as any ) . _detachView ) . not . toHaveBeenCalled ( ) ;
516
515
517
516
testComponent . items = [ 1 ] ;
518
517
fixture . detectChanges ( ) ;
519
518
flush ( ) ;
520
519
521
- expect ( testComponent . virtualForViewContainer . detach ) . not . toHaveBeenCalled ( ) ;
520
+ expect ( ( testComponent . virtualForOf as any ) . _detachView ) . not . toHaveBeenCalled ( ) ;
522
521
} ) ) ;
523
522
524
523
it ( 'should recycle views when template cache is large enough to accommodate' , fakeAsync ( ( ) => {
525
524
testComponent . trackBy = i => i ;
526
- const spy =
527
- spyOn ( testComponent . virtualForViewContainer , 'createEmbeddedView' ) . and . callThrough ( ) ;
525
+ const spy = spyOn < any > ( testComponent . virtualForOf , '_createEmbeddedViewAt' )
526
+ . and . callThrough ( ) ;
527
+
528
528
finishInit ( fixture ) ;
529
529
530
530
// Should create views for the initial rendered items.
531
- expect ( testComponent . virtualForViewContainer . createEmbeddedView ) . toHaveBeenCalledTimes ( 4 ) ;
531
+ expect ( ( testComponent . virtualForOf as any ) . _createEmbeddedViewAt )
532
+ . toHaveBeenCalledTimes ( 4 ) ;
532
533
533
534
spy . calls . reset ( ) ;
534
535
triggerScroll ( viewport , 10 ) ;
@@ -538,7 +539,8 @@ describe('CdkVirtualScrollViewport', () => {
538
539
// As we first start to scroll we need to create one more item. This is because the first item
539
540
// is still partially on screen and therefore can't be removed yet. At the same time a new
540
541
// item is now partially on the screen at the bottom and so a new view is needed.
541
- expect ( testComponent . virtualForViewContainer . createEmbeddedView ) . toHaveBeenCalledTimes ( 1 ) ;
542
+ expect ( ( testComponent . virtualForOf as any ) . _createEmbeddedViewAt )
543
+ . toHaveBeenCalledTimes ( 1 ) ;
542
544
543
545
spy . calls . reset ( ) ;
544
546
const maxOffset =
@@ -551,18 +553,21 @@ describe('CdkVirtualScrollViewport', () => {
551
553
552
554
// As we scroll through the rest of the items, no new views should be created, our existing 5
553
555
// can just be recycled as appropriate.
554
- expect ( testComponent . virtualForViewContainer . createEmbeddedView ) . not . toHaveBeenCalled ( ) ;
556
+ expect ( ( testComponent . virtualForOf as any ) . _createEmbeddedViewAt )
557
+ . not . toHaveBeenCalled ( ) ;
555
558
} ) ) ;
556
559
557
560
it ( 'should not recycle views when template cache is full' , fakeAsync ( ( ) => {
558
561
testComponent . trackBy = i => i ;
559
562
testComponent . templateCacheSize = 0 ;
560
- const spy =
561
- spyOn ( testComponent . virtualForViewContainer , 'createEmbeddedView' ) . and . callThrough ( ) ;
562
- finishInit ( fixture ) ;
563
+ const spy = spyOn < any > ( testComponent . virtualForOf , '_createEmbeddedViewAt' )
564
+ . and . callThrough ( ) ;
565
+
566
+ finishInit ( fixture ) ;
563
567
564
568
// Should create views for the initial rendered items.
565
- expect ( testComponent . virtualForViewContainer . createEmbeddedView ) . toHaveBeenCalledTimes ( 4 ) ;
569
+ expect ( ( testComponent . virtualForOf as any ) . _createEmbeddedViewAt )
570
+ . toHaveBeenCalledTimes ( 4 ) ;
566
571
567
572
spy . calls . reset ( ) ;
568
573
triggerScroll ( viewport , 10 ) ;
@@ -572,7 +577,8 @@ describe('CdkVirtualScrollViewport', () => {
572
577
// As we first start to scroll we need to create one more item. This is because the first item
573
578
// is still partially on screen and therefore can't be removed yet. At the same time a new
574
579
// item is now partially on the screen at the bottom and so a new view is needed.
575
- expect ( testComponent . virtualForViewContainer . createEmbeddedView ) . toHaveBeenCalledTimes ( 1 ) ;
580
+ expect ( ( testComponent . virtualForOf as any ) . _createEmbeddedViewAt )
581
+ . toHaveBeenCalledTimes ( 1 ) ;
576
582
577
583
spy . calls . reset ( ) ;
578
584
const maxOffset =
@@ -585,7 +591,8 @@ describe('CdkVirtualScrollViewport', () => {
585
591
586
592
// Since our template cache size is 0, as we scroll through the rest of the items, we need to
587
593
// create a new view for each one.
588
- expect ( testComponent . virtualForViewContainer . createEmbeddedView ) . toHaveBeenCalledTimes ( 5 ) ;
594
+ expect ( ( testComponent . virtualForOf as any ) . _createEmbeddedViewAt )
595
+ . toHaveBeenCalledTimes ( 5 ) ;
589
596
} ) ) ;
590
597
591
598
it ( 'should render up to maxBufferPx when buffer dips below minBufferPx' , fakeAsync ( ( ) => {
@@ -829,7 +836,6 @@ function triggerScroll(viewport: CdkVirtualScrollViewport, offset?: number) {
829
836
class FixedSizeVirtualScroll {
830
837
@ViewChild ( CdkVirtualScrollViewport ) viewport : CdkVirtualScrollViewport ;
831
838
@ViewChild ( CdkVirtualForOf ) virtualForOf : CdkVirtualForOf < any > ;
832
- @ViewChild ( CdkVirtualForOf , { read : ViewContainerRef } ) virtualForViewContainer : ViewContainerRef ;
833
839
834
840
@Input ( ) orientation = 'vertical' ;
835
841
@Input ( ) viewportSize = 200 ;
@@ -880,7 +886,6 @@ class FixedSizeVirtualScroll {
880
886
} )
881
887
class FixedSizeVirtualScrollWithRtlDirection {
882
888
@ViewChild ( CdkVirtualScrollViewport ) viewport : CdkVirtualScrollViewport ;
883
- @ViewChild ( CdkVirtualForOf , { read : ViewContainerRef } ) virtualForViewContainer : ViewContainerRef ;
884
889
885
890
@Input ( ) orientation = 'vertical' ;
886
891
@Input ( ) viewportSize = 200 ;
0 commit comments