1
- /* global countScopes */
2
1
'use strict' ;
2
+ /* global describe, beforeEach, inject, it, expect, afterEach, spyOn, countScopes */
3
3
4
- describe ( 'dropdown' , function ( ) {
4
+ describe ( 'dropdown' , function ( ) {
5
5
6
6
var $compile , $templateCache , scope , sandboxEl , $animate , $timeout , $dropdown ;
7
7
8
8
beforeEach ( module ( 'ngAnimate' ) ) ;
9
9
beforeEach ( module ( 'ngAnimateMock' ) ) ;
10
10
beforeEach ( module ( 'ngSanitize' ) ) ;
11
11
beforeEach ( module ( 'mgcrea.ngStrap.dropdown' ) ) ;
12
+ beforeEach ( module ( 'mgcrea.ngStrap.modal' ) ) ;
12
13
13
- beforeEach ( inject ( function ( $injector , _$rootScope_ , _$compile_ , _$templateCache_ , _$animate_ , _$timeout_ , _$dropdown_ ) {
14
+ beforeEach ( inject ( function ( $injector , _$rootScope_ , _$compile_ , _$templateCache_ , _$animate_ , _$timeout_ , _$dropdown_ ) {
14
15
scope = _$rootScope_ . $new ( ) ;
15
16
sandboxEl = $ ( '<div>' ) . attr ( 'id' , 'sandbox' ) . appendTo ( $ ( 'body' ) ) ;
16
17
$compile = _$compile_ ;
@@ -19,7 +20,7 @@ describe('dropdown', function () {
19
20
$timeout = $injector . get ( '$timeout' ) ;
20
21
var flush = $animate . flush || $animate . triggerCallbacks ;
21
22
$animate . flush = function ( ) {
22
- flush . call ( $animate ) ; if ( ! $animate . triggerCallbacks ) $timeout . flush ( ) ;
23
+ flush . call ( $animate ) ; if ( ! $animate . triggerCallbacks ) $timeout . flush ( ) ;
23
24
} ;
24
25
$dropdown = _$dropdown_ ;
25
26
} ) ) ;
@@ -50,6 +51,9 @@ describe('dropdown', function () {
50
51
scope : { } ,
51
52
element : '<a bs-dropdown>click me</a><ul class="dropdown-menu"><li ng-repeat="i in [1, 2, 3]"><a>{{i}}</a></li></ul>'
52
53
} ,
54
+ 'markup-insideModal' : {
55
+ element : '<a data-template-url="custom" bs-modal>click me</a>'
56
+ } ,
53
57
'options-animation' : {
54
58
element : '<a data-animation="am-flip-x" bs-dropdown="dropdown">click me</a>'
55
59
} ,
@@ -89,7 +93,7 @@ describe('dropdown', function () {
89
93
90
94
function compileDirective ( template , locals ) {
91
95
template = templates [ template ] ;
92
- angular . extend ( scope , template . scope || templates [ ' default' ] . scope , locals ) ;
96
+ angular . extend ( scope , template . scope || templates . default . scope , locals ) ;
93
97
var element = $ ( template . element ) . appendTo ( sandboxEl ) ;
94
98
element = $compile ( element ) ( scope ) ;
95
99
scope . $digest ( ) ;
@@ -98,7 +102,7 @@ describe('dropdown', function () {
98
102
99
103
// Tests
100
104
101
- describe ( 'with default template' , function ( ) {
105
+ describe ( 'with default template' , function ( ) {
102
106
103
107
it ( 'should open on click' , function ( ) {
104
108
var elm = compileDirective ( 'default' ) ;
@@ -146,6 +150,14 @@ describe('dropdown', function () {
146
150
expect ( sandboxEl . children ( '.dropdown-menu' ) . children ( 'li' ) . length ) . toBe ( 3 ) ;
147
151
} ) ;
148
152
153
+ it ( 'should support being embedded in a modal' , function ( ) {
154
+ $templateCache . put ( 'custom' , '<a bs-dropdown="dropdown">click me</a>' ) ;
155
+ var elm = compileDirective ( 'markup-insideModal' ) ;
156
+ angular . element ( elm [ 0 ] ) . triggerHandler ( 'click' ) ;
157
+ angular . element ( elm [ 0 ] ) . triggerHandler ( 'click' ) ;
158
+ angular . element ( elm [ 0 ] ) . triggerHandler ( 'click' ) ;
159
+ } ) ;
160
+
149
161
} ) ;
150
162
151
163
describe ( 'resource allocation' , function ( ) {
@@ -265,23 +277,24 @@ describe('dropdown', function () {
265
277
var myDropdown = $dropdown ( sandboxEl ) ;
266
278
var emit = spyOn ( myDropdown . $scope , '$emit' ) ;
267
279
scope . $digest ( ) ;
268
- myDropdown . $promise . then ( function ( ) {
269
- myDropdown . $scope . content = templates [ 'default' ] . scope . dropdown ;
280
+ myDropdown . $promise
281
+ . then ( function ( ) {
282
+ myDropdown . $scope . content = templates . default . scope . dropdown ;
270
283
myDropdown . show ( ) ;
271
284
272
285
expect ( emit ) . toHaveBeenCalledWith ( 'dropdown.show.before' , myDropdown ) ;
273
286
// show only fires AFTER the animation is complete
274
287
expect ( emit ) . not . toHaveBeenCalledWith ( 'dropdown.show' , myDropdown ) ;
275
288
$animate . flush ( ) ;
276
289
expect ( emit ) . toHaveBeenCalledWith ( 'dropdown.show' , myDropdown ) ;
277
- } ) ;
290
+ } ) ;
278
291
} ) ;
279
292
280
293
it ( 'should dispatch hide and hide.before events' , function ( ) {
281
294
var myDropdown = $dropdown ( sandboxEl ) ;
282
295
scope . $digest ( ) ;
283
- myDropdown . $promise . then ( function ( ) {
284
- myDropdown . $scope . content = templates [ ' default' ] . scope . dropdown ;
296
+ myDropdown . $promise . then ( function ( ) {
297
+ myDropdown . $scope . content = templates . default . scope . dropdown ;
285
298
myDropdown . show ( ) ;
286
299
287
300
var emit = spyOn ( myDropdown . $scope , '$emit' ) ;
@@ -309,9 +322,9 @@ describe('dropdown', function () {
309
322
310
323
} ) ;
311
324
312
- describe ( 'options' , function ( ) {
325
+ describe ( 'options' , function ( ) {
313
326
314
- describe ( 'animation' , function ( ) {
327
+ describe ( 'animation' , function ( ) {
315
328
316
329
it ( 'should default to `am-fade` animation' , function ( ) {
317
330
var elm = compileDirective ( 'default' ) ;
@@ -327,9 +340,9 @@ describe('dropdown', function () {
327
340
328
341
} ) ;
329
342
330
- describe ( 'placement' , function ( ) {
343
+ describe ( 'placement' , function ( ) {
331
344
var $$rAF ;
332
- beforeEach ( inject ( function ( _$$rAF_ ) {
345
+ beforeEach ( inject ( function ( _$$rAF_ ) {
333
346
$$rAF = _$$rAF_ ;
334
347
} ) ) ;
335
348
@@ -356,7 +369,7 @@ describe('dropdown', function () {
356
369
357
370
} ) ;
358
371
359
- describe ( 'trigger' , function ( ) {
372
+ describe ( 'trigger' , function ( ) {
360
373
361
374
it ( 'should support an alternative trigger' , function ( ) {
362
375
var elm = compileDirective ( 'options-trigger' ) ;
@@ -369,7 +382,7 @@ describe('dropdown', function () {
369
382
370
383
} ) ;
371
384
372
- describe ( 'html' , function ( ) {
385
+ describe ( 'html' , function ( ) {
373
386
374
387
it ( 'should correctly compile inner content when html is true' , function ( ) {
375
388
var elm = compileDirective ( 'options-html' , { html : 'true' } ) ;
@@ -387,7 +400,7 @@ describe('dropdown', function () {
387
400
388
401
} ) ;
389
402
390
- describe ( 'template' , function ( ) {
403
+ describe ( 'template' , function ( ) {
391
404
392
405
it ( 'should support custom template' , function ( ) {
393
406
$templateCache . put ( 'custom' , '<div class="dropdown"><div class="dropdown-inner">foo: {{dropdown.length}}</div></div>' ) ;
0 commit comments