Skip to content

Commit

Permalink
if we cancel don't call the callback
Browse files Browse the repository at this point in the history
  • Loading branch information
fredkingham committed Feb 17, 2017
1 parent 26ffcc4 commit e594704
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
19 changes: 13 additions & 6 deletions pathway/static/js/pathway/controllers/modal_pathway_maker.js
Expand Up @@ -15,15 +15,22 @@ angular.module('opal.controllers').controller('ModalPathwayMaker', function(
var result = new pathwayService(pathwayDefinition, episode).open();

result.then(function(response){
var resolved = pathwayCallback(response);
if(resolved && resolved.then){
resolved.then(function(callBackResult){
$modalInstance.close(callBackResult);
});
// if there is a response then this was saved, otherwise it was cancelled
if(response){
var resolved = pathwayCallback(response);
if(resolved && resolved.then){
resolved.then(function(callBackResult){
$modalInstance.close(callBackResult);
});
}
else{
$modalInstance.close(resolved);
}
}
else{
$modalInstance.close(resolved);
$modalInstance.close();
}

}, function(error){
$window.alert("unable to save patient");
});
Expand Down
Expand Up @@ -37,6 +37,34 @@ describe("ModalPathwayMaker", function(){
});
});

it("should not call the callback if there is no response", function(){
var mockPathwayService = function(pathwaySlug, episode, isModal){
this.open = function(){
return {
then: function(fn){
fn();
}
};
};
};

mockInjector = {
get: function(something){ return mockPathwayService; }
};

$controller("ModalPathwayMaker", {
$scope: $scope,
$modalInstance: $modalInstance,
$injector: mockInjector,
pathwaySlug: pathwaySlug,
pathwayLoader: pathwayLoader,
episode: episode,
pathwayCallback: callBack
});
expect(callBack).not.toHaveBeenCalled();
expect($modalInstance.close).toHaveBeenCalledWith();
});

it("should flow through on success", function(){
var mockPathwayService = function(pathwaySlug, episode, isModal){
this.open = function(){
Expand Down

0 comments on commit e594704

Please sign in to comment.