Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
refactor(alert): move logic to controller & add tests
Browse files Browse the repository at this point in the history
 * Add missing tests that `close` button is actually visible
   Tests were passing even if link function was empty.
  • Loading branch information
bekos committed Dec 14, 2013
1 parent 3fe7aa8 commit 41bea46
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/alert/alert.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
angular.module("ui.bootstrap.alert", []).directive('alert', function () {
angular.module("ui.bootstrap.alert", [])

.controller('AlertController', ['$scope', '$attrs', function ($scope, $attrs) {
$scope.closeable = 'close' in $attrs;
}])

.directive('alert', function () {
return {
restrict:'EA',
controller:'AlertController',
templateUrl:'template/alert/alert.html',
transclude:true,
replace:true,
scope: {
type: '=',
close: '&'
},
link: function(scope, iElement, iAttrs) {
scope.closeable = "close" in iAttrs;
}
};
});
10 changes: 10 additions & 0 deletions src/alert/test/alert.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ describe("alert", function () {
expect(alerts.eq(2)).not.toHaveClass('alert-block');
});

it("should show close buttons", function () {
var alerts = createAlerts();

for (var i = 0, n = alerts.length; i < n; i++) {
expect(findCloseButton(i).css('display')).not.toBe('none');
}
});

it("should fire callback when closed", function () {

var alerts = createAlerts();
Expand All @@ -59,7 +67,9 @@ describe("alert", function () {
scope.removeAlert = jasmine.createSpy();
});

expect(findCloseButton(0).css('display')).not.toBe('none');
findCloseButton(1).click();

expect(scope.removeAlert).toHaveBeenCalledWith(1);
});

Expand Down

0 comments on commit 41bea46

Please sign in to comment.