Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit 6be05f9

Browse files
committed
test(deep-linking): update and add tests around IonicPageModule and compare to static, known NgModule content instead of generating it dynamically in the test
1 parent 0df246a commit 6be05f9

File tree

2 files changed

+90
-40
lines changed

2 files changed

+90
-40
lines changed

src/deep-linking/util.spec.ts

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ export function removeDecorators(fileName: string, source: string): string {
580580
it('should return non-aot adjusted paths when not in AoT', () => {
581581
const pageNgModuleContent = `
582582
import { NgModule } from '@angular/core';
583-
import { DeepLinkModule } from 'ionic-angular';
583+
import { IonicPageModule } from 'ionic-angular';
584584
585585
import { HomePage } from './home';
586586
@@ -589,7 +589,7 @@ import { HomePage } from './home';
589589
HomePage,
590590
],
591591
imports: [
592-
DeepLinkModule.forChild(HomePage),
592+
IonicPageModule.forChild(HomePage),
593593
]
594594
})
595595
export class HomePageModule {}
@@ -613,7 +613,7 @@ export class HomePageModule {}
613613
it('should return adjusted paths to account for AoT', () => {
614614
const pageNgModuleContent = `
615615
import { NgModule } from '@angular/core';
616-
import { DeepLinkModule } from 'ionic-angular';
616+
import { IonicPageModule } from 'ionic-angular';
617617
618618
import { HomePage } from './home';
619619
@@ -622,7 +622,7 @@ import { HomePage } from './home';
622622
HomePage,
623623
],
624624
imports: [
625-
DeepLinkModule.forChild(HomePage),
625+
IonicPageModule.forChild(HomePage),
626626
]
627627
})
628628
export class HomePageModule {}
@@ -676,14 +676,14 @@ export class PageOne {
676676
const pageOneNgModuleContent = `
677677
import { NgModule } from '@angular/core';
678678
import { PageOne } from './page-one';
679-
import { DeepLinkModule } from 'ionic-angular';
679+
import { IonicPageModule } from 'ionic-angular';
680680
681681
@NgModule({
682682
declarations: [
683683
PageOne,
684684
],
685685
imports: [
686-
DeepLinkModule.forChild(PageOne)
686+
IonicPageModule.forChild(PageOne)
687687
],
688688
entryComponents: [
689689
PageOne
@@ -739,14 +739,14 @@ export class PageTwo {
739739
const pageTwoNgModuleContent = `
740740
import { NgModule } from '@angular/core';
741741
import { PageTwo } from './page-two';
742-
import { DeepLinkModule } from 'ionic-angular';
742+
import { IonicPageModule } from 'ionic-angular';
743743
744744
@NgModule({
745745
declarations: [
746746
PageTwo,
747747
],
748748
imports: [
749-
DeepLinkModule.forChild(PageTwo)
749+
IonicPageModule.forChild(PageTwo)
750750
]
751751
})
752752
export class PageTwoModule {
@@ -786,14 +786,14 @@ export class PageThree {
786786
const pageSettingsNgModuleContent = `
787787
import { NgModule } from '@angular/core';
788788
import { PageThree } from './page-three';
789-
import { DeepLinkModule } from 'ionic-angular';
789+
import { IonicPageModule } from 'ionic-angular';
790790
791791
@NgModule({
792792
declarations: [
793793
PageThree,
794794
],
795795
imports: [
796-
DeepLinkModule.forChild(PageThree)
796+
IonicPageModule.forChild(PageThree)
797797
]
798798
})
799799
export class PageThreeModule {
@@ -863,14 +863,14 @@ export class PageOne {
863863
const pageOneNgModuleContent = `
864864
import { NgModule } from '@angular/core';
865865
import { PageOne } from './page-one';
866-
import { DeepLinkModule } from 'ionic-angular';
866+
import { IonicPageModule } from 'ionic-angular';
867867
868868
@NgModule({
869869
declarations: [
870870
PageOne,
871871
],
872872
imports: [
873-
DeepLinkModule.forChild(PageOne)
873+
IonicPageModule.forChild(PageOne)
874874
],
875875
entryComponents: [
876876
PageOne
@@ -926,14 +926,14 @@ export class PageTwo {
926926
const pageTwoNgModuleContent = `
927927
import { NgModule } from '@angular/core';
928928
import { PageTwo } from './page-two';
929-
import { DeepLinkModule } from 'ionic-angular';
929+
import { IonicPageModule } from 'ionic-angular';
930930
931931
@NgModule({
932932
declarations: [
933933
PageTwo,
934934
],
935935
imports: [
936-
DeepLinkModule.forChild(PageTwo)
936+
IonicPageModule.forChild(PageTwo)
937937
]
938938
})
939939
export class PageTwoModule {
@@ -972,14 +972,14 @@ export class PageThree {
972972
const pageSettingsNgModuleContent = `
973973
import { NgModule } from '@angular/core';
974974
import { PageThree } from './page-three';
975-
import { DeepLinkModule } from 'ionic-angular';
975+
import { IonicPageModule } from 'ionic-angular';
976976
977977
@NgModule({
978978
declarations: [
979979
PageThree,
980980
],
981981
imports: [
982-
DeepLinkModule.forChild(PageThree)
982+
IonicPageModule.forChild(PageThree)
983983
]
984984
})
985985
export class PageThreeModule {
@@ -1054,14 +1054,14 @@ export class PageOne {
10541054
const pageOneNgModuleContent = `
10551055
import { NgModule } from '@angular/core';
10561056
import { PageOne } from './page-one';
1057-
import { DeepLinkModule } from 'ionic-angular';
1057+
import { IonicPageModule } from 'ionic-angular';
10581058
10591059
@NgModule({
10601060
declarations: [
10611061
PageOne,
10621062
],
10631063
imports: [
1064-
DeepLinkModule.forChild(PageOne)
1064+
IonicPageModule.forChild(PageOne)
10651065
],
10661066
entryComponents: [
10671067
PageOne
@@ -1119,14 +1119,14 @@ export class PageTwo {
11191119
const pageTwoNgModuleContent = `
11201120
import { NgModule } from '@angular/core';
11211121
import { PageTwo } from './page-two';
1122-
import { DeepLinkModule } from 'ionic-angular';
1122+
import { IonicPageModule } from 'ionic-angular';
11231123
11241124
@NgModule({
11251125
declarations: [
11261126
PageTwo,
11271127
],
11281128
imports: [
1129-
DeepLinkModule.forChild(PageTwo)
1129+
IonicPageModule.forChild(PageTwo)
11301130
]
11311131
})
11321132
export class PageTwoModule {
@@ -1165,14 +1165,14 @@ export class PageThree {
11651165
const pageSettingsNgModuleContent = `
11661166
import { NgModule } from '@angular/core';
11671167
import { PageThree } from './page-three';
1168-
import { DeepLinkModule } from 'ionic-angular';
1168+
import { IonicPageModule } from 'ionic-angular';
11691169
11701170
@NgModule({
11711171
declarations: [
11721172
PageThree,
11731173
],
11741174
imports: [
1175-
DeepLinkModule.forChild(PageThree)
1175+
IonicPageModule.forChild(PageThree)
11761176
]
11771177
})
11781178
export class PageThreeModule {
@@ -1272,14 +1272,14 @@ export class PageOne {
12721272
const pageOneNgModuleContent = `
12731273
import { NgModule } from '@angular/core';
12741274
import { PageOne } from './page-one';
1275-
import { DeepLinkModule } from 'ionic-angular';
1275+
import { IonicPageModule } from 'ionic-angular';
12761276
12771277
@NgModule({
12781278
declarations: [
12791279
PageOne,
12801280
],
12811281
imports: [
1282-
DeepLinkModule.forChild(PageOne)
1282+
IonicPageModule.forChild(PageOne)
12831283
],
12841284
entryComponents: [
12851285
PageOne
@@ -1337,14 +1337,14 @@ export class PageTwo {
13371337
const pageTwoNgModuleContent = `
13381338
import { NgModule } from '@angular/core';
13391339
import { PageTwo } from './page-two';
1340-
import { DeepLinkModule } from 'ionic-angular';
1340+
import { IonicPageModule } from 'ionic-angular';
13411341
13421342
@NgModule({
13431343
declarations: [
13441344
PageTwo,
13451345
],
13461346
imports: [
1347-
DeepLinkModule.forChild(PageTwo)
1347+
IonicPageModule.forChild(PageTwo)
13481348
]
13491349
})
13501350
export class PageTwoModule {
@@ -1383,14 +1383,14 @@ export class PageThree {
13831383
const pageSettingsNgModuleContent = `
13841384
import { NgModule } from '@angular/core';
13851385
import { PageThree } from './page-three';
1386-
import { DeepLinkModule } from 'ionic-angular';
1386+
import { IonicPageModule } from 'ionic-angular';
13871387
13881388
@NgModule({
13891389
declarations: [
13901390
PageThree,
13911391
],
13921392
imports: [
1393-
DeepLinkModule.forChild(PageThree)
1393+
IonicPageModule.forChild(PageThree)
13941394
]
13951395
})
13961396
export class PageThreeModule {
@@ -1960,7 +1960,7 @@ class AppModuleInjector extends import0.ɵNgModuleInjector<import1.AppModule> {
19601960
_FormsModule_4:import4.FormsModule;
19611961
_ReactiveFormsModule_5:import4.ReactiveFormsModule;
19621962
_IonicModule_6:import5.IonicModule;
1963-
_DeepLinkModule_7:import5.DeepLinkModule;
1963+
_IonicPageModule_7:import5.IonicPageModule;
19641964
_HomePageModule_8:import6.HomePageModule;
19651965
_AppModule_9:import1.AppModule;
19661966
__LOCALE_ID_10:any;
@@ -2203,7 +2203,7 @@ class AppModuleInjector extends import0.ɵNgModuleInjector<import1.AppModule> {
22032203
this._FormsModule_4 = new import4.FormsModule();
22042204
this._ReactiveFormsModule_5 = new import4.ReactiveFormsModule();
22052205
this._IonicModule_6 = new import5.IonicModule();
2206-
this._DeepLinkModule_7 = new import5.DeepLinkModule();
2206+
this._IonicPageModule_7 = new import5.IonicPageModule();
22072207
this._HomePageModule_8 = new import6.HomePageModule();
22082208
this._AppModule_9 = new import1.AppModule();
22092209
this._ErrorHandler_12 = import3.ɵa();
@@ -2241,7 +2241,7 @@ class AppModuleInjector extends import0.ɵNgModuleInjector<import1.AppModule> {
22412241
if ((token === import4.FormsModule)) { return this._FormsModule_4; }
22422242
if ((token === import4.ReactiveFormsModule)) { return this._ReactiveFormsModule_5; }
22432243
if ((token === import5.IonicModule)) { return this._IonicModule_6; }
2244-
if ((token === import5.DeepLinkModule)) { return this._DeepLinkModule_7; }
2244+
if ((token === import5.IonicPageModule)) { return this._IonicPageModule_7; }
22452245
if ((token === import6.HomePageModule)) { return this._HomePageModule_8; }
22462246
if ((token === import1.AppModule)) { return this._AppModule_9; }
22472247
if ((token === import0.LOCALE_ID)) { return this._LOCALE_ID_10; }
@@ -2331,16 +2331,15 @@ export const AppModuleNgFactory:import0.NgModuleFactory<import1.AppModule> = new
23312331
it('should generate a default NgModule for a DeepLinked component', () => {
23322332
const knownFileContent = `
23332333
import { NgModule } from '@angular/core';
2334-
import { DeepLinkModule } from 'ionic-angular';
2334+
import { IonicPageModule } from 'ionic-angular';
23352335
import { PageOne } from './page-one';
23362336
2337-
23382337
@NgModule({
23392338
declarations: [
23402339
PageOne,
23412340
],
23422341
imports: [
2343-
DeepLinkModule.forChild(PageOne)
2342+
IonicPageModule.forChild(PageOne)
23442343
]
23452344
})
23462345
export class PageOneModule {}
@@ -2604,7 +2603,7 @@ class AppModuleInjector extends import0.ɵNgModuleInjector<import1.AppModule> {
26042603
_FormsModule_4:import4.FormsModule;
26052604
_ReactiveFormsModule_5:import4.ReactiveFormsModule;
26062605
_IonicModule_6:import5.IonicModule;
2607-
_DeepLinkModule_7:import5.DeepLinkModule;
2606+
_IonicPageModule_7:import5.IonicPageModule;
26082607
_HomePageModule_8:import6.HomePageModule;
26092608
_AppModule_9:import1.AppModule;
26102609
__LOCALE_ID_10:any;
@@ -2847,7 +2846,7 @@ class AppModuleInjector extends import0.ɵNgModuleInjector<import1.AppModule> {
28472846
this._FormsModule_4 = new import4.FormsModule();
28482847
this._ReactiveFormsModule_5 = new import4.ReactiveFormsModule();
28492848
this._IonicModule_6 = new import5.IonicModule();
2850-
this._DeepLinkModule_7 = new import5.DeepLinkModule();
2849+
this._IonicPageModule_7 = new import5.IonicPageModule();
28512850
this._HomePageModule_8 = new import6.HomePageModule();
28522851
this._AppModule_9 = new import1.AppModule();
28532852
this._ErrorHandler_12 = import3.ɵa();
@@ -2885,7 +2884,7 @@ class AppModuleInjector extends import0.ɵNgModuleInjector<import1.AppModule> {
28852884
if ((token === import4.FormsModule)) { return this._FormsModule_4; }
28862885
if ((token === import4.ReactiveFormsModule)) { return this._ReactiveFormsModule_5; }
28872886
if ((token === import5.IonicModule)) { return this._IonicModule_6; }
2888-
if ((token === import5.DeepLinkModule)) { return this._DeepLinkModule_7; }
2887+
if ((token === import5.IonicPageModule)) { return this._IonicPageModule_7; }
28892888
if ((token === import6.HomePageModule)) { return this._HomePageModule_8; }
28902889
if ((token === import1.AppModule)) { return this._AppModule_9; }
28912890
if ((token === import0.LOCALE_ID)) { return this._LOCALE_ID_10; }

src/upgrade-scripts/add-default-ngmodules.spec.ts

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,71 @@ describe('add default ngmodules upgrade script', () => {
100100

101101
const ngModuleFileExtension = '.module.ts';
102102

103+
const knownNgModulePageOne = `
104+
import { NgModule } from '@angular/core';
105+
import { IonicPageModule } from 'ionic-angular';
106+
import { PageOne } from './page-one';
107+
108+
@NgModule({
109+
declarations: [
110+
PageOne,
111+
],
112+
imports: [
113+
IonicPageModule.forChild(PageOne)
114+
]
115+
})
116+
export class PageOneModule {}
117+
118+
`;
119+
120+
const knownNgModulePageTwo = `
121+
import { NgModule } from '@angular/core';
122+
import { IonicPageModule } from 'ionic-angular';
123+
import { PageTwo } from './page-two';
124+
125+
@NgModule({
126+
declarations: [
127+
PageTwo,
128+
],
129+
imports: [
130+
IonicPageModule.forChild(PageTwo)
131+
]
132+
})
133+
export class PageTwoModule {}
134+
135+
`;
136+
137+
const knownNgModuleModalPage = `
138+
import { NgModule } from '@angular/core';
139+
import { IonicPageModule } from 'ionic-angular';
140+
import { ModalOne } from './modal-one';
141+
142+
@NgModule({
143+
declarations: [
144+
ModalOne,
145+
],
146+
imports: [
147+
IonicPageModule.forChild(ModalOne)
148+
]
149+
})
150+
export class ModalOneModule {}
151+
152+
`;
153+
103154
spyOn(helpers, helpers.getStringPropertyValue.name).and.returnValue(ngModuleFileExtension);
104155
const fsSpy = spyOn(fs, 'writeFileSync');
105156

106157
upgradeScript.generateAndWriteNgModules(context.fileCache);
107158

108159
expect(fsSpy.calls.count()).toEqual(3);
109160
expect(fsSpy.calls.argsFor(0)[0]).toEqual(helpers.changeExtension(knownFileOne, ngModuleFileExtension));
110-
expect(fsSpy.calls.argsFor(0)[1]).toEqual(deeplinkUtils.generateDefaultDeepLinkNgModuleContent(knownFileOne, 'PageOne'));
161+
expect(fsSpy.calls.argsFor(0)[1]).toEqual(knownNgModulePageOne);
111162

112163
expect(fsSpy.calls.argsFor(1)[0]).toEqual(helpers.changeExtension(knownFileTwo, ngModuleFileExtension));
113-
expect(fsSpy.calls.argsFor(1)[1]).toEqual(deeplinkUtils.generateDefaultDeepLinkNgModuleContent(knownFileTwo, 'PageTwo'));
164+
expect(fsSpy.calls.argsFor(1)[1]).toEqual(knownNgModulePageTwo);
114165

115166
expect(fsSpy.calls.argsFor(2)[0]).toEqual(helpers.changeExtension(knownFileSix, ngModuleFileExtension));
116-
expect(fsSpy.calls.argsFor(2)[1]).toEqual(deeplinkUtils.generateDefaultDeepLinkNgModuleContent(knownFileSix, 'ModalOne'));
167+
expect(fsSpy.calls.argsFor(2)[1]).toEqual(knownNgModuleModalPage);
117168
});
118169
});
119170
});

0 commit comments

Comments
 (0)