Skip to content

Commit

Permalink
fix(rxModalAction): close modal on route change #157
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Lamping committed Apr 17, 2014
1 parent 64473c5 commit db7e0fe
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion grunt-tasks/options/connect.js
Expand Up @@ -29,7 +29,7 @@ module.exports = {
config.mountFolder(cnct, config.docs)
];
},
livereload:1337
livereload: 1337
}
},
keepalive: {
Expand Down
5 changes: 4 additions & 1 deletion src/rxModalAction/rxModalAction.js
Expand Up @@ -13,13 +13,16 @@ angular.module('encore.ui.rxModalAction', ['ui.bootstrap'])
}
};
})
.controller('rxModalCtrl', function ($scope, $modalInstance) {
.controller('rxModalCtrl', function ($scope, $modalInstance, $rootScope) {
// define a controller for the modal to use
$scope.submit = function () {
$modalInstance.close($scope);
};

$scope.cancel = $modalInstance.dismiss;

// cancel out of the modal if the route is changed
$rootScope.$on('$routeChangeSuccess', $modalInstance.dismiss);
})
.directive('rxModalAction', function ($modal) {
var createModal = function (config, scope) {
Expand Down
20 changes: 18 additions & 2 deletions src/rxModalAction/rxModalAction.spec.js
@@ -1,8 +1,8 @@
/* jshint node: true */

describe('rxModalAction', function () {
var el, scope, compile, rootScope, mockModal, modalApi, instanceApi, instanceMock, controller,
validTemplate = '<rx-modal-action ' +
var el, scope, compile, rootScope, mockModal, modalApi, instanceApi, instanceMock, controller;
var validTemplate = '<rx-modal-action ' +
'template-url="test.html" ' +
'post-hook="post()" ' +
'pre-hook="pre()" ' +
Expand Down Expand Up @@ -112,6 +112,22 @@ describe('rxModalAction', function () {
instanceMock.verify();
});

it('should dismiss modal on routeChange', function () {
var link = el.find('a')[0];

helpers.clickElement(link);

instanceMock.expects('close').never();
instanceMock.expects('dismiss').once();

setupModalCtrl(modalApi.open.getCall(0).args[0].controller);

// fake a route change
rootScope.$broadcast('$routeChangeSuccess');

instanceMock.verify();
});

it('should focus on calling link after submitting', function () {
var link = el.find('a')[0];

Expand Down

0 comments on commit db7e0fe

Please sign in to comment.