fix(viewService): No error on clearHistory for empty history

This commit is contained in:
Max Lynch
2014-08-04 14:17:54 -05:00
parent 5b99fd6891
commit 64641b1be0
2 changed files with 22 additions and 14 deletions

View File

@@ -550,21 +550,23 @@ function($rootScope, $state, $location, $window, $injector, $animate, $ionicNavV
histories = $rootScope.$viewHistory.histories,
currentView = $rootScope.$viewHistory.currentView;
for(var historyId in histories) {
if(histories) {
for(var historyId in histories) {
if(histories[historyId].stack) {
histories[historyId].stack = [];
histories[historyId].cursor = -1;
}
if(currentView && currentView.historyId === historyId) {
currentView.backViewId = null;
currentView.forwardViewId = null;
histories[historyId].stack.push(currentView);
} else if(histories[historyId].destroy) {
histories[historyId].destroy();
}
if(histories[historyId].stack) {
histories[historyId].stack = [];
histories[historyId].cursor = -1;
}
if(currentView.historyId === historyId) {
currentView.backViewId = null;
currentView.forwardViewId = null;
histories[historyId].stack.push(currentView);
} else if(histories[historyId].destroy) {
histories[historyId].destroy();
}
}
for(var viewId in $rootScope.$viewHistory.views) {
@@ -573,7 +575,9 @@ function($rootScope, $state, $location, $window, $injector, $animate, $ionicNavV
}
}
this.setNavViews(currentView.viewId);
if(currentView) {
this.setNavViews(currentView.viewId);
}
}
};

View File

@@ -697,6 +697,10 @@ describe('Ionic View Service', function() {
});
}));
it('should not error when clearing empty history', function() {
expect(viewService.clearHistory.bind(null)).not.toThrow();
});
it('should create a viewService view', inject(function($location) {
var newView = viewService.createView();
expect(newView).toEqual(null);