11'use strict' ;
22
3- describe ( 'alert' , function ( ) {
3+ describe ( 'alert' , function ( ) {
44
5- var $compile , $templateCache , scope , sandboxEl ;
5+ var bodyEl = $ ( 'body' ) , sandboxEl ;
6+ var $compile , $templateCache , $alert , scope ;
67
78 beforeEach ( module ( 'ngSanitize' ) ) ;
89 beforeEach ( module ( 'mgcrea.ngStrap.modal' , 'mgcrea.ngStrap.alert' ) ) ;
910
10- beforeEach ( inject ( function ( _$rootScope_ , _$compile_ , _$templateCache_ ) {
11+ beforeEach ( inject ( function ( _$rootScope_ , _$compile_ , _$templateCache_ , _$alert_ ) {
1112 scope = _$rootScope_ . $new ( ) ;
13+ bodyEl . html ( '' ) ;
1214 sandboxEl = $ ( '<div>' ) . attr ( 'id' , 'sandbox' ) . appendTo ( $ ( 'body' ) ) ;
1315 $compile = _$compile_ ;
1416 $templateCache = _$templateCache_ ;
17+ $alert = _$alert_ ;
1518 } ) ) ;
1619
1720 afterEach ( function ( ) {
@@ -33,6 +36,9 @@ describe('alert', function () {
3336 scope : { items : [ { name : 'foo' , alert : { title : 'Title' , content : 'Hello alert!' } } ] } ,
3437 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>'
3538 } ,
39+ 'markup-ngClick-service' : {
40+ element : '<a ng-click="showAlert()">click me</a>'
41+ } ,
3642 'options-placement' : {
3743 element : '<a data-placement="left" bs-alert="alert">click me</a>'
3844 } ,
@@ -57,7 +63,7 @@ describe('alert', function () {
5763
5864 // Tests
5965
60- describe ( 'with default template' , function ( ) {
66+ describe ( 'with default template' , function ( ) {
6167
6268 it ( 'should open on click' , function ( ) {
6369 var elm = compileDirective ( 'default' ) ;
@@ -97,10 +103,41 @@ describe('alert', function () {
97103
98104 } ) ;
99105
106+ describe ( 'using service' , function ( ) {
107+
108+ it ( 'should correctly open on next digest' , function ( ) {
109+ var myAlert = $alert ( angular . extend ( { type : 'danger' } , templates [ 'default' ] . scope . alert ) ) ;
110+ scope . $digest ( ) ;
111+ expect ( bodyEl . children ( '.alert' ) . length ) . toBe ( 1 ) ;
112+ myAlert . hide ( ) ;
113+ expect ( bodyEl . children ( '.alert' ) . length ) . toBe ( 0 ) ;
114+ } ) ;
115+
116+ it ( 'should correctly be destroyed' , function ( ) {
117+ var myAlert = $alert ( templates [ 'default' ] . scope . alert ) ;
118+ scope . $digest ( ) ;
119+ expect ( bodyEl . children ( '.alert' ) . length ) . toBe ( 1 ) ;
120+ myAlert . destroy ( ) ;
121+ expect ( bodyEl . children ( '.alert' ) . length ) . toBe ( 0 ) ;
122+ expect ( bodyEl . children ( ) . length ) . toBe ( 1 ) ;
123+ } ) ;
124+
125+ it ( 'should correctly work with ngClick' , function ( ) {
126+ var elm = compileDirective ( 'markup-ngClick-service' ) ;
127+ var myAlert = $alert ( angular . extend ( { show : false } , templates [ 'default' ] . scope . alert ) ) ;
128+ scope . showAlert = function ( ) {
129+ myAlert . $promise . then ( myAlert . show ) ;
130+ } ;
131+ expect ( bodyEl . children ( '.alert' ) . length ) . toBe ( 0 ) ;
132+ angular . element ( elm [ 0 ] ) . triggerHandler ( 'click' ) ;
133+ expect ( bodyEl . children ( '.alert' ) . length ) . toBe ( 1 ) ;
134+ } ) ;
135+
136+ } ) ;
100137
101- describe ( 'options' , function ( ) {
138+ describe ( 'options' , function ( ) {
102139
103- describe ( 'animation' , function ( ) {
140+ describe ( 'animation' , function ( ) {
104141
105142 it ( 'should default to `animation-fade` animation' , function ( ) {
106143 var elm = compileDirective ( 'default' ) ;
@@ -110,7 +147,7 @@ describe('alert', function () {
110147
111148 } ) ;
112149
113- describe ( 'placement' , function ( ) {
150+ describe ( 'placement' , function ( ) {
114151
115152 it ( 'should default to `null` placement' , function ( ) {
116153 var elm = compileDirective ( 'default' ) ;
@@ -126,7 +163,7 @@ describe('alert', function () {
126163
127164 } ) ;
128165
129- describe ( 'html' , function ( ) {
166+ describe ( 'html' , function ( ) {
130167
131168 it ( 'should correctly compile inner content' , function ( ) {
132169 var elm = compileDirective ( 'options-html' ) ;
@@ -137,7 +174,7 @@ describe('alert', function () {
137174
138175 } ) ;
139176
140- describe ( 'template' , function ( ) {
177+ describe ( 'template' , function ( ) {
141178
142179 it ( 'should support custom template' , function ( ) {
143180 $templateCache . put ( 'custom' , '<div class="alert"><div class="alert-inner">foo: {{title}}</div></div>' ) ;
0 commit comments