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

Commit

Permalink
fix(deep-linking): only attempt to inject deep-link config if there i…
Browse files Browse the repository at this point in the history
…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
danbucholtz committed Mar 26, 2017
1 parent 3b1fd16 commit 507f1a8
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
84 changes: 84 additions & 0 deletions src/deep-linking.spec.ts
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);
});
});
});
});
2 changes: 1 addition & 1 deletion src/deep-linking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function deepLinkingWorkerImpl(context: BuildContext, changedFiles: Chang
}
const deepLinkConfigEntries = getDeepLinkData(appNgModulePath, context.fileCache, context.runAot);
const hasExisting = hasExistingDeepLinkConfig(appNgModulePath, cachedUnmodifiedAppNgModuleFileContent);
if (!hasExisting) {
if (!hasExisting && deepLinkConfigEntries && deepLinkConfigEntries.length) {
// only update the app's main ngModule if there isn't an existing config
const deepLinkString = convertDeepLinkConfigEntriesToString(deepLinkConfigEntries);
updateAppNgModuleAndFactoryWithDeepLinkConfig(context, deepLinkString, changedFiles, context.runAot);
Expand Down

0 comments on commit 507f1a8

Please sign in to comment.