Skip to content

Commit f91f4da

Browse files
committed
test(dropdown): test being embedded in a modal
1 parent c8d06e4 commit f91f4da

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

src/dropdown/test/dropdown.spec.js

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
/* global countScopes */
21
'use strict';
2+
/* global describe, beforeEach, inject, it, expect, afterEach, spyOn, countScopes */
33

4-
describe('dropdown', function () {
4+
describe('dropdown', function() {
55

66
var $compile, $templateCache, scope, sandboxEl, $animate, $timeout, $dropdown;
77

88
beforeEach(module('ngAnimate'));
99
beforeEach(module('ngAnimateMock'));
1010
beforeEach(module('ngSanitize'));
1111
beforeEach(module('mgcrea.ngStrap.dropdown'));
12+
beforeEach(module('mgcrea.ngStrap.modal'));
1213

13-
beforeEach(inject(function ($injector, _$rootScope_, _$compile_, _$templateCache_, _$animate_, _$timeout_, _$dropdown_) {
14+
beforeEach(inject(function($injector, _$rootScope_, _$compile_, _$templateCache_, _$animate_, _$timeout_, _$dropdown_) {
1415
scope = _$rootScope_.$new();
1516
sandboxEl = $('<div>').attr('id', 'sandbox').appendTo($('body'));
1617
$compile = _$compile_;
@@ -19,7 +20,7 @@ describe('dropdown', function () {
1920
$timeout = $injector.get('$timeout');
2021
var flush = $animate.flush || $animate.triggerCallbacks;
2122
$animate.flush = function() {
22-
flush.call($animate); if(!$animate.triggerCallbacks) $timeout.flush();
23+
flush.call($animate); if (!$animate.triggerCallbacks) $timeout.flush();
2324
};
2425
$dropdown = _$dropdown_;
2526
}));
@@ -50,6 +51,9 @@ describe('dropdown', function () {
5051
scope: {},
5152
element: '<a bs-dropdown>click me</a><ul class="dropdown-menu"><li ng-repeat="i in [1, 2, 3]"><a>{{i}}</a></li></ul>'
5253
},
54+
'markup-insideModal': {
55+
element: '<a data-template-url="custom" bs-modal>click me</a>'
56+
},
5357
'options-animation': {
5458
element: '<a data-animation="am-flip-x" bs-dropdown="dropdown">click me</a>'
5559
},
@@ -89,7 +93,7 @@ describe('dropdown', function () {
8993

9094
function compileDirective(template, locals) {
9195
template = templates[template];
92-
angular.extend(scope, template.scope || templates['default'].scope, locals);
96+
angular.extend(scope, template.scope || templates.default.scope, locals);
9397
var element = $(template.element).appendTo(sandboxEl);
9498
element = $compile(element)(scope);
9599
scope.$digest();
@@ -98,7 +102,7 @@ describe('dropdown', function () {
98102

99103
// Tests
100104

101-
describe('with default template', function () {
105+
describe('with default template', function() {
102106

103107
it('should open on click', function() {
104108
var elm = compileDirective('default');
@@ -146,6 +150,14 @@ describe('dropdown', function () {
146150
expect(sandboxEl.children('.dropdown-menu').children('li').length).toBe(3);
147151
});
148152

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+
149161
});
150162

151163
describe('resource allocation', function() {
@@ -265,23 +277,24 @@ describe('dropdown', function () {
265277
var myDropdown = $dropdown(sandboxEl);
266278
var emit = spyOn(myDropdown.$scope, '$emit');
267279
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;
270283
myDropdown.show();
271284

272285
expect(emit).toHaveBeenCalledWith('dropdown.show.before', myDropdown);
273286
// show only fires AFTER the animation is complete
274287
expect(emit).not.toHaveBeenCalledWith('dropdown.show', myDropdown);
275288
$animate.flush();
276289
expect(emit).toHaveBeenCalledWith('dropdown.show', myDropdown);
277-
});
290+
});
278291
});
279292

280293
it('should dispatch hide and hide.before events', function() {
281294
var myDropdown = $dropdown(sandboxEl);
282295
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;
285298
myDropdown.show();
286299

287300
var emit = spyOn(myDropdown.$scope, '$emit');
@@ -309,9 +322,9 @@ describe('dropdown', function () {
309322

310323
});
311324

312-
describe('options', function () {
325+
describe('options', function() {
313326

314-
describe('animation', function () {
327+
describe('animation', function() {
315328

316329
it('should default to `am-fade` animation', function() {
317330
var elm = compileDirective('default');
@@ -327,9 +340,9 @@ describe('dropdown', function () {
327340

328341
});
329342

330-
describe('placement', function () {
343+
describe('placement', function() {
331344
var $$rAF;
332-
beforeEach(inject(function (_$$rAF_) {
345+
beforeEach(inject(function(_$$rAF_) {
333346
$$rAF = _$$rAF_;
334347
}));
335348

@@ -356,7 +369,7 @@ describe('dropdown', function () {
356369

357370
});
358371

359-
describe('trigger', function () {
372+
describe('trigger', function() {
360373

361374
it('should support an alternative trigger', function() {
362375
var elm = compileDirective('options-trigger');
@@ -369,7 +382,7 @@ describe('dropdown', function () {
369382

370383
});
371384

372-
describe('html', function () {
385+
describe('html', function() {
373386

374387
it('should correctly compile inner content when html is true', function() {
375388
var elm = compileDirective('options-html', {html: 'true'});
@@ -387,7 +400,7 @@ describe('dropdown', function () {
387400

388401
});
389402

390-
describe('template', function () {
403+
describe('template', function() {
391404

392405
it('should support custom template', function() {
393406
$templateCache.put('custom', '<div class="dropdown"><div class="dropdown-inner">foo: {{dropdown.length}}</div></div>');

0 commit comments

Comments
 (0)