No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dropdownParent-tests.js 2.1KB

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