refactor($ionicLoading): make sure .hide() always happens after .show()

Fixes #1085.  Thanks @graemefoster.
This commit is contained in:
Andy Joslin
2014-04-09 06:41:43 -06:00
parent d0b47d879f
commit c7d7dab75f
2 changed files with 20 additions and 2 deletions

View File

@@ -45,6 +45,8 @@ angular.module('ionic.service.loading', [])
function($animate, $document, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q, $log) {
var loaderInstance;
//default value
var loadingShowDelay = $q.when();
return {
/**
@@ -135,7 +137,7 @@ function($animate, $document, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q
deprecated.field(SHOW_DELAY_LOADING_DEPRECATED, $log.warn, options, 'showDelay', options.showDelay);
deprecated.field(SHOW_BACKDROP_LOADING_DEPRECATED, $log.warn, options, 'showBackdrop', options.showBackdrop);
$timeout(getLoader, options.delay || options.showDelay || 0)
loadingShowDelay = $timeout(getLoader, options.delay || options.showDelay || 0)
.then(function(loader) {
return loader.show(options);
});
@@ -154,7 +156,7 @@ function($animate, $document, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q
}
function hideLoader() {
getLoader().then(function(loader) {
loadingShowDelay.then(getLoader).then(function(loader) {
loader.hide();
});
}

View File

@@ -103,5 +103,21 @@ describe('$ionicLoading service', function() {
expect(loader.hide).toHaveBeenCalled();
}));
it('hide should happen after show', inject(function($ionicLoading, $timeout) {
ionic.requestAnimationFrame = function(cb) { cb(); };
var loader = TestUtil.unwrapPromise($ionicLoading._getLoader());
spyOn(loader, 'hide').andCallThrough();
spyOn(loader, 'show').andCallThrough();
$ionicLoading.show({ delay: 1000 });
$ionicLoading.hide();
expect(loader.show).not.toHaveBeenCalled();
expect(loader.hide).not.toHaveBeenCalled();
$timeout.flush();
expect(loader.show).toHaveBeenCalled();
expect(loader.hide).toHaveBeenCalled();
expect(loader.isShown).toBe(false);
expect(loader.element.hasClass('ng-hide')).toBe(true);
}));
});
});