Skip to content

Commit 9c35475

Browse files
committed
Added test for attachBody
This is just a basic test that ensures that the dropdown is appended to the end of the dropdown parent when `dropdownParent` is defined.
1 parent bc19964 commit 9c35475

2 files changed

Lines changed: 60 additions & 0 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
module('Dropdown - attachBody - positioning');
2+
3+
test('appends to the dropdown parent', function (assert) {
4+
expect(4);
5+
6+
var $ = require('jquery');
7+
8+
var $select = $('<select></select>');
9+
var $parent = $('<div></div>');
10+
11+
var $container = $('<span></span>');
12+
var container = new MockContainer();
13+
14+
$parent.appendTo($('#qunit-fixture'));
15+
$select.appendTo($parent);
16+
17+
var Utils = require('select2/utils');
18+
var Options = require('select2/options');
19+
20+
var Dropdown = require('select2/dropdown');
21+
var AttachBody = require('select2/dropdown/attachBody');
22+
23+
var DropdownAdapter = Utils.Decorate(Dropdown, AttachBody);
24+
25+
var dropdown = new DropdownAdapter($select, new Options({
26+
dropdownParent: $parent
27+
}));
28+
29+
assert.equal(
30+
$parent.children().length,
31+
1,
32+
'Only the select should be in the container'
33+
);
34+
35+
var $dropdown = dropdown.render();
36+
37+
dropdown.bind(container, $container);
38+
39+
dropdown.position($dropdown, $container);
40+
41+
assert.equal(
42+
$parent.children().length,
43+
1,
44+
'The dropdown should not be placed until after it is opened'
45+
);
46+
47+
dropdown._showDropdown();
48+
49+
assert.equal(
50+
$parent.children().length,
51+
2,
52+
'The dropdown should now be in the container as well'
53+
);
54+
55+
assert.ok(
56+
$.contains($parent[0], $dropdown[0]),
57+
'The dropdown should be contained within the parent container'
58+
);
59+
});

tests/unit.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
<script src="data/minimumInputLength-tests.js" type="text/javascript"></script>
7070

7171
<script src="dropdown/dropdownCss-tests.js" type="text/javascript"></script>
72+
<script src="dropdown/positioning-tests.js" type="text/javascript"></script>
7273
<script src="dropdown/selectOnClose-tests.js" type="text/javascript"></script>
7374
<script src="dropdown/stopPropagation-tests.js" type="text/javascript"></script>
7475

0 commit comments

Comments
 (0)