11//make sure you import mocha-config before @angular/core
22import { assert } from "./test-config" ;
3+
34import { Component , ElementRef , Renderer } from "@angular/core" ;
4- import { TestApp } from "./test-app" ;
5+ import { NavigationEnd , NavigationStart , NavigationError } from "@angular/router" ;
6+
7+ import { Subscription } from "rxjs" ;
8+ import { TestApp , bootstrapTestApp , destroyTestApp } from "./test-app" ;
59
610import { GestureComponent } from "../snippets/gestures.component" ;
711import { LayoutsComponent } from "../snippets/layouts.component" ;
812import { IconFontComponent } from "../snippets/icon-font.component" ;
913
14+ import { APP_ROUTER_PROVIDERS } from "../snippets/navigation/app.routes" ;
15+ import { PageNavigationApp } from "../snippets/navigation/page-outlet" ;
16+ import { NavigationApp } from "../snippets/navigation/router-outlet" ;
17+
1018import { device , platformNames } from "platform" ;
1119const IS_IOS = ( device . os === platformNames . ios ) ;
1220
@@ -47,3 +55,69 @@ describe('Snippets', () => {
4755 } ) ;
4856 } ) ;
4957} )
58+
59+ describe ( 'Snippets Navigation' , ( ) => {
60+ var runningApp : any ;
61+ var subscription : Subscription ;
62+
63+ var cleanup = ( ) => {
64+ if ( subscription ) {
65+ subscription . unsubscribe ( ) ;
66+ subscription = null ;
67+ }
68+ if ( runningApp ) {
69+ destroyTestApp ( runningApp ) ;
70+ runningApp = null ;
71+ }
72+ }
73+
74+ after ( cleanup ) ;
75+
76+ it ( "router-outlet app" , ( done ) => {
77+ bootstrapTestApp ( NavigationApp , [ APP_ROUTER_PROVIDERS ] ) . then ( ( app ) => {
78+ console . log ( "app bootstraped" ) ;
79+ runningApp = app ;
80+ var navStarted = false ;
81+
82+ subscription = app . router . events . subscribe ( ( e ) => {
83+ if ( e instanceof NavigationStart ) {
84+ assert . equal ( "/" , e . url ) ;
85+ navStarted = true ;
86+ }
87+ if ( e instanceof NavigationEnd ) {
88+ assert . isTrue ( navStarted , "No NavigationStart event" ) ;
89+ assert . equal ( "/" , e . url ) ;
90+ assert . equal ( "/first" , e . urlAfterRedirects ) ;
91+
92+ cleanup ( ) ;
93+ done ( ) ;
94+ }
95+ } )
96+ } )
97+ } ) ;
98+
99+ it ( "page-router-outlet app" , ( done ) => {
100+ console . log ( "------------- PageNavigationApp: " + PageNavigationApp ) ;
101+
102+ bootstrapTestApp ( PageNavigationApp , [ APP_ROUTER_PROVIDERS ] ) . then ( ( app ) => {
103+ console . log ( "app bootstraped" ) ;
104+ runningApp = app ;
105+ var navStarted = false ;
106+
107+ subscription = app . router . events . subscribe ( ( e ) => {
108+ if ( e instanceof NavigationStart ) {
109+ assert . equal ( "/" , e . url ) ;
110+ navStarted = true ;
111+ }
112+ if ( e instanceof NavigationEnd ) {
113+ assert . isTrue ( navStarted , "No NavigationStart event" ) ;
114+ assert . equal ( "/" , e . url ) ;
115+ assert . equal ( "/first" , e . urlAfterRedirects ) ;
116+
117+ cleanup ( ) ;
118+ done ( ) ;
119+ }
120+ } )
121+ } )
122+ } ) ;
123+ } ) ;
0 commit comments