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

Commit

Permalink
test(deep-linking): update and add tests around IonicPageModule and c…
Browse files Browse the repository at this point in the history
…ompare to static, known NgModule content instead of generating it dynamically in the test
  • Loading branch information
danbucholtz committed Mar 27, 2017
1 parent 0df246a commit 6be05f9
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 40 deletions.
73 changes: 36 additions & 37 deletions src/deep-linking/util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ export function removeDecorators(fileName: string, source: string): string {
it('should return non-aot adjusted paths when not in AoT', () => {
const pageNgModuleContent = `
import { NgModule } from '@angular/core';
import { DeepLinkModule } from 'ionic-angular';
import { IonicPageModule } from 'ionic-angular';
import { HomePage } from './home';
Expand All @@ -589,7 +589,7 @@ import { HomePage } from './home';
HomePage,
],
imports: [
DeepLinkModule.forChild(HomePage),
IonicPageModule.forChild(HomePage),
]
})
export class HomePageModule {}
Expand All @@ -613,7 +613,7 @@ export class HomePageModule {}
it('should return adjusted paths to account for AoT', () => {
const pageNgModuleContent = `
import { NgModule } from '@angular/core';
import { DeepLinkModule } from 'ionic-angular';
import { IonicPageModule } from 'ionic-angular';
import { HomePage } from './home';
Expand All @@ -622,7 +622,7 @@ import { HomePage } from './home';
HomePage,
],
imports: [
DeepLinkModule.forChild(HomePage),
IonicPageModule.forChild(HomePage),
]
})
export class HomePageModule {}
Expand Down Expand Up @@ -676,14 +676,14 @@ export class PageOne {
const pageOneNgModuleContent = `
import { NgModule } from '@angular/core';
import { PageOne } from './page-one';
import { DeepLinkModule } from 'ionic-angular';
import { IonicPageModule } from 'ionic-angular';
@NgModule({
declarations: [
PageOne,
],
imports: [
DeepLinkModule.forChild(PageOne)
IonicPageModule.forChild(PageOne)
],
entryComponents: [
PageOne
Expand Down Expand Up @@ -739,14 +739,14 @@ export class PageTwo {
const pageTwoNgModuleContent = `
import { NgModule } from '@angular/core';
import { PageTwo } from './page-two';
import { DeepLinkModule } from 'ionic-angular';
import { IonicPageModule } from 'ionic-angular';
@NgModule({
declarations: [
PageTwo,
],
imports: [
DeepLinkModule.forChild(PageTwo)
IonicPageModule.forChild(PageTwo)
]
})
export class PageTwoModule {
Expand Down Expand Up @@ -786,14 +786,14 @@ export class PageThree {
const pageSettingsNgModuleContent = `
import { NgModule } from '@angular/core';
import { PageThree } from './page-three';
import { DeepLinkModule } from 'ionic-angular';
import { IonicPageModule } from 'ionic-angular';
@NgModule({
declarations: [
PageThree,
],
imports: [
DeepLinkModule.forChild(PageThree)
IonicPageModule.forChild(PageThree)
]
})
export class PageThreeModule {
Expand Down Expand Up @@ -863,14 +863,14 @@ export class PageOne {
const pageOneNgModuleContent = `
import { NgModule } from '@angular/core';
import { PageOne } from './page-one';
import { DeepLinkModule } from 'ionic-angular';
import { IonicPageModule } from 'ionic-angular';
@NgModule({
declarations: [
PageOne,
],
imports: [
DeepLinkModule.forChild(PageOne)
IonicPageModule.forChild(PageOne)
],
entryComponents: [
PageOne
Expand Down Expand Up @@ -926,14 +926,14 @@ export class PageTwo {
const pageTwoNgModuleContent = `
import { NgModule } from '@angular/core';
import { PageTwo } from './page-two';
import { DeepLinkModule } from 'ionic-angular';
import { IonicPageModule } from 'ionic-angular';
@NgModule({
declarations: [
PageTwo,
],
imports: [
DeepLinkModule.forChild(PageTwo)
IonicPageModule.forChild(PageTwo)
]
})
export class PageTwoModule {
Expand Down Expand Up @@ -972,14 +972,14 @@ export class PageThree {
const pageSettingsNgModuleContent = `
import { NgModule } from '@angular/core';
import { PageThree } from './page-three';
import { DeepLinkModule } from 'ionic-angular';
import { IonicPageModule } from 'ionic-angular';
@NgModule({
declarations: [
PageThree,
],
imports: [
DeepLinkModule.forChild(PageThree)
IonicPageModule.forChild(PageThree)
]
})
export class PageThreeModule {
Expand Down Expand Up @@ -1054,14 +1054,14 @@ export class PageOne {
const pageOneNgModuleContent = `
import { NgModule } from '@angular/core';
import { PageOne } from './page-one';
import { DeepLinkModule } from 'ionic-angular';
import { IonicPageModule } from 'ionic-angular';
@NgModule({
declarations: [
PageOne,
],
imports: [
DeepLinkModule.forChild(PageOne)
IonicPageModule.forChild(PageOne)
],
entryComponents: [
PageOne
Expand Down Expand Up @@ -1119,14 +1119,14 @@ export class PageTwo {
const pageTwoNgModuleContent = `
import { NgModule } from '@angular/core';
import { PageTwo } from './page-two';
import { DeepLinkModule } from 'ionic-angular';
import { IonicPageModule } from 'ionic-angular';
@NgModule({
declarations: [
PageTwo,
],
imports: [
DeepLinkModule.forChild(PageTwo)
IonicPageModule.forChild(PageTwo)
]
})
export class PageTwoModule {
Expand Down Expand Up @@ -1165,14 +1165,14 @@ export class PageThree {
const pageSettingsNgModuleContent = `
import { NgModule } from '@angular/core';
import { PageThree } from './page-three';
import { DeepLinkModule } from 'ionic-angular';
import { IonicPageModule } from 'ionic-angular';
@NgModule({
declarations: [
PageThree,
],
imports: [
DeepLinkModule.forChild(PageThree)
IonicPageModule.forChild(PageThree)
]
})
export class PageThreeModule {
Expand Down Expand Up @@ -1272,14 +1272,14 @@ export class PageOne {
const pageOneNgModuleContent = `
import { NgModule } from '@angular/core';
import { PageOne } from './page-one';
import { DeepLinkModule } from 'ionic-angular';
import { IonicPageModule } from 'ionic-angular';
@NgModule({
declarations: [
PageOne,
],
imports: [
DeepLinkModule.forChild(PageOne)
IonicPageModule.forChild(PageOne)
],
entryComponents: [
PageOne
Expand Down Expand Up @@ -1337,14 +1337,14 @@ export class PageTwo {
const pageTwoNgModuleContent = `
import { NgModule } from '@angular/core';
import { PageTwo } from './page-two';
import { DeepLinkModule } from 'ionic-angular';
import { IonicPageModule } from 'ionic-angular';
@NgModule({
declarations: [
PageTwo,
],
imports: [
DeepLinkModule.forChild(PageTwo)
IonicPageModule.forChild(PageTwo)
]
})
export class PageTwoModule {
Expand Down Expand Up @@ -1383,14 +1383,14 @@ export class PageThree {
const pageSettingsNgModuleContent = `
import { NgModule } from '@angular/core';
import { PageThree } from './page-three';
import { DeepLinkModule } from 'ionic-angular';
import { IonicPageModule } from 'ionic-angular';
@NgModule({
declarations: [
PageThree,
],
imports: [
DeepLinkModule.forChild(PageThree)
IonicPageModule.forChild(PageThree)
]
})
export class PageThreeModule {
Expand Down Expand Up @@ -1960,7 +1960,7 @@ class AppModuleInjector extends import0.ɵNgModuleInjector<import1.AppModule> {
_FormsModule_4:import4.FormsModule;
_ReactiveFormsModule_5:import4.ReactiveFormsModule;
_IonicModule_6:import5.IonicModule;
_DeepLinkModule_7:import5.DeepLinkModule;
_IonicPageModule_7:import5.IonicPageModule;
_HomePageModule_8:import6.HomePageModule;
_AppModule_9:import1.AppModule;
__LOCALE_ID_10:any;
Expand Down Expand Up @@ -2203,7 +2203,7 @@ class AppModuleInjector extends import0.ɵNgModuleInjector<import1.AppModule> {
this._FormsModule_4 = new import4.FormsModule();
this._ReactiveFormsModule_5 = new import4.ReactiveFormsModule();
this._IonicModule_6 = new import5.IonicModule();
this._DeepLinkModule_7 = new import5.DeepLinkModule();
this._IonicPageModule_7 = new import5.IonicPageModule();
this._HomePageModule_8 = new import6.HomePageModule();
this._AppModule_9 = new import1.AppModule();
this._ErrorHandler_12 = import3.ɵa();
Expand Down Expand Up @@ -2241,7 +2241,7 @@ class AppModuleInjector extends import0.ɵNgModuleInjector<import1.AppModule> {
if ((token === import4.FormsModule)) { return this._FormsModule_4; }
if ((token === import4.ReactiveFormsModule)) { return this._ReactiveFormsModule_5; }
if ((token === import5.IonicModule)) { return this._IonicModule_6; }
if ((token === import5.DeepLinkModule)) { return this._DeepLinkModule_7; }
if ((token === import5.IonicPageModule)) { return this._IonicPageModule_7; }
if ((token === import6.HomePageModule)) { return this._HomePageModule_8; }
if ((token === import1.AppModule)) { return this._AppModule_9; }
if ((token === import0.LOCALE_ID)) { return this._LOCALE_ID_10; }
Expand Down Expand Up @@ -2331,16 +2331,15 @@ export const AppModuleNgFactory:import0.NgModuleFactory<import1.AppModule> = new
it('should generate a default NgModule for a DeepLinked component', () => {
const knownFileContent = `
import { NgModule } from '@angular/core';
import { DeepLinkModule } from 'ionic-angular';
import { IonicPageModule } from 'ionic-angular';
import { PageOne } from './page-one';
@NgModule({
declarations: [
PageOne,
],
imports: [
DeepLinkModule.forChild(PageOne)
IonicPageModule.forChild(PageOne)
]
})
export class PageOneModule {}
Expand Down Expand Up @@ -2604,7 +2603,7 @@ class AppModuleInjector extends import0.ɵNgModuleInjector<import1.AppModule> {
_FormsModule_4:import4.FormsModule;
_ReactiveFormsModule_5:import4.ReactiveFormsModule;
_IonicModule_6:import5.IonicModule;
_DeepLinkModule_7:import5.DeepLinkModule;
_IonicPageModule_7:import5.IonicPageModule;
_HomePageModule_8:import6.HomePageModule;
_AppModule_9:import1.AppModule;
__LOCALE_ID_10:any;
Expand Down Expand Up @@ -2847,7 +2846,7 @@ class AppModuleInjector extends import0.ɵNgModuleInjector<import1.AppModule> {
this._FormsModule_4 = new import4.FormsModule();
this._ReactiveFormsModule_5 = new import4.ReactiveFormsModule();
this._IonicModule_6 = new import5.IonicModule();
this._DeepLinkModule_7 = new import5.DeepLinkModule();
this._IonicPageModule_7 = new import5.IonicPageModule();
this._HomePageModule_8 = new import6.HomePageModule();
this._AppModule_9 = new import1.AppModule();
this._ErrorHandler_12 = import3.ɵa();
Expand Down Expand Up @@ -2885,7 +2884,7 @@ class AppModuleInjector extends import0.ɵNgModuleInjector<import1.AppModule> {
if ((token === import4.FormsModule)) { return this._FormsModule_4; }
if ((token === import4.ReactiveFormsModule)) { return this._ReactiveFormsModule_5; }
if ((token === import5.IonicModule)) { return this._IonicModule_6; }
if ((token === import5.DeepLinkModule)) { return this._DeepLinkModule_7; }
if ((token === import5.IonicPageModule)) { return this._IonicPageModule_7; }
if ((token === import6.HomePageModule)) { return this._HomePageModule_8; }
if ((token === import1.AppModule)) { return this._AppModule_9; }
if ((token === import0.LOCALE_ID)) { return this._LOCALE_ID_10; }
Expand Down
57 changes: 54 additions & 3 deletions src/upgrade-scripts/add-default-ngmodules.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,71 @@ describe('add default ngmodules upgrade script', () => {

const ngModuleFileExtension = '.module.ts';

const knownNgModulePageOne = `
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { PageOne } from './page-one';
@NgModule({
declarations: [
PageOne,
],
imports: [
IonicPageModule.forChild(PageOne)
]
})
export class PageOneModule {}
`;

const knownNgModulePageTwo = `
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { PageTwo } from './page-two';
@NgModule({
declarations: [
PageTwo,
],
imports: [
IonicPageModule.forChild(PageTwo)
]
})
export class PageTwoModule {}
`;

const knownNgModuleModalPage = `
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { ModalOne } from './modal-one';
@NgModule({
declarations: [
ModalOne,
],
imports: [
IonicPageModule.forChild(ModalOne)
]
})
export class ModalOneModule {}
`;

spyOn(helpers, helpers.getStringPropertyValue.name).and.returnValue(ngModuleFileExtension);
const fsSpy = spyOn(fs, 'writeFileSync');

upgradeScript.generateAndWriteNgModules(context.fileCache);

expect(fsSpy.calls.count()).toEqual(3);
expect(fsSpy.calls.argsFor(0)[0]).toEqual(helpers.changeExtension(knownFileOne, ngModuleFileExtension));
expect(fsSpy.calls.argsFor(0)[1]).toEqual(deeplinkUtils.generateDefaultDeepLinkNgModuleContent(knownFileOne, 'PageOne'));
expect(fsSpy.calls.argsFor(0)[1]).toEqual(knownNgModulePageOne);

expect(fsSpy.calls.argsFor(1)[0]).toEqual(helpers.changeExtension(knownFileTwo, ngModuleFileExtension));
expect(fsSpy.calls.argsFor(1)[1]).toEqual(deeplinkUtils.generateDefaultDeepLinkNgModuleContent(knownFileTwo, 'PageTwo'));
expect(fsSpy.calls.argsFor(1)[1]).toEqual(knownNgModulePageTwo);

expect(fsSpy.calls.argsFor(2)[0]).toEqual(helpers.changeExtension(knownFileSix, ngModuleFileExtension));
expect(fsSpy.calls.argsFor(2)[1]).toEqual(deeplinkUtils.generateDefaultDeepLinkNgModuleContent(knownFileSix, 'ModalOne'));
expect(fsSpy.calls.argsFor(2)[1]).toEqual(knownNgModuleModalPage);
});
});
});
Expand Down

0 comments on commit 6be05f9

Please sign in to comment.