@@ -24,6 +24,7 @@ describe('OpenlmisAppCacheController', function() {
2424 this . $rootScope = $injector . get ( '$rootScope' ) ;
2525 this . $controller = $injector . get ( '$controller' ) ;
2626 this . $q = $injector . get ( '$q' ) ;
27+ this . OPENLMIS_BUILD_DATE = $injector . get ( 'OPENLMIS_BUILD_DATE' ) ;
2728 } ) ;
2829
2930 this . applicationCacheMock = jasmine . createSpyObj ( 'applicationCache' , [
@@ -146,4 +147,47 @@ describe('OpenlmisAppCacheController', function() {
146147
147148 } ) ;
148149
150+ // The deprecated window.applicationCache has been removed from modern browsers,
151+ // so $window.applicationCache can be undefined. The controller must not crash.
152+ describe ( 'when applicationCache is not available' , function ( ) {
153+
154+ beforeEach ( function ( ) {
155+ this . vm = this . $controller ( 'OpenlmisAppCacheController' , {
156+ $window : {
157+ applicationCache : undefined ,
158+ location : this . locationMock
159+ }
160+ } ) ;
161+ } ) ;
162+
163+ it ( 'should not throw on init' , function ( ) {
164+ var vm = this . vm ;
165+
166+ expect ( function ( ) {
167+ vm . $onInit ( ) ;
168+ } ) . not . toThrow ( ) ;
169+ } ) ;
170+
171+ it ( 'should still set the build date' , function ( ) {
172+ this . vm . $onInit ( ) ;
173+
174+ expect ( this . vm . buildDate ) . toBe ( this . OPENLMIS_BUILD_DATE ) ;
175+ } ) ;
176+
177+ it ( 'should set updateReady flag to false' , function ( ) {
178+ this . vm . $onInit ( ) ;
179+
180+ expect ( this . vm . updateReady ) . toBe ( false ) ;
181+ } ) ;
182+
183+ it ( 'should do nothing when updateCache is called' , function ( ) {
184+ this . vm . $onInit ( ) ;
185+
186+ this . vm . updateCache ( ) ;
187+
188+ expect ( this . confirmService . confirm ) . not . toHaveBeenCalled ( ) ;
189+ } ) ;
190+
191+ } ) ;
192+
149193} ) ;
0 commit comments