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

Commit 41bea46

Browse files
committed
refactor(alert): move logic to controller & add tests
* Add missing tests that `close` button is actually visible Tests were passing even if link function was empty.
1 parent 3fe7aa8 commit 41bea46

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/alert/alert.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
angular.module("ui.bootstrap.alert", []).directive('alert', function () {
1+
angular.module("ui.bootstrap.alert", [])
2+
3+
.controller('AlertController', ['$scope', '$attrs', function ($scope, $attrs) {
4+
$scope.closeable = 'close' in $attrs;
5+
}])
6+
7+
.directive('alert', function () {
28
return {
39
restrict:'EA',
10+
controller:'AlertController',
411
templateUrl:'template/alert/alert.html',
512
transclude:true,
613
replace:true,
714
scope: {
815
type: '=',
916
close: '&'
10-
},
11-
link: function(scope, iElement, iAttrs) {
12-
scope.closeable = "close" in iAttrs;
1317
}
1418
};
1519
});

src/alert/test/alert.spec.js

+10
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ describe("alert", function () {
5151
expect(alerts.eq(2)).not.toHaveClass('alert-block');
5252
});
5353

54+
it("should show close buttons", function () {
55+
var alerts = createAlerts();
56+
57+
for (var i = 0, n = alerts.length; i < n; i++) {
58+
expect(findCloseButton(i).css('display')).not.toBe('none');
59+
}
60+
});
61+
5462
it("should fire callback when closed", function () {
5563

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

70+
expect(findCloseButton(0).css('display')).not.toBe('none');
6271
findCloseButton(1).click();
72+
6373
expect(scope.removeAlert).toHaveBeenCalledWith(1);
6474
});
6575

0 commit comments

Comments
 (0)