@@ -3,7 +3,7 @@ import * as util from './util';
33
44describe ( 'util' , ( ) => {
55 describe ( 'extractDeepLinkPathData' , ( ) => {
6- /* it('should return the deep link metadata', () => {
6+ it ( 'should return the parsed deep link metadata' , ( ) => {
77 const fileContent = `
88import { NgModule } from '@angular/core';
99import { IonicApp, IonicModule } from 'ionic-angular';
@@ -33,27 +33,92 @@ export function getSharedIonicModule() {
3333 return IonicModule.forRoot(MyApp, {}, {
3434 links: [
3535 { loadChildren: '../pages/home/home.module#HomePageModule', name: 'Home' },
36- { loadChildren: '../pages/page-one/page-one.module#PageOneModule', name: 'PageOne' },
37- { loadChildren: '../pages/page-two/page-two.module#PageTwoModule', name: 'PageTwo' }
36+ { name: "PageOne", loadChildren: "../pages/page-one/page-one.module#PageOneModule" },
37+ { loadChildren: \`../pages/page-two/page-two.module#PageTwoModule\`, name: \`PageTwo\` },
38+ { Component: MyComponent, name: 'SomePage'},
39+ { name: 'SomePage2', Component: MyComponent2 }
3840 ]
3941 });
4042}
4143 ` ;
4244 const results = util . extractDeepLinkPathData ( fileContent ) ;
43-
4445 expect ( results ) . toBeTruthy ( ) ;
45- expect(Array.isArray(results)).toBeTruthy();
46- expect(results[0].modulePath).toEqual('../pages/home/home.module');
47- expect(results[0].namedExport).toEqual('HomePageModule');
48- expect(results[0].name).toEqual('Home');
49- expect(results[1].modulePath).toEqual('../pages/page-one/page-one.module');
50- expect(results[1].namedExport).toEqual('PageOneModule');
51- expect(results[1].name).toEqual('PageOne');
52- expect(results[2].modulePath).toEqual('../pages/page-two/page-two.module');
53- expect(results[2].namedExport).toEqual('PageTwoModule');
54- expect(results[2].name).toEqual('PageTwo');
46+
47+ expect ( results [ 0 ] . component ) . toEqual ( null ) ;
48+ expect ( results [ 0 ] . name ) . toBe ( 'Home' ) ;
49+ expect ( results [ 0 ] . modulePath ) . toBe ( '../pages/home/home.module' ) ;
50+ expect ( results [ 0 ] . namedExport ) . toBe ( 'HomePageModule' ) ;
51+
52+ expect ( results [ 1 ] . component ) . toEqual ( null ) ;
53+ expect ( results [ 1 ] . name ) . toBe ( 'PageOne' ) ;
54+ expect ( results [ 1 ] . modulePath ) . toBe ( '../pages/page-one/page-one.module' ) ;
55+ expect ( results [ 1 ] . namedExport ) . toBe ( 'PageOneModule' ) ;
56+
57+ expect ( results [ 2 ] . component ) . toEqual ( null ) ;
58+ expect ( results [ 2 ] . name ) . toBe ( 'PageTwo' ) ;
59+ expect ( results [ 2 ] . modulePath ) . toBe ( '../pages/page-two/page-two.module' ) ;
60+ expect ( results [ 2 ] . namedExport ) . toBe ( 'PageTwoModule' ) ;
61+
62+ expect ( results [ 3 ] . component ) . toEqual ( 'MyComponent' ) ;
63+ expect ( results [ 3 ] . name ) . toBe ( 'SomePage' ) ;
64+ expect ( results [ 3 ] . modulePath ) . toBe ( null ) ;
65+ expect ( results [ 3 ] . namedExport ) . toBe ( null ) ;
66+
67+ expect ( results [ 4 ] . component ) . toEqual ( 'MyComponent2' ) ;
68+ expect ( results [ 4 ] . name ) . toBe ( 'SomePage2' ) ;
69+ expect ( results [ 4 ] . modulePath ) . toBe ( null ) ;
70+ expect ( results [ 4 ] . namedExport ) . toBe ( null ) ;
71+ } ) ;
72+
73+ it ( 'should throw an exception when there is an invalid deep link config' , ( ) => {
74+ // arrange
75+ const fileContent = `
76+ import { NgModule } from '@angular/core';
77+ import { IonicApp, IonicModule } from 'ionic-angular';
78+ import { MyApp } from './app.component';
79+ import { HomePage } from '../pages/home/home';
80+
81+ import * as Constants from '../util/constants';
82+
83+ @NgModule({
84+ declarations: [
85+ MyApp,
86+ HomePage
87+ ],
88+ imports: [
89+ getSharedIonicModule()
90+ ],
91+ bootstrap: [IonicApp],
92+ entryComponents: [
93+ MyApp,
94+ HomePage
95+ ],
96+ providers: []
97+ })
98+ export class AppModule {}
99+
100+ export function getSharedIonicModule() {
101+ return IonicModule.forRoot(MyApp, {}, {
102+ links: [
103+ { loadChildren: '../pages/home/home.module#HomePageModule'},
104+ { name: "PageOne", loadChildren: "../pages/page-one/page-one.module#PageOneModule" },
105+ { loadChildren: \`../pages/page-two/page-two.module#PageTwoModule\`, name: \`PageTwo\` },
106+ { Component: MyComponent, name: 'SomePage'},
107+ { name: 'SomePage2', Component: MyComponent2 }
108+ ]
109+ });
110+ }
111+ ` ;
112+ // act
113+ const knownMessage = 'Should never get here' ;
114+ try {
115+ util . extractDeepLinkPathData ( fileContent ) ;
116+ throw new Error ( knownMessage ) ;
117+ } catch ( ex ) {
118+ // assert
119+ expect ( ex . message ) . not . toEqual ( knownMessage ) ;
120+ }
55121 } ) ;
56- */
57122 } ) ;
58123
59124 describe ( 'getDeepLinkData' , ( ) => {
@@ -126,8 +191,9 @@ export function getSharedIonicModule() {
126191 return IonicModule.forRoot(MyApp, {}, {
127192 links: [
128193 { loadChildren: '../pages/home/home.module#HomePageModule', name: 'Home' },
129- { loadChildren: '../pages/page-one/page-one.module#PageOneModule', name: 'PageOne' },
130- { loadChildren: '../pages/page-two/page-two.module#PageTwoModule', name: 'PageTwo' }
194+ { name: "PageOne", loadChildren: "../pages/page-one/page-one.module#PageOneModule" },
195+ { loadChildren: \`../pages/page-two/page-two.module#PageTwoModule\`, name: \`PageTwo\` },
196+ { Component: MyComponent, name: 'SomePage'},
131197 ]
132198 });
133199}
@@ -136,20 +202,31 @@ export function getSharedIonicModule() {
136202 const srcDir = '/Users/dan/Dev/myApp/src' ;
137203 const result = util . getDeepLinkData ( join ( srcDir , 'app/app.module.ts' ) , fileContent , false ) ;
138204 expect ( result [ 0 ] . modulePath ) . toEqual ( '../pages/home/home.module' ) ;
205+ expect ( result [ 0 ] . namedExport ) . toEqual ( 'HomePageModule' ) ;
139206 expect ( result [ 0 ] . name ) . toEqual ( 'Home' ) ;
207+ expect ( result [ 0 ] . component ) . toEqual ( null ) ;
140208 expect ( result [ 0 ] . absolutePath ) . toEqual ( '/Users/dan/Dev/myApp/src/pages/home/home.module.ts' ) ;
141209
142210 expect ( result [ 1 ] . modulePath ) . toEqual ( '../pages/page-one/page-one.module' ) ;
211+ expect ( result [ 1 ] . namedExport ) . toEqual ( 'PageOneModule' ) ;
143212 expect ( result [ 1 ] . name ) . toEqual ( 'PageOne' ) ;
213+ expect ( result [ 1 ] . component ) . toEqual ( null ) ;
144214 expect ( result [ 1 ] . absolutePath ) . toEqual ( '/Users/dan/Dev/myApp/src/pages/page-one/page-one.module.ts' ) ;
145215
146216 expect ( result [ 2 ] . modulePath ) . toEqual ( '../pages/page-two/page-two.module' ) ;
217+ expect ( result [ 2 ] . namedExport ) . toEqual ( 'PageTwoModule' ) ;
147218 expect ( result [ 2 ] . name ) . toEqual ( 'PageTwo' ) ;
219+ expect ( result [ 2 ] . component ) . toEqual ( null ) ;
148220 expect ( result [ 2 ] . absolutePath ) . toEqual ( '/Users/dan/Dev/myApp/src/pages/page-two/page-two.module.ts' ) ;
149221
222+ expect ( result [ 3 ] . modulePath ) . toEqual ( null ) ;
223+ expect ( result [ 3 ] . namedExport ) . toEqual ( null ) ;
224+ expect ( result [ 3 ] . name ) . toEqual ( 'SomePage' ) ;
225+ expect ( result [ 3 ] . component ) . toEqual ( 'MyComponent' ) ;
226+ expect ( result [ 3 ] . absolutePath ) . toEqual ( null ) ;
150227 } ) ;
151228
152- /* it('should return a deep link data adjusted for AoT', () => {
229+ it ( 'should return a deep link data adjusted for AoT' , ( ) => {
153230
154231 const fileContent = `
155232import { NgModule } from '@angular/core';
@@ -180,9 +257,9 @@ export function getSharedIonicModule() {
180257 return IonicModule.forRoot(MyApp, {}, {
181258 links: [
182259 { loadChildren: '../pages/home/home.module#HomePageModule', name: 'Home' },
183- { loadChildren: ' ../pages/page-one/page-one.module#PageOneModule', name: 'PageOne' },
184- { loadChildren: ' ../pages/page-two/page-two.module#PageTwoModule' , name: ' PageTwo' },
185- { loadChildren: '../pages/page-three/page-three.module#PageThreeModule' , name: 'PageThree' }
260+ { name: "PageOne", loadChildren: " ../pages/page-one/page-one.module#PageOneModule" },
261+ { loadChildren: \` ../pages/page-two/page-two.module#PageTwoModule\` , name: \` PageTwo\` },
262+ { Component: MyComponent , name: 'SomePage'},
186263 ]
187264 });
188265}
@@ -193,18 +270,132 @@ export function getSharedIonicModule() {
193270 expect ( result [ 0 ] . modulePath ) . toEqual ( '../pages/home/home.module.ngfactory' ) ;
194271 expect ( result [ 0 ] . namedExport ) . toEqual ( 'HomePageModuleNgFactory' ) ;
195272 expect ( result [ 0 ] . name ) . toEqual ( 'Home' ) ;
273+ expect ( result [ 0 ] . component ) . toEqual ( null ) ;
196274 expect ( result [ 0 ] . absolutePath ) . toEqual ( '/Users/dan/Dev/myApp/src/pages/home/home.module.ngfactory.ts' ) ;
197275
198276 expect ( result [ 1 ] . modulePath ) . toEqual ( '../pages/page-one/page-one.module.ngfactory' ) ;
199277 expect ( result [ 1 ] . namedExport ) . toEqual ( 'PageOneModuleNgFactory' ) ;
200278 expect ( result [ 1 ] . name ) . toEqual ( 'PageOne' ) ;
279+ expect ( result [ 1 ] . component ) . toEqual ( null ) ;
201280 expect ( result [ 1 ] . absolutePath ) . toEqual ( '/Users/dan/Dev/myApp/src/pages/page-one/page-one.module.ngfactory.ts' ) ;
202281
203282 expect ( result [ 2 ] . modulePath ) . toEqual ( '../pages/page-two/page-two.module.ngfactory' ) ;
204283 expect ( result [ 2 ] . namedExport ) . toEqual ( 'PageTwoModuleNgFactory' ) ;
205284 expect ( result [ 2 ] . name ) . toEqual ( 'PageTwo' ) ;
285+ expect ( result [ 2 ] . component ) . toEqual ( null ) ;
206286 expect ( result [ 2 ] . absolutePath ) . toEqual ( '/Users/dan/Dev/myApp/src/pages/page-two/page-two.module.ngfactory.ts' ) ;
287+
288+ expect ( result [ 3 ] . modulePath ) . toEqual ( null ) ;
289+ expect ( result [ 3 ] . namedExport ) . toEqual ( null ) ;
290+ expect ( result [ 3 ] . name ) . toEqual ( 'SomePage' ) ;
291+ expect ( result [ 3 ] . component ) . toEqual ( 'MyComponent' ) ;
292+ expect ( result [ 3 ] . absolutePath ) . toEqual ( null ) ;
293+ } ) ;
294+ } ) ;
295+
296+ describe ( 'validateDeepLinks' , ( ) => {
297+ it ( 'should return false when one entry is missing name' , ( ) => {
298+ // arrange
299+ const invalidDeepLinkConfig : any = {
300+ name : null ,
301+ component : { }
302+ } ;
303+ // act
304+ const result = util . validateDeepLinks ( [ invalidDeepLinkConfig ] ) ;
305+
306+ // assert
307+ expect ( result ) . toEqual ( false ) ;
308+ } ) ;
309+
310+ it ( 'should return false when one entry has empty name' , ( ) => {
311+ // arrange
312+ const invalidDeepLinkConfig : any = {
313+ name : '' ,
314+ component : { }
315+ } ;
316+ // act
317+ const result = util . validateDeepLinks ( [ invalidDeepLinkConfig ] ) ;
318+
319+ // assert
320+ expect ( result ) . toEqual ( false ) ;
321+ } ) ;
322+
323+ it ( 'should return false when missing component and (modulePath or namedExport)' , ( ) => {
324+ // arrange
325+ const invalidDeepLinkConfig : any = {
326+ name : 'someName' ,
327+ component : null ,
328+ modulePath : null
329+ } ;
330+
331+ // act
332+ const result = util . validateDeepLinks ( [ invalidDeepLinkConfig ] ) ;
333+
334+ // assert
335+ expect ( result ) . toEqual ( false ) ;
336+ } ) ;
337+
338+ it ( 'should return false when missing component and (modulePath or namedExport)' , ( ) => {
339+ // arrange
340+ const invalidDeepLinkConfig : any = {
341+ name : 'someName' ,
342+ component : '' ,
343+ modulePath : ''
344+ } ;
345+
346+ // act
347+ const result = util . validateDeepLinks ( [ invalidDeepLinkConfig ] ) ;
348+
349+ // assert
350+ expect ( result ) . toEqual ( false ) ;
351+ } ) ;
352+
353+ it ( 'should return false when missing component and has valid modulePath but missing namedExport' , ( ) => {
354+ // arrange
355+ const invalidDeepLinkConfig : any = {
356+ name : 'someName' ,
357+ component : '' ,
358+ modulePath : 'somePath' ,
359+ namedExport : ''
360+ } ;
361+
362+ // act
363+ const result = util . validateDeepLinks ( [ invalidDeepLinkConfig ] ) ;
364+
365+ // assert
366+ expect ( result ) . toEqual ( false ) ;
367+ } ) ;
368+
369+ it ( 'should return true when it has a valid modulePath and namedExport' , ( ) => {
370+ // arrange
371+ const invalidDeepLinkConfig : any = {
372+ name : 'someName' ,
373+ component : '' ,
374+ modulePath : 'somePath' ,
375+ namedExport : 'someNamedExport'
376+ } ;
377+
378+ // act
379+ const result = util . validateDeepLinks ( [ invalidDeepLinkConfig ] ) ;
380+
381+ // assert
382+ expect ( result ) . toEqual ( true ) ;
383+ } ) ;
384+
385+ it ( 'should return true when it has a valid component' , ( ) => {
386+ // arrange
387+ const invalidDeepLinkConfig : any = {
388+ name : 'someName' ,
389+ component : 'MyComponent' ,
390+ modulePath : null ,
391+ namedExport : null
392+ } ;
393+
394+ // act
395+ const result = util . validateDeepLinks ( [ invalidDeepLinkConfig ] ) ;
396+
397+ // assert
398+ expect ( result ) . toEqual ( true ) ;
207399 } ) ;
208- */
209400 } ) ;
210401} ) ;
0 commit comments