|
| 1 | +module('Dropdown - attachBody - dropdownParent option'); |
| 2 | + |
| 3 | +test('can be a selector string', function (assert) { |
| 4 | + assert.expect(1); |
| 5 | + |
| 6 | + var $ = require('jquery'); |
| 7 | + |
| 8 | + var $select = $('<select></select>'); |
| 9 | + var $parent = $('<div id="parent"></div>'); |
| 10 | + |
| 11 | + $('#qunit-fixture').append($parent); |
| 12 | + |
| 13 | + var Utils = require('select2/utils'); |
| 14 | + var Options = require('select2/options'); |
| 15 | + |
| 16 | + var Dropdown = require('select2/dropdown'); |
| 17 | + var AttachBody = require('select2/dropdown/attachBody'); |
| 18 | + |
| 19 | + var DropdownAdapter = Utils.Decorate(Dropdown, AttachBody); |
| 20 | + |
| 21 | + var dropdown = new DropdownAdapter($select, new Options({ |
| 22 | + dropdownParent: '#parent' |
| 23 | + })); |
| 24 | + |
| 25 | + assert.equal( |
| 26 | + dropdown.$dropdownParent[0], |
| 27 | + $parent[0], |
| 28 | + 'Should be parsed using the selector as a jQuery object' |
| 29 | + ); |
| 30 | +}); |
| 31 | + |
| 32 | +test('can be a jQuery object', function (assert) { |
| 33 | + assert.expect(1); |
| 34 | + |
| 35 | + var $ = require('jquery'); |
| 36 | + |
| 37 | + var $select = $('<select></select>'); |
| 38 | + var $parent = $('<div id="parent"></div>'); |
| 39 | + |
| 40 | + $('#qunit-fixture').append($parent); |
| 41 | + |
| 42 | + var Utils = require('select2/utils'); |
| 43 | + var Options = require('select2/options'); |
| 44 | + |
| 45 | + var Dropdown = require('select2/dropdown'); |
| 46 | + var AttachBody = require('select2/dropdown/attachBody'); |
| 47 | + |
| 48 | + var DropdownAdapter = Utils.Decorate(Dropdown, AttachBody); |
| 49 | + |
| 50 | + var dropdown = new DropdownAdapter($select, new Options({ |
| 51 | + dropdownParent: $parent |
| 52 | + })); |
| 53 | + |
| 54 | + assert.equal( |
| 55 | + dropdown.$dropdownParent[0], |
| 56 | + $parent[0], |
| 57 | + 'Should just take the passed in jQuery object' |
| 58 | + ); |
| 59 | +}); |
| 60 | + |
| 61 | +test('defaults to the document body', function (assert) { |
| 62 | + assert.expect(1); |
| 63 | + |
| 64 | + var $ = require('jquery'); |
| 65 | + |
| 66 | + var $select = $('<select></select>'); |
| 67 | + |
| 68 | + var Utils = require('select2/utils'); |
| 69 | + var Options = require('select2/options'); |
| 70 | + |
| 71 | + var Dropdown = require('select2/dropdown'); |
| 72 | + var AttachBody = require('select2/dropdown/attachBody'); |
| 73 | + |
| 74 | + var DropdownAdapter = Utils.Decorate(Dropdown, AttachBody); |
| 75 | + |
| 76 | + var dropdown = new DropdownAdapter($select, new Options({})); |
| 77 | + |
| 78 | + assert.equal( |
| 79 | + dropdown.$dropdownParent[0], |
| 80 | + document.body, |
| 81 | + 'Should default to wrapping document.body' |
| 82 | + ); |
| 83 | +}); |
0 commit comments