This repository was archived by the owner on May 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(deep-linking): only attempt to inject deep-link config if there i…
…sn't an existing config and the only attempt to inject deep-link config if there isn't an existing config and there is one or more valid IonicPage decorators
- Loading branch information
1 parent
3b1fd16
commit 507f1a8
Showing
2 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { join } from 'path'; | ||
|
||
import * as deepLinking from './deep-linking'; | ||
import * as deeplinkUtils from './deep-linking/util'; | ||
import * as Constants from './util/constants'; | ||
import { ChangedFile } from './util/interfaces'; | ||
import { FileCache } from './util/file-cache'; | ||
import * as helpers from './util/helpers'; | ||
|
||
describe('Deep Linking task', () => { | ||
describe('deepLinkingWorkerImpl', () => { | ||
it('should not update app ngmodule when it has an existing deeplink config', () => { | ||
const appNgModulePath = join('some', 'fake', 'path', 'myApp', 'src', 'app', 'app.module.ts'); | ||
const context = { | ||
fileCache: new FileCache() | ||
}; | ||
const knownFileContent = 'someFileContent'; | ||
const knownDeepLinkString = 'someDeepLinkString'; | ||
context.fileCache.set(appNgModulePath, { path: appNgModulePath, content: knownFileContent}); | ||
spyOn(helpers, helpers.getStringPropertyValue.name).and.returnValue(appNgModulePath); | ||
spyOn(deeplinkUtils, deeplinkUtils.getDeepLinkData.name).and.returnValue([1]); | ||
spyOn(deeplinkUtils, deeplinkUtils.hasExistingDeepLinkConfig.name).and.returnValue(true); | ||
spyOn(deeplinkUtils, deeplinkUtils.convertDeepLinkConfigEntriesToString.name).and.returnValue(knownDeepLinkString); | ||
spyOn(deeplinkUtils, deeplinkUtils.updateAppNgModuleAndFactoryWithDeepLinkConfig.name); | ||
|
||
const promise = deepLinking.deepLinkingWorkerImpl(context, null); | ||
|
||
return promise.then(() => { | ||
expect(deeplinkUtils.convertDeepLinkConfigEntriesToString).not.toHaveBeenCalled(); | ||
expect(deeplinkUtils.updateAppNgModuleAndFactoryWithDeepLinkConfig).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
it('should not update app ngmodule when no deeplinks were found', () => { | ||
const appNgModulePath = join('some', 'fake', 'path', 'myApp', 'src', 'app', 'app.module.ts'); | ||
const context = { | ||
fileCache: new FileCache() | ||
}; | ||
const knownFileContent = 'someFileContent'; | ||
const knownDeepLinkString = 'someDeepLinkString'; | ||
context.fileCache.set(appNgModulePath, { path: appNgModulePath, content: knownFileContent}); | ||
spyOn(helpers, helpers.getStringPropertyValue.name).and.returnValue(appNgModulePath); | ||
spyOn(deeplinkUtils, deeplinkUtils.getDeepLinkData.name).and.returnValue([]); | ||
spyOn(deeplinkUtils, deeplinkUtils.hasExistingDeepLinkConfig.name).and.returnValue(false); | ||
spyOn(deeplinkUtils, deeplinkUtils.convertDeepLinkConfigEntriesToString.name).and.returnValue(knownDeepLinkString); | ||
spyOn(deeplinkUtils, deeplinkUtils.updateAppNgModuleAndFactoryWithDeepLinkConfig.name); | ||
|
||
const promise = deepLinking.deepLinkingWorkerImpl(context, null); | ||
|
||
return promise.then(() => { | ||
expect(deeplinkUtils.convertDeepLinkConfigEntriesToString).not.toHaveBeenCalled(); | ||
expect(deeplinkUtils.updateAppNgModuleAndFactoryWithDeepLinkConfig).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
it('should update deeplink config', () => { | ||
const appNgModulePath = join('some', 'fake', 'path', 'myApp', 'src', 'app', 'app.module.ts'); | ||
const context = { | ||
fileCache: new FileCache(), | ||
runAot: true | ||
}; | ||
const knownFileContent = 'someFileContent'; | ||
const knownDeepLinkString = 'someDeepLinkString'; | ||
const knownMockDeepLinkArray = [1]; | ||
const changedFiles: ChangedFile[] = []; | ||
context.fileCache.set(appNgModulePath, { path: appNgModulePath, content: knownFileContent}); | ||
spyOn(helpers, helpers.getStringPropertyValue.name).and.returnValue(appNgModulePath); | ||
spyOn(deeplinkUtils, deeplinkUtils.getDeepLinkData.name).and.returnValue(knownMockDeepLinkArray); | ||
spyOn(deeplinkUtils, deeplinkUtils.hasExistingDeepLinkConfig.name).and.returnValue(false); | ||
spyOn(deeplinkUtils, deeplinkUtils.convertDeepLinkConfigEntriesToString.name).and.returnValue(knownDeepLinkString); | ||
spyOn(deeplinkUtils, deeplinkUtils.updateAppNgModuleAndFactoryWithDeepLinkConfig.name); | ||
|
||
const promise = deepLinking.deepLinkingWorkerImpl(context, changedFiles); | ||
|
||
return promise.then(() => { | ||
expect(helpers.getStringPropertyValue).toBeCalledWith(Constants.ENV_APP_NG_MODULE_PATH); | ||
expect(deeplinkUtils.getDeepLinkData).toHaveBeenCalledWith(appNgModulePath, context.fileCache, context.runAot); | ||
expect(deeplinkUtils.hasExistingDeepLinkConfig).toHaveBeenCalledWith(appNgModulePath, knownFileContent); | ||
expect(deeplinkUtils.convertDeepLinkConfigEntriesToString).toHaveBeenCalledWith(knownMockDeepLinkArray); | ||
expect(deeplinkUtils.updateAppNgModuleAndFactoryWithDeepLinkConfig).toHaveBeenCalledWith(context, knownDeepLinkString, changedFiles, context.runAot); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters