Pass result of submit to wizard modal close

This passes the result of the submit function on to the modal close
function that gets called when the wizard modal is closed. This
allows the response to be handled following the wizard close.

Closes-Bug: #1521692
Change-Id: I259b7ff3133169a721b0923d9f790a08d9b692c8
This commit is contained in:
Justin Pomeroy 2015-12-01 10:47:40 -06:00
parent d40391714a
commit 0a00d6a79c
3 changed files with 25 additions and 4 deletions

View File

@ -34,8 +34,8 @@
// wizard and modal-container controller
/*eslint-disable angular/ng_controller_as */
$scope.launchContext = launchContext;
$scope.close = function() {
$modalInstance.close();
$scope.close = function(args) {
$modalInstance.close(args);
};
$scope.cancel = function() {
$modalInstance.dismiss();

View File

@ -93,10 +93,10 @@
$scope.$broadcast(wizardEvents.BEFORE_SUBMIT);
}
function afterSubmit() {
function afterSubmit(args) {
$scope.$broadcast(wizardEvents.AFTER_SUBMIT);
/*eslint-disable angular/ng_controller_as */
$scope.close();
$scope.close(args);
/*eslint-enable angular/ng_controller_as */
}

View File

@ -25,6 +25,7 @@
describe('wizard directive', function () {
var $compile,
$scope,
$q,
element;
beforeEach(module('templates'));
@ -32,6 +33,7 @@
beforeEach(inject(function ($injector) {
$scope = $injector.get('$rootScope').$new();
$compile = $injector.get('$compile');
$q = $injector.get('$q');
element = $compile('<wizard></wizard>')($scope);
}));
@ -191,6 +193,19 @@
expect(checkedStep.checkReadiness).toHaveBeenCalled();
});
it('should pass result of submit function on to close function', function () {
$scope.$apply();
$scope.submit = function() {
var deferred = $q.defer();
deferred.resolve('foo');
return deferred.promise;
};
$scope.close = angular.noop;
spyOn($scope, 'close');
element[0].querySelector('button.finish').click();
expect($scope.close).toHaveBeenCalledWith('foo');
});
});
describe("ModalContainerController", function() {
@ -223,6 +238,12 @@
expect(modalInstance.close).toHaveBeenCalled();
});
it('passes arguments to scope.close on to the modal close function', function() {
spyOn(modalInstance, 'close');
scope.close('foo');
expect(modalInstance.close).toHaveBeenCalledWith('foo');
});
it('sets scope.cancel to a function that dismisses the modal', function() {
expect(scope.cancel).toBeDefined();
spyOn(modalInstance, 'dismiss');