Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Commit

Permalink
fix(alert): correct scope typo (fixes #348)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgcrea committed Jan 15, 2014
1 parent 4b80b37 commit 1bc0372
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/alert/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ angular.module('mgcrea.ngStrap.alert', [])
// Support scope as string options
if(!options.scope) {
angular.forEach([/*'title', 'content', */'type'], function(key) {
if(options[key]) $alert.scope[key] = options[key];
if(options[key]) $alert.$scope[key] = options[key];
});
}

Expand Down
55 changes: 46 additions & 9 deletions src/alert/test/alert.spec.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
'use strict';

describe('alert', function () {
describe('alert', function() {

var $compile, $templateCache, scope, sandboxEl;
var bodyEl = $('body'), sandboxEl;
var $compile, $templateCache, $alert, scope;

beforeEach(module('ngSanitize'));
beforeEach(module('mgcrea.ngStrap.modal', 'mgcrea.ngStrap.alert'));

beforeEach(inject(function (_$rootScope_, _$compile_, _$templateCache_) {
beforeEach(inject(function (_$rootScope_, _$compile_, _$templateCache_, _$alert_) {
scope = _$rootScope_.$new();
bodyEl.html('');
sandboxEl = $('<div>').attr('id', 'sandbox').appendTo($('body'));
$compile = _$compile_;
$templateCache = _$templateCache_;
$alert = _$alert_;
}));

afterEach(function() {
Expand All @@ -33,6 +36,9 @@ describe('alert', function () {
scope: {items: [{name: 'foo', alert: {title: 'Title', content: 'Hello alert!'}}]},
element: '<ul><li ng-repeat="item in items"><a title="{{item.alert.title}}" data-content="{{item.alert.content}}" bs-alert>{{item.name}}</a></li></ul>'
},
'markup-ngClick-service': {
element: '<a ng-click="showAlert()">click me</a>'
},
'options-placement': {
element: '<a data-placement="left" bs-alert="alert">click me</a>'
},
Expand All @@ -57,7 +63,7 @@ describe('alert', function () {

// Tests

describe('with default template', function () {
describe('with default template', function() {

it('should open on click', function() {
var elm = compileDirective('default');
Expand Down Expand Up @@ -97,10 +103,41 @@ describe('alert', function () {

});

describe('using service', function() {

it('should correctly open on next digest', function() {
var myAlert = $alert(angular.extend({type: 'danger'}, templates['default'].scope.alert));
scope.$digest();
expect(bodyEl.children('.alert').length).toBe(1);
myAlert.hide();
expect(bodyEl.children('.alert').length).toBe(0);
});

it('should correctly be destroyed', function() {
var myAlert = $alert(templates['default'].scope.alert);
scope.$digest();
expect(bodyEl.children('.alert').length).toBe(1);
myAlert.destroy();
expect(bodyEl.children('.alert').length).toBe(0);
expect(bodyEl.children().length).toBe(1);
});

it('should correctly work with ngClick', function() {
var elm = compileDirective('markup-ngClick-service');
var myAlert = $alert(angular.extend({show: false}, templates['default'].scope.alert));
scope.showAlert = function() {
myAlert.$promise.then(myAlert.show);
};
expect(bodyEl.children('.alert').length).toBe(0);
angular.element(elm[0]).triggerHandler('click');
expect(bodyEl.children('.alert').length).toBe(1);
});

});

describe('options', function () {
describe('options', function() {

describe('animation', function () {
describe('animation', function() {

it('should default to `animation-fade` animation', function() {
var elm = compileDirective('default');
Expand All @@ -110,7 +147,7 @@ describe('alert', function () {

});

describe('placement', function () {
describe('placement', function() {

it('should default to `null` placement', function() {
var elm = compileDirective('default');
Expand All @@ -126,7 +163,7 @@ describe('alert', function () {

});

describe('html', function () {
describe('html', function() {

it('should correctly compile inner content', function() {
var elm = compileDirective('options-html');
Expand All @@ -137,7 +174,7 @@ describe('alert', function () {

});

describe('template', function () {
describe('template', function() {

it('should support custom template', function() {
$templateCache.put('custom', '<div class="alert"><div class="alert-inner">foo: {{title}}</div></div>');
Expand Down

0 comments on commit 1bc0372

Please sign in to comment.