1
0
mirror of synced 2024-11-25 14:26:03 +03:00

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.
This commit is contained in:
Kevin Brown 2015-12-31 13:04:38 -05:00
parent bc19964170
commit 9c35475c6c
2 changed files with 60 additions and 0 deletions

View File

@ -0,0 +1,59 @@
module('Dropdown - attachBody - positioning');
test('appends to the dropdown parent', function (assert) {
expect(4);
var $ = require('jquery');
var $select = $('<select></select>');
var $parent = $('<div></div>');
var $container = $('<span></span>');
var container = new MockContainer();
$parent.appendTo($('#qunit-fixture'));
$select.appendTo($parent);
var Utils = require('select2/utils');
var Options = require('select2/options');
var Dropdown = require('select2/dropdown');
var AttachBody = require('select2/dropdown/attachBody');
var DropdownAdapter = Utils.Decorate(Dropdown, AttachBody);
var dropdown = new DropdownAdapter($select, new Options({
dropdownParent: $parent
}));
assert.equal(
$parent.children().length,
1,
'Only the select should be in the container'
);
var $dropdown = dropdown.render();
dropdown.bind(container, $container);
dropdown.position($dropdown, $container);
assert.equal(
$parent.children().length,
1,
'The dropdown should not be placed until after it is opened'
);
dropdown._showDropdown();
assert.equal(
$parent.children().length,
2,
'The dropdown should now be in the container as well'
);
assert.ok(
$.contains($parent[0], $dropdown[0]),
'The dropdown should be contained within the parent container'
);
});

View File

@ -69,6 +69,7 @@
<script src="data/minimumInputLength-tests.js" type="text/javascript"></script>
<script src="dropdown/dropdownCss-tests.js" type="text/javascript"></script>
<script src="dropdown/positioning-tests.js" type="text/javascript"></script>
<script src="dropdown/selectOnClose-tests.js" type="text/javascript"></script>
<script src="dropdown/stopPropagation-tests.js" type="text/javascript"></script>