@@ -9,6 +9,11 @@ import * as helpers from './util/helpers';
9
9
10
10
describe ( 'Deep Linking task' , ( ) => {
11
11
describe ( 'deepLinkingWorkerImpl' , ( ) => {
12
+
13
+ beforeEach ( ( ) => {
14
+ deepLinking . reset ( ) ;
15
+ } ) ;
16
+
12
17
it ( 'should not update app ngmodule when it has an existing deeplink config' , ( ) => {
13
18
const appNgModulePath = join ( 'some' , 'fake' , 'path' , 'myApp' , 'src' , 'app' , 'app.module.ts' ) ;
14
19
const context = {
@@ -26,6 +31,7 @@ describe('Deep Linking task', () => {
26
31
const promise = deepLinking . deepLinkingWorkerImpl ( context , null ) ;
27
32
28
33
return promise . then ( ( ) => {
34
+ expect ( deepLinking . cachedUnmodifiedAppNgModuleFileContent ) . toEqual ( knownFileContent ) ;
29
35
expect ( deeplinkUtils . convertDeepLinkConfigEntriesToString ) . not . toHaveBeenCalled ( ) ;
30
36
expect ( deeplinkUtils . updateAppNgModuleAndFactoryWithDeepLinkConfig ) . not . toHaveBeenCalled ( ) ;
31
37
} ) ;
@@ -73,12 +79,118 @@ describe('Deep Linking task', () => {
73
79
const promise = deepLinking . deepLinkingWorkerImpl ( context , changedFiles ) ;
74
80
75
81
return promise . then ( ( ) => {
82
+ expect ( deepLinking . cachedDeepLinkString ) . toEqual ( knownDeepLinkString ) ;
76
83
expect ( helpers . getStringPropertyValue ) . toBeCalledWith ( Constants . ENV_APP_NG_MODULE_PATH ) ;
77
84
expect ( deeplinkUtils . getDeepLinkData ) . toHaveBeenCalledWith ( appNgModulePath , context . fileCache , context . runAot ) ;
78
85
expect ( deeplinkUtils . hasExistingDeepLinkConfig ) . toHaveBeenCalledWith ( appNgModulePath , knownFileContent ) ;
79
86
expect ( deeplinkUtils . convertDeepLinkConfigEntriesToString ) . toHaveBeenCalledWith ( knownMockDeepLinkArray ) ;
80
87
expect ( deeplinkUtils . updateAppNgModuleAndFactoryWithDeepLinkConfig ) . toHaveBeenCalledWith ( context , knownDeepLinkString , changedFiles , context . runAot ) ;
81
88
} ) ;
82
89
} ) ;
90
+
91
+ it ( 'should update deeplink config on subsequent updates when the deeplink string is different' , ( ) => {
92
+ const appNgModulePath = join ( 'some' , 'fake' , 'path' , 'myApp' , 'src' , 'app' , 'app.module.ts' ) ;
93
+ const context = {
94
+ fileCache : new FileCache ( ) ,
95
+ runAot : true
96
+ } ;
97
+ const knownFileContent = 'someFileContent' ;
98
+ const knownDeepLinkString = 'someDeepLinkString' ;
99
+ const knownDeepLinkString2 = 'someDeepLinkString2' ;
100
+ const knownMockDeepLinkArray = [ 1 ] ;
101
+ const changedFiles : ChangedFile [ ] = null ;
102
+ context . fileCache . set ( appNgModulePath , { path : appNgModulePath , content : knownFileContent } ) ;
103
+
104
+ spyOn ( helpers , helpers . getStringPropertyValue . name ) . and . returnValue ( appNgModulePath ) ;
105
+ spyOn ( deeplinkUtils , deeplinkUtils . getDeepLinkData . name ) . and . returnValue ( knownMockDeepLinkArray ) ;
106
+ spyOn ( deeplinkUtils , deeplinkUtils . hasExistingDeepLinkConfig . name ) . and . returnValue ( false ) ;
107
+
108
+ let hasConvertDeepLinkConfigToStringBeenCalled = false ;
109
+ spyOn ( deeplinkUtils , deeplinkUtils . convertDeepLinkConfigEntriesToString . name ) . and . callFake ( ( ) => {
110
+ if ( ! hasConvertDeepLinkConfigToStringBeenCalled ) {
111
+ hasConvertDeepLinkConfigToStringBeenCalled = true ;
112
+ return knownDeepLinkString ;
113
+ }
114
+ return knownDeepLinkString2 ;
115
+ } ) ;
116
+
117
+ const spy = spyOn ( deeplinkUtils , deeplinkUtils . updateAppNgModuleAndFactoryWithDeepLinkConfig . name ) ;
118
+
119
+ const promise = deepLinking . deepLinkingWorkerImpl ( context , changedFiles ) ;
120
+
121
+ return promise . then ( ( ) => {
122
+ expect ( deepLinking . cachedDeepLinkString ) . toEqual ( knownDeepLinkString ) ;
123
+ expect ( helpers . getStringPropertyValue ) . toBeCalledWith ( Constants . ENV_APP_NG_MODULE_PATH ) ;
124
+ expect ( deeplinkUtils . getDeepLinkData ) . toHaveBeenCalledWith ( appNgModulePath , context . fileCache , context . runAot ) ;
125
+ expect ( deeplinkUtils . hasExistingDeepLinkConfig ) . toHaveBeenCalledWith ( appNgModulePath , knownFileContent ) ;
126
+ expect ( deeplinkUtils . convertDeepLinkConfigEntriesToString ) . toHaveBeenCalledWith ( knownMockDeepLinkArray ) ;
127
+ expect ( spy . calls . first ( ) . args [ 0 ] ) . toEqual ( context ) ;
128
+ expect ( spy . calls . first ( ) . args [ 1 ] ) . toEqual ( knownDeepLinkString ) ;
129
+ expect ( spy . calls . first ( ) . args [ 2 ] ) . toEqual ( changedFiles ) ;
130
+ expect ( spy . calls . first ( ) . args [ 3 ] ) . toEqual ( context . runAot ) ;
131
+
132
+ return deepLinking . deepLinkingWorkerImpl ( context , changedFiles ) ;
133
+ } ) . then ( ( result ) => {
134
+ expect ( deepLinking . cachedDeepLinkString ) . toEqual ( knownDeepLinkString2 ) ;
135
+ expect ( deeplinkUtils . getDeepLinkData ) . toHaveBeenCalledTimes ( 2 ) ;
136
+ expect ( deeplinkUtils . getDeepLinkData ) . toHaveBeenCalledWith ( appNgModulePath , context . fileCache , context . runAot ) ;
137
+ expect ( deeplinkUtils . hasExistingDeepLinkConfig ) . toHaveBeenCalledTimes ( 2 ) ;
138
+ expect ( deeplinkUtils . hasExistingDeepLinkConfig ) . toHaveBeenCalledWith ( appNgModulePath , knownFileContent ) ;
139
+ expect ( deeplinkUtils . convertDeepLinkConfigEntriesToString ) . toHaveBeenCalledWith ( knownMockDeepLinkArray ) ;
140
+ expect ( deeplinkUtils . convertDeepLinkConfigEntriesToString ) . toHaveBeenCalledTimes ( 2 ) ;
141
+ expect ( spy ) . toHaveBeenCalledTimes ( 2 ) ;
142
+ expect ( spy . calls . mostRecent ( ) . args [ 0 ] ) . toEqual ( context ) ;
143
+ expect ( spy . calls . mostRecent ( ) . args [ 1 ] ) . toEqual ( knownDeepLinkString2 ) ;
144
+ expect ( spy . calls . mostRecent ( ) . args [ 2 ] ) . toEqual ( changedFiles ) ;
145
+ expect ( spy . calls . mostRecent ( ) . args [ 3 ] ) . toEqual ( context . runAot ) ;
146
+ } ) ;
147
+ } ) ;
148
+
149
+ it ( 'should not update deeplink config on subsequent updates when the deeplink string is the same' , ( ) => {
150
+ const appNgModulePath = join ( 'some' , 'fake' , 'path' , 'myApp' , 'src' , 'app' , 'app.module.ts' ) ;
151
+ const context = {
152
+ fileCache : new FileCache ( ) ,
153
+ runAot : true
154
+ } ;
155
+ const knownFileContent = 'someFileContent' ;
156
+ const knownDeepLinkString = 'someDeepLinkString' ;
157
+ const knownMockDeepLinkArray = [ 1 ] ;
158
+ const changedFiles : ChangedFile [ ] = null ;
159
+ context . fileCache . set ( appNgModulePath , { path : appNgModulePath , content : knownFileContent } ) ;
160
+
161
+ spyOn ( helpers , helpers . getStringPropertyValue . name ) . and . returnValue ( appNgModulePath ) ;
162
+ spyOn ( deeplinkUtils , deeplinkUtils . getDeepLinkData . name ) . and . returnValue ( knownMockDeepLinkArray ) ;
163
+ spyOn ( deeplinkUtils , deeplinkUtils . hasExistingDeepLinkConfig . name ) . and . returnValue ( false ) ;
164
+
165
+ spyOn ( deeplinkUtils , deeplinkUtils . convertDeepLinkConfigEntriesToString . name ) . and . returnValue ( knownDeepLinkString ) ;
166
+
167
+ const spy = spyOn ( deeplinkUtils , deeplinkUtils . updateAppNgModuleAndFactoryWithDeepLinkConfig . name ) ;
168
+
169
+ const promise = deepLinking . deepLinkingWorkerImpl ( context , changedFiles ) ;
170
+
171
+ return promise . then ( ( ) => {
172
+ expect ( deepLinking . cachedDeepLinkString ) . toEqual ( knownDeepLinkString ) ;
173
+ expect ( helpers . getStringPropertyValue ) . toBeCalledWith ( Constants . ENV_APP_NG_MODULE_PATH ) ;
174
+ expect ( deeplinkUtils . getDeepLinkData ) . toHaveBeenCalledWith ( appNgModulePath , context . fileCache , context . runAot ) ;
175
+ expect ( deeplinkUtils . hasExistingDeepLinkConfig ) . toHaveBeenCalledWith ( appNgModulePath , knownFileContent ) ;
176
+ expect ( deeplinkUtils . convertDeepLinkConfigEntriesToString ) . toHaveBeenCalledWith ( knownMockDeepLinkArray ) ;
177
+ expect ( spy . calls . first ( ) . args [ 0 ] ) . toEqual ( context ) ;
178
+ expect ( spy . calls . first ( ) . args [ 1 ] ) . toEqual ( knownDeepLinkString ) ;
179
+ expect ( spy . calls . first ( ) . args [ 2 ] ) . toEqual ( changedFiles ) ;
180
+ expect ( spy . calls . first ( ) . args [ 3 ] ) . toEqual ( context . runAot ) ;
181
+
182
+ return deepLinking . deepLinkingWorkerImpl ( context , changedFiles ) ;
183
+ } ) . then ( ( result ) => {
184
+ expect ( result ) . toEqual ( knownMockDeepLinkArray ) ;
185
+ expect ( deepLinking . cachedDeepLinkString ) . toEqual ( knownDeepLinkString ) ;
186
+ expect ( deeplinkUtils . getDeepLinkData ) . toHaveBeenCalledTimes ( 2 ) ;
187
+ expect ( deeplinkUtils . getDeepLinkData ) . toHaveBeenCalledWith ( appNgModulePath , context . fileCache , context . runAot ) ;
188
+ expect ( deeplinkUtils . hasExistingDeepLinkConfig ) . toHaveBeenCalledTimes ( 2 ) ;
189
+ expect ( deeplinkUtils . hasExistingDeepLinkConfig ) . toHaveBeenCalledWith ( appNgModulePath , knownFileContent ) ;
190
+ expect ( deeplinkUtils . convertDeepLinkConfigEntriesToString ) . toHaveBeenCalledWith ( knownMockDeepLinkArray ) ;
191
+ expect ( deeplinkUtils . convertDeepLinkConfigEntriesToString ) . toHaveBeenCalledTimes ( 2 ) ;
192
+ expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
193
+ } ) ;
194
+ } ) ;
83
195
} ) ;
84
196
} ) ;
0 commit comments