|
| 1 | +import { join } from 'path'; |
| 2 | + |
| 3 | +import * as deepLinking from './deep-linking'; |
| 4 | +import * as deeplinkUtils from './deep-linking/util'; |
| 5 | +import * as Constants from './util/constants'; |
| 6 | +import { ChangedFile } from './util/interfaces'; |
| 7 | +import { FileCache } from './util/file-cache'; |
| 8 | +import * as helpers from './util/helpers'; |
| 9 | + |
| 10 | +describe('Deep Linking task', () => { |
| 11 | + describe('deepLinkingWorkerImpl', () => { |
| 12 | + it('should not update app ngmodule when it has an existing deeplink config', () => { |
| 13 | + const appNgModulePath = join('some', 'fake', 'path', 'myApp', 'src', 'app', 'app.module.ts'); |
| 14 | + const context = { |
| 15 | + fileCache: new FileCache() |
| 16 | + }; |
| 17 | + const knownFileContent = 'someFileContent'; |
| 18 | + const knownDeepLinkString = 'someDeepLinkString'; |
| 19 | + context.fileCache.set(appNgModulePath, { path: appNgModulePath, content: knownFileContent}); |
| 20 | + spyOn(helpers, helpers.getStringPropertyValue.name).and.returnValue(appNgModulePath); |
| 21 | + spyOn(deeplinkUtils, deeplinkUtils.getDeepLinkData.name).and.returnValue([1]); |
| 22 | + spyOn(deeplinkUtils, deeplinkUtils.hasExistingDeepLinkConfig.name).and.returnValue(true); |
| 23 | + spyOn(deeplinkUtils, deeplinkUtils.convertDeepLinkConfigEntriesToString.name).and.returnValue(knownDeepLinkString); |
| 24 | + spyOn(deeplinkUtils, deeplinkUtils.updateAppNgModuleAndFactoryWithDeepLinkConfig.name); |
| 25 | + |
| 26 | + const promise = deepLinking.deepLinkingWorkerImpl(context, null); |
| 27 | + |
| 28 | + return promise.then(() => { |
| 29 | + expect(deeplinkUtils.convertDeepLinkConfigEntriesToString).not.toHaveBeenCalled(); |
| 30 | + expect(deeplinkUtils.updateAppNgModuleAndFactoryWithDeepLinkConfig).not.toHaveBeenCalled(); |
| 31 | + }); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should not update app ngmodule when no deeplinks were found', () => { |
| 35 | + const appNgModulePath = join('some', 'fake', 'path', 'myApp', 'src', 'app', 'app.module.ts'); |
| 36 | + const context = { |
| 37 | + fileCache: new FileCache() |
| 38 | + }; |
| 39 | + const knownFileContent = 'someFileContent'; |
| 40 | + const knownDeepLinkString = 'someDeepLinkString'; |
| 41 | + context.fileCache.set(appNgModulePath, { path: appNgModulePath, content: knownFileContent}); |
| 42 | + spyOn(helpers, helpers.getStringPropertyValue.name).and.returnValue(appNgModulePath); |
| 43 | + spyOn(deeplinkUtils, deeplinkUtils.getDeepLinkData.name).and.returnValue([]); |
| 44 | + spyOn(deeplinkUtils, deeplinkUtils.hasExistingDeepLinkConfig.name).and.returnValue(false); |
| 45 | + spyOn(deeplinkUtils, deeplinkUtils.convertDeepLinkConfigEntriesToString.name).and.returnValue(knownDeepLinkString); |
| 46 | + spyOn(deeplinkUtils, deeplinkUtils.updateAppNgModuleAndFactoryWithDeepLinkConfig.name); |
| 47 | + |
| 48 | + const promise = deepLinking.deepLinkingWorkerImpl(context, null); |
| 49 | + |
| 50 | + return promise.then(() => { |
| 51 | + expect(deeplinkUtils.convertDeepLinkConfigEntriesToString).not.toHaveBeenCalled(); |
| 52 | + expect(deeplinkUtils.updateAppNgModuleAndFactoryWithDeepLinkConfig).not.toHaveBeenCalled(); |
| 53 | + }); |
| 54 | + }); |
| 55 | + |
| 56 | + it('should update deeplink config', () => { |
| 57 | + const appNgModulePath = join('some', 'fake', 'path', 'myApp', 'src', 'app', 'app.module.ts'); |
| 58 | + const context = { |
| 59 | + fileCache: new FileCache(), |
| 60 | + runAot: true |
| 61 | + }; |
| 62 | + const knownFileContent = 'someFileContent'; |
| 63 | + const knownDeepLinkString = 'someDeepLinkString'; |
| 64 | + const knownMockDeepLinkArray = [1]; |
| 65 | + const changedFiles: ChangedFile[] = []; |
| 66 | + context.fileCache.set(appNgModulePath, { path: appNgModulePath, content: knownFileContent}); |
| 67 | + spyOn(helpers, helpers.getStringPropertyValue.name).and.returnValue(appNgModulePath); |
| 68 | + spyOn(deeplinkUtils, deeplinkUtils.getDeepLinkData.name).and.returnValue(knownMockDeepLinkArray); |
| 69 | + spyOn(deeplinkUtils, deeplinkUtils.hasExistingDeepLinkConfig.name).and.returnValue(false); |
| 70 | + spyOn(deeplinkUtils, deeplinkUtils.convertDeepLinkConfigEntriesToString.name).and.returnValue(knownDeepLinkString); |
| 71 | + spyOn(deeplinkUtils, deeplinkUtils.updateAppNgModuleAndFactoryWithDeepLinkConfig.name); |
| 72 | + |
| 73 | + const promise = deepLinking.deepLinkingWorkerImpl(context, changedFiles); |
| 74 | + |
| 75 | + return promise.then(() => { |
| 76 | + expect(helpers.getStringPropertyValue).toBeCalledWith(Constants.ENV_APP_NG_MODULE_PATH); |
| 77 | + expect(deeplinkUtils.getDeepLinkData).toHaveBeenCalledWith(appNgModulePath, context.fileCache, context.runAot); |
| 78 | + expect(deeplinkUtils.hasExistingDeepLinkConfig).toHaveBeenCalledWith(appNgModulePath, knownFileContent); |
| 79 | + expect(deeplinkUtils.convertDeepLinkConfigEntriesToString).toHaveBeenCalledWith(knownMockDeepLinkArray); |
| 80 | + expect(deeplinkUtils.updateAppNgModuleAndFactoryWithDeepLinkConfig).toHaveBeenCalledWith(context, knownDeepLinkString, changedFiles, context.runAot); |
| 81 | + }); |
| 82 | + }); |
| 83 | + }); |
| 84 | +}); |
0 commit comments