1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-08-26 06:44:35 +02:00

Move dropdown offset function logic into private function. (#28138)

This commit is contained in:
Jason Golieb
2019-02-05 03:31:18 -05:00
committed by XhmikosR
parent 1139f62ca2
commit e44d0475e0
3 changed files with 73 additions and 7 deletions

View File

@@ -1361,4 +1361,59 @@ $(function () {
$dropdown.hide()
assert.ok($dropdown.parent('.dropdown').hasClass('show'))
})
QUnit.test('should create offset modifier correctly when offset option is a function', function (assert) {
assert.expect(2)
var getOffset = function (offsets) {
return offsets
}
var dropdownHTML =
'<div class="dropdown">' +
' <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>' +
' <div class="dropdown-menu">' +
' <a class="dropdown-item" href="#">Another link</a>' +
' </div>' +
'</div>'
var $dropdown = $(dropdownHTML)
.appendTo('#qunit-fixture')
.find('[data-toggle="dropdown"]')
.bootstrapDropdown({
offset: getOffset
})
var dropdown = $dropdown.data('bs.dropdown')
var offset = dropdown._getOffset()
assert.ok(typeof offset.offset === 'undefined')
assert.ok(typeof offset.fn === 'function')
})
QUnit.test('should create offset modifier correctly when offset option is not a function', function (assert) {
assert.expect(2)
var dropdownHTML =
'<div class="dropdown">' +
' <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>' +
' <div class="dropdown-menu">' +
' <a class="dropdown-item" href="#">Another link</a>' +
' </div>' +
'</div>'
var myOffset = 42
var $dropdown = $(dropdownHTML)
.appendTo('#qunit-fixture')
.find('[data-toggle="dropdown"]')
.bootstrapDropdown({
offset: myOffset
})
var dropdown = $dropdown.data('bs.dropdown')
var offset = dropdown._getOffset()
assert.strictEqual(offset.offset, myOffset)
assert.ok(typeof offset.fn === 'undefined')
})
})