2015-11-23 22:00:21 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-08-19 22:29:01 +00:00
|
|
|
angular.module('stateMock',[]);
|
2015-11-23 21:06:02 +00:00
|
|
|
angular.module('stateMock').service('$state', function($q){
|
2015-08-19 22:29:01 +00:00
|
|
|
this.expectedTransitions = [];
|
|
|
|
this.transitionTo = function(stateName){
|
|
|
|
if(this.expectedTransitions.length > 0){
|
|
|
|
var expectedState = this.expectedTransitions.shift();
|
|
|
|
if(expectedState !== stateName){
|
2015-11-23 21:06:02 +00:00
|
|
|
throw Error('Expected transition to state: ' + expectedState + ' but transitioned to ' + stateName );
|
2015-08-19 22:29:01 +00:00
|
|
|
}
|
|
|
|
}else{
|
2015-11-23 21:06:02 +00:00
|
|
|
throw Error('No more transitions were expected! Tried to transition to '+ stateName );
|
2015-08-19 22:29:01 +00:00
|
|
|
}
|
|
|
|
var deferred = $q.defer();
|
|
|
|
var promise = deferred.promise;
|
|
|
|
deferred.resolve();
|
|
|
|
return promise;
|
2015-11-23 21:06:02 +00:00
|
|
|
};
|
|
|
|
|
2015-08-19 22:29:01 +00:00
|
|
|
this.go = this.transitionTo;
|
|
|
|
this.expectTransitionTo = function(stateName){
|
|
|
|
this.expectedTransitions.push(stateName);
|
2015-11-23 21:06:02 +00:00
|
|
|
};
|
2015-08-19 22:29:01 +00:00
|
|
|
|
|
|
|
this.ensureAllTransitionsHappened = function(){
|
|
|
|
if(this.expectedTransitions.length > 0){
|
2015-11-23 21:06:02 +00:00
|
|
|
throw Error('Not all transitions happened!');
|
2015-08-19 22:29:01 +00:00
|
|
|
}
|
2015-11-23 21:06:02 +00:00
|
|
|
};
|
2015-08-19 22:29:01 +00:00
|
|
|
});
|