From 41bea46b557df64822861551638bf8be21454124 Mon Sep 17 00:00:00 2001 From: Tasos Bekos Date: Wed, 11 Dec 2013 13:01:11 +0100 Subject: [PATCH] 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. --- src/alert/alert.js | 12 ++++++++---- src/alert/test/alert.spec.js | 10 ++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/alert/alert.js b/src/alert/alert.js index b8bb392a1a..16df5339dc 100644 --- a/src/alert/alert.js +++ b/src/alert/alert.js @@ -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; } }; }); diff --git a/src/alert/test/alert.spec.js b/src/alert/test/alert.spec.js index 7a5feb42cf..6742c5ea0f 100644 --- a/src/alert/test/alert.spec.js +++ b/src/alert/test/alert.spec.js @@ -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(); @@ -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); });