Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/openlmis-app-cache/openlmis-app-cache.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@
* Initialization method of the OpenlmisAppCacheController.
*/
function onInit() {
appCache.addEventListener('updateready', setUpdateReady);
if (appCache) {
appCache.addEventListener('updateready', setUpdateReady);
}
vm.buildDate = OPENLMIS_BUILD_DATE;
setUpdateReady();
}
Expand Down Expand Up @@ -97,7 +99,7 @@
}

function setUpdateReady() {
vm.updateReady = appCache.status === appCache.UPDATEREADY;
vm.updateReady = !!appCache && appCache.status === appCache.UPDATEREADY;
}

}
Expand Down
44 changes: 44 additions & 0 deletions src/openlmis-app-cache/openlmis-app-cache.controller.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('OpenlmisAppCacheController', function() {
this.$rootScope = $injector.get('$rootScope');
this.$controller = $injector.get('$controller');
this.$q = $injector.get('$q');
this.OPENLMIS_BUILD_DATE = $injector.get('OPENLMIS_BUILD_DATE');
});

this.applicationCacheMock = jasmine.createSpyObj('applicationCache', [
Expand Down Expand Up @@ -146,4 +147,47 @@ describe('OpenlmisAppCacheController', function() {

});

// The deprecated window.applicationCache has been removed from modern browsers,
// so $window.applicationCache can be undefined. The controller must not crash.
describe('when applicationCache is not available', function() {

beforeEach(function() {
this.vm = this.$controller('OpenlmisAppCacheController', {
$window: {
applicationCache: undefined,
location: this.locationMock
}
});
});

it('should not throw on init', function() {
var vm = this.vm;

expect(function() {
vm.$onInit();
}).not.toThrow();
});

it('should still set the build date', function() {
this.vm.$onInit();

expect(this.vm.buildDate).toBe(this.OPENLMIS_BUILD_DATE);
});

it('should set updateReady flag to false', function() {
this.vm.$onInit();

expect(this.vm.updateReady).toBe(false);
});

it('should do nothing when updateCache is called', function() {
this.vm.$onInit();

this.vm.updateCache();

expect(this.confirmService.confirm).not.toHaveBeenCalled();
});

});

});
Loading