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