Merge "Pass result of submit to wizard modal close"

This commit is contained in:
Jenkins
2015-12-04 08:14:11 +00:00
committed by Gerrit Code Review
3 changed files with 25 additions and 4 deletions

View File

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

View File

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

View File

@@ -25,6 +25,7 @@
describe('wizard directive', function () { describe('wizard directive', function () {
var $compile, var $compile,
$scope, $scope,
$q,
element; element;
beforeEach(module('templates')); beforeEach(module('templates'));
@@ -32,6 +33,7 @@
beforeEach(inject(function ($injector) { beforeEach(inject(function ($injector) {
$scope = $injector.get('$rootScope').$new(); $scope = $injector.get('$rootScope').$new();
$compile = $injector.get('$compile'); $compile = $injector.get('$compile');
$q = $injector.get('$q');
element = $compile('<wizard></wizard>')($scope); element = $compile('<wizard></wizard>')($scope);
})); }));
@@ -199,6 +201,19 @@
expect(checkedStep.checkReadiness).toHaveBeenCalled(); 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() { describe("ModalContainerController", function() {
@@ -231,6 +246,12 @@
expect(modalInstance.close).toHaveBeenCalled(); 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() { it('sets scope.cancel to a function that dismisses the modal', function() {
expect(scope.cancel).toBeDefined(); expect(scope.cancel).toBeDefined();
spyOn(modalInstance, 'dismiss'); spyOn(modalInstance, 'dismiss');