@@ -29,6 +29,7 @@ import {DirectiveResolver} from 'angular2/src/core/compiler/directive_resolver';
2929import { Component } from 'angular2/annotations' ;
3030import { AppViewManager } from 'angular2/src/core/compiler/view_manager' ;
3131import { AppViewManagerUtils } from 'angular2/src/core/compiler/view_manager_utils' ;
32+ import { AppViewListener } from 'angular2/src/core/compiler/view_listener' ;
3233import { AppViewPool } from 'angular2/src/core/compiler/view_pool' ;
3334
3435export function main ( ) {
@@ -37,6 +38,7 @@ export function main() {
3738 describe ( 'AppViewManager' , ( ) => {
3839 var renderer ;
3940 var utils ;
41+ var viewListener ;
4042 var viewPool ;
4143 var manager ;
4244 var directiveResolver ;
@@ -113,8 +115,9 @@ export function main() {
113115 directiveResolver = new DirectiveResolver ( ) ;
114116 renderer = new SpyRenderer ( ) ;
115117 utils = new SpyAppViewManagerUtils ( ) ;
118+ viewListener = new SpyAppViewListener ( ) ;
116119 viewPool = new SpyAppViewPool ( ) ;
117- manager = new AppViewManager ( viewPool , utils , renderer ) ;
120+ manager = new AppViewManager ( viewPool , viewListener , utils , renderer ) ;
118121 createdViews = [ ] ;
119122 createdRenderViews = [ ] ;
120123
@@ -149,6 +152,7 @@ export function main() {
149152 ListWrapper . push ( createdRenderViews , rv ) ;
150153 return rv ;
151154 } ) ;
155+ viewPool . spy ( 'returnView' ) . andReturn ( true ) ;
152156 } ) ;
153157
154158 describe ( 'createDynamicComponentView' , ( ) => {
@@ -165,6 +169,7 @@ export function main() {
165169 elementRef ( wrapView ( hostView ) , 0 ) , wrapPv ( componentProtoView ) , null , null ) ) )
166170 . toBe ( createdViews [ 0 ] ) ;
167171 expect ( createdViews [ 0 ] . proto ) . toBe ( componentProtoView ) ;
172+ expect ( viewListener . spy ( 'viewCreated' ) ) . toHaveBeenCalledWith ( createdViews [ 0 ] ) ;
168173 } ) ;
169174
170175 it ( 'should get the view from the pool' , ( ) => {
@@ -178,6 +183,7 @@ export function main() {
178183 . toBe ( createdView ) ;
179184 expect ( utils . spy ( 'createView' ) ) . not . toHaveBeenCalled ( ) ;
180185 expect ( renderer . spy ( 'createView' ) ) . not . toHaveBeenCalled ( ) ;
186+ expect ( viewListener . spy ( 'viewCreated' ) ) . not . toHaveBeenCalled ( ) ;
181187 } ) ;
182188
183189 it ( 'should attach the view' , ( ) => {
@@ -315,6 +321,7 @@ export function main() {
315321 wrapPv ( hostProtoView ) , null ) ) )
316322 . toBe ( createdViews [ 0 ] ) ;
317323 expect ( createdViews [ 0 ] . proto ) . toBe ( hostProtoView ) ;
324+ expect ( viewListener . spy ( 'viewCreated' ) ) . toHaveBeenCalledWith ( createdViews [ 0 ] ) ;
318325 } ) ;
319326
320327 it ( 'should attachAndHydrate the view' , ( ) => {
@@ -377,7 +384,16 @@ export function main() {
377384 it ( 'should return the view to the pool' , ( ) => {
378385 manager . destroyFreeHostView ( elementRef ( wrapView ( parentHostView ) , 0 ) , wrapView ( hostView ) ) ;
379386 expect ( viewPool . spy ( 'returnView' ) ) . toHaveBeenCalledWith ( hostView ) ;
387+ expect ( renderer . spy ( 'destroyView' ) ) . not . toHaveBeenCalled ( ) ;
380388 } ) ;
389+
390+ it ( 'should destroy the view if the pool is full' , ( ) => {
391+ viewPool . spy ( 'returnView' ) . andReturn ( false ) ;
392+ manager . destroyFreeHostView ( elementRef ( wrapView ( parentHostView ) , 0 ) , wrapView ( hostView ) ) ;
393+ expect ( renderer . spy ( 'destroyView' ) ) . toHaveBeenCalledWith ( hostView . render ) ;
394+ expect ( viewListener . spy ( 'viewDestroyed' ) ) . toHaveBeenCalledWith ( hostView ) ;
395+ } ) ;
396+
381397 } ) ;
382398
383399 describe ( 'recursively destroy inPlaceHostViews' , ( ) => {
@@ -395,6 +411,7 @@ export function main() {
395411 expect ( internalView ( manager . createRootHostView ( wrapPv ( hostProtoView ) , null , null ) ) )
396412 . toBe ( createdViews [ 0 ] ) ;
397413 expect ( createdViews [ 0 ] . proto ) . toBe ( hostProtoView ) ;
414+ expect ( viewListener . spy ( 'viewCreated' ) ) . toHaveBeenCalledWith ( createdViews [ 0 ] ) ;
398415 } ) ;
399416
400417 it ( 'should hydrate the view' , ( ) => {
@@ -444,6 +461,7 @@ export function main() {
444461 it ( 'should destroy the render view' , ( ) => {
445462 manager . destroyRootHostView ( wrapView ( hostView ) ) ;
446463 expect ( renderer . spy ( 'destroyView' ) ) . toHaveBeenCalledWith ( hostRenderViewRef ) ;
464+ expect ( viewListener . spy ( 'viewDestroyed' ) ) . toHaveBeenCalledWith ( hostView ) ;
447465 } ) ;
448466
449467 it ( 'should not return the view to the pool' , ( ) => {
@@ -473,6 +491,7 @@ export function main() {
473491 wrapPv ( childProtoView ) , null ) ) )
474492 . toBe ( createdViews [ 0 ] ) ;
475493 expect ( createdViews [ 0 ] . proto ) . toBe ( childProtoView ) ;
494+ expect ( viewListener . spy ( 'viewCreated' ) ) . toHaveBeenCalledWith ( createdViews [ 0 ] ) ;
476495 } ) ;
477496
478497 it ( 'should attach the view' , ( ) => {
@@ -622,6 +641,13 @@ class SpyAppViewManagerUtils extends SpyObject {
622641 noSuchMethod ( m ) { return super . noSuchMethod ( m ) }
623642}
624643
644+ @proxy
645+ @IMPLEMENTS ( AppViewListener )
646+ class SpyAppViewListener extends SpyObject {
647+ constructor ( ) { super ( AppViewListener ) ; }
648+ noSuchMethod ( m ) { return super . noSuchMethod ( m ) }
649+ }
650+
625651@proxy
626652@IMPLEMENTS ( ElementInjector )
627653class SpyElementInjector extends SpyObject {
0 commit comments