import { mockNavController , mockView , mockViews } from '../../util/mock-providers' ; import { STATE_ATTACHED } from '../nav-util' ; describe ( 'ViewController' , ( ) => { describe ( 'willEnter' , ( ) => { it ( 'should emit LifeCycleEvent when called with component data' , ( done ) => { let viewController = mockView ( ) ; subscription = viewController . willEnter . subscribe ( ( event ) => { expect ( event ) . toEqual ( null ) ; done ( ) ; } , ( err ) => { done ( err ) ; } ) ; viewController . _state = STATE_ATTACHED ; viewController . _willEnter ( ) ; } , 10000 ) ; } ) ; describe ( 'didEnter' , ( ) => { it ( 'should emit LifeCycleEvent when called with component data' , ( done ) => { let viewController = mockView ( ) ; subscription = viewController . didEnter . subscribe ( ( event ) => { expect ( event ) . toEqual ( null ) ; done ( ) ; } , ( err ) => { done ( err ) ; } ) ; viewController . _state = STATE_ATTACHED ; viewController . _didEnter ( ) ; } , 10000 ) ; } ) ; describe ( 'willLeave' , ( ) => { it ( 'should emit LifeCycleEvent when called with component data' , ( done ) => { let viewController = mockView ( ) ; subscription = viewController . willLeave . subscribe ( ( event ) => { expect ( event ) . toEqual ( null ) ; done ( ) ; } , ( err ) => { done ( err ) ; } ) ; viewController . _state = STATE_ATTACHED ; viewController . _willLeave ( false ) ; } , 10000 ) ; } ) ; describe ( 'didLeave' , ( ) => { it ( 'should emit LifeCycleEvent when called with component data' , ( done ) => { let viewController = mockView ( ) ; subscription = viewController . didLeave . subscribe ( ( event ) => { expect ( event ) . toEqual ( null ) ; done ( ) ; } , ( err ) => { done ( err ) ; } ) ; viewController . _didLeave ( ) ; } , 10000 ) ; } ) ; describe ( 'willUnload' , ( ) => { it ( 'should emit LifeCycleEvent when called with component data' , ( done ) => { let viewController = mockView ( ) ; subscription = viewController . willUnload . subscribe ( ( event ) => { expect ( event ) . toEqual ( null ) ; done ( ) ; } , ( err ) => { done ( err ) ; } ) ; viewController . _willUnload ( ) ; } , 10000 ) ; } ) ; describe ( 'willDismiss' , ( ) => { it ( 'should have data in the willDismiss' , ( done ) => { let viewController = mockView ( ) ; let navControllerBase = mockNavController ( ) ; navControllerBase . _isPortal = true ; mockViews ( navControllerBase , [ viewController ] ) ; viewController . onWillDismiss ( ( data ) => { expect ( data ) . toEqual ( 'willDismiss data' ) ; done ( ) ; } ) ; viewController . dismiss ( 'willDismiss data' ) ; } , 10000 ) ; } ) ; describe ( 'didDismiss' , ( ) => { it ( 'should have data in the didDismiss' , ( done ) => { let viewController = mockView ( ) ; let navControllerBase = mockNavController ( ) ; navControllerBase . _isPortal = true ; mockViews ( navControllerBase , [ viewController ] ) ; viewController . onDidDismiss ( ( data ) => { expect ( data ) . toEqual ( 'didDismiss data' ) ; done ( ) ; } ) ; viewController . dismiss ( 'didDismiss data' ) ; } , 10000 ) ; it ( 'should not crash when calling dismiss() twice' , ( done ) => { let viewController = mockView ( ) ; let navControllerBase = mockNavController ( ) ; navControllerBase . _isPortal = true ; mockViews ( navControllerBase , [ viewController ] ) ; viewController . onDidDismiss ( ( data ) => { expect ( data ) . toEqual ( 'didDismiss data' ) ; setTimeout ( ( ) => { viewController . dismiss ( ) ; done ( ) ; } , 100 ) ; } ) ; viewController . dismiss ( 'didDismiss data' ) ; } , 10000 ) ; } ) ; afterEach ( ( ) => { if ( subscription ) { subscription . unsubscribe ( ) ; } } ) ; let subscription = null ; } ) ;