From 9c35475c6cba5d2ccd9767deab81687244bc210a Mon Sep 17 00:00:00 2001 From: Kevin Brown Date: Thu, 31 Dec 2015 13:04:38 -0500 Subject: [PATCH] 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. --- tests/dropdown/positioning-tests.js | 59 +++++++++++++++++++++++++++++ tests/unit.html | 1 + 2 files changed, 60 insertions(+) create mode 100644 tests/dropdown/positioning-tests.js diff --git a/tests/dropdown/positioning-tests.js b/tests/dropdown/positioning-tests.js new file mode 100644 index 00000000..3c41c83d --- /dev/null +++ b/tests/dropdown/positioning-tests.js @@ -0,0 +1,59 @@ +module('Dropdown - attachBody - positioning'); + +test('appends to the dropdown parent', function (assert) { + expect(4); + + var $ = require('jquery'); + + var $select = $(''); + var $parent = $('
'); + + var $container = $(''); + 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' + ); +}); \ No newline at end of file diff --git a/tests/unit.html b/tests/unit.html index c1f19c5e..49de5188 100644 --- a/tests/unit.html +++ b/tests/unit.html @@ -69,6 +69,7 @@ +