From 01e68f4dd76e52cae9a446ae0799100000c581b8 Mon Sep 17 00:00:00 2001 From: Mikhail Titov Date: Mon, 24 Sep 2018 20:54:34 -0500 Subject: [PATCH] Test for dropdownParent option --- tests/dropdown/dropdownParent-tests.js | 83 ++++++++++++++++++++++++++ tests/unit-jq1.html | 1 + tests/unit-jq2.html | 1 + tests/unit-jq3.html | 1 + 4 files changed, 86 insertions(+) create mode 100644 tests/dropdown/dropdownParent-tests.js diff --git a/tests/dropdown/dropdownParent-tests.js b/tests/dropdown/dropdownParent-tests.js new file mode 100644 index 00000000..1ccd5b9f --- /dev/null +++ b/tests/dropdown/dropdownParent-tests.js @@ -0,0 +1,83 @@ +module('Dropdown - attachBody - dropdownParent option'); + +test('can be a selector string', function (assert) { + assert.expect(1); + + var $ = require('jquery'); + + var $select = $(''); + var $parent = $('
'); + + $('#qunit-fixture').append($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( + dropdown.$dropdownParent[0], + $parent[0], + 'Should be parsed using the selector as a jQuery object' + ); +}); + +test('can be a jQuery object', function (assert) { + assert.expect(1); + + var $ = require('jquery'); + + var $select = $(''); + var $parent = $('
'); + + $('#qunit-fixture').append($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( + dropdown.$dropdownParent[0], + $parent[0], + 'Should just take the passed in jQuery object' + ); +}); + +test('defaults to the document body', function (assert) { + assert.expect(1); + + var $ = require('jquery'); + + var $select = $(''); + + 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({})); + + assert.equal( + dropdown.$dropdownParent[0], + document.body, + 'Should default to wrapping document.body' + ); +}); diff --git a/tests/unit-jq1.html b/tests/unit-jq1.html index dc2ca21e..b5ec3461 100644 --- a/tests/unit-jq1.html +++ b/tests/unit-jq1.html @@ -70,6 +70,7 @@ + diff --git a/tests/unit-jq2.html b/tests/unit-jq2.html index 52500510..7eca5057 100644 --- a/tests/unit-jq2.html +++ b/tests/unit-jq2.html @@ -70,6 +70,7 @@ + diff --git a/tests/unit-jq3.html b/tests/unit-jq3.html index d038818a..a34f771c 100644 --- a/tests/unit-jq3.html +++ b/tests/unit-jq3.html @@ -70,6 +70,7 @@ +