@@ -20,14 +20,7 @@ describe('get-routes', () => {
2020 it ( 'reads an eager component' , async ( ) => {
2121 const routes = await routesFor ( `[{ path: 'about', component: AboutComponent }]` ) ;
2222 expect ( routes ) . toEqual ( [
23- {
24- path : 'about' ,
25- component : 'AboutComponent' ,
26- redirectTo : undefined ,
27- title : undefined ,
28- hasChildren : false ,
29- file : 'src/app.routes.ts' ,
30- } ,
23+ { path : 'about' , component : 'AboutComponent' , hasChildren : false , file : 'src/app.routes.ts' } ,
3124 ] ) ;
3225 } ) ;
3326
@@ -71,47 +64,100 @@ describe('get-routes', () => {
7164 expect ( routes ) . toEqual ( [
7265 {
7366 path : '' ,
74- component : undefined ,
7567 redirectTo : 'home' ,
76- title : undefined ,
7768 hasChildren : false ,
7869 file : 'src/app.routes.ts' ,
7970 } ,
8071 {
8172 path : 'home' ,
8273 component : 'HomeComponent' ,
83- redirectTo : undefined ,
8474 title : 'Home' ,
8575 hasChildren : false ,
8676 file : 'src/app.routes.ts' ,
8777 } ,
8878 {
8979 path : 'dashboard' ,
9080 component : 'DashboardComponent' ,
91- redirectTo : undefined ,
9281 title : 'Dashboard' ,
9382 hasChildren : true ,
9483 file : 'src/app.routes.ts' ,
9584 } ,
9685 {
9786 path : 'stats' ,
9887 component : 'StatsComponent' ,
99- redirectTo : undefined ,
100- title : undefined ,
10188 hasChildren : false ,
10289 file : 'src/app.routes.ts' ,
10390 } ,
10491 ] ) ;
10592 } ) ;
10693
107- it ( 'handles function or expression title / redirectTo gracefully ' , async ( ) => {
94+ it ( 'marks function or expression title / redirectTo as (dynamic) ' , async ( ) => {
10895 const routes = await routesFor ( `[
10996 { path: 'custom-title', component: HomeComponent, title: customTitleResolver },
11097 { path: 'custom-redirect', redirectTo: () => '/fallback' },
98+ { path: 'template-title', component: HomeComponent, title: \`Home \${id}\` },
11199 ]` ) ;
112100 expect ( routes . map ( ( r ) => [ r . path , r . title , r . redirectTo ] ) ) . toEqual ( [
113- [ 'custom-title' , undefined , undefined ] ,
114- [ 'custom-redirect' , undefined , undefined ] ,
101+ [ 'custom-title' , '(dynamic)' , undefined ] ,
102+ [ 'custom-redirect' , undefined , '(dynamic)' ] ,
103+ [ 'template-title' , '(dynamic)' , undefined ] ,
104+ ] ) ;
105+ } ) ;
106+
107+ it ( 'handles string literal escapes, unescapes, and concatenated non-literals' , async ( ) => {
108+ const routes = await routesFor ( `[
109+ { path: 'about', title: 'It\\'s "special"', redirectTo: "my/\\"path\\"" },
110+ { path: 'a' + 'b', component: Nope },
111+ ]` ) ;
112+ expect ( routes ) . toEqual ( [
113+ {
114+ path : 'about' ,
115+ title : 'It\'s "special"' ,
116+ redirectTo : 'my/"path"' ,
117+ hasChildren : false ,
118+ file : 'src/app.routes.ts' ,
119+ } ,
120+ ] ) ;
121+ } ) ;
122+
123+ it ( 'reads redirectTo and title on nested child routes and wildcard routes' , async ( ) => {
124+ const routes = await routesFor ( `[
125+ {
126+ path: 'admin',
127+ title: 'Admin Panel',
128+ children: [
129+ { path: '', redirectTo: 'overview', pathMatch: 'full' },
130+ { path: 'overview', component: AdminOverview, title: 'Overview' },
131+ ],
132+ },
133+ { path: '**', redirectTo: '' },
134+ ]` ) ;
135+ expect ( routes ) . toEqual ( [
136+ {
137+ path : 'admin' ,
138+ title : 'Admin Panel' ,
139+ hasChildren : true ,
140+ file : 'src/app.routes.ts' ,
141+ } ,
142+ {
143+ path : '' ,
144+ redirectTo : 'overview' ,
145+ hasChildren : false ,
146+ file : 'src/app.routes.ts' ,
147+ } ,
148+ {
149+ path : 'overview' ,
150+ component : 'AdminOverview' ,
151+ title : 'Overview' ,
152+ hasChildren : false ,
153+ file : 'src/app.routes.ts' ,
154+ } ,
155+ {
156+ path : '**' ,
157+ redirectTo : '' ,
158+ hasChildren : false ,
159+ file : 'src/app.routes.ts' ,
160+ } ,
115161 ] ) ;
116162 } ) ;
117163
0 commit comments