mirror of
https://github.com/twbs/bootstrap.git
synced 2025-01-28 20:52:21 +01:00
v4 improve coverage (#25945)
* Improve code coverage for our Button plugin * improve coverage for our Alert plugin * test tooltip update method * test update and dispose for dropdown * increase code coverage requirements
This commit is contained in:
parent
875ed0b975
commit
0871d69ec9
@ -58,9 +58,11 @@ const Alert = (($) => {
|
||||
// Public
|
||||
|
||||
close(element) {
|
||||
element = element || this._element
|
||||
let rootElement = this._element
|
||||
if (element) {
|
||||
rootElement = this._getRootElement(element)
|
||||
}
|
||||
|
||||
const rootElement = this._getRootElement(element)
|
||||
const customEvent = this._triggerCloseEvent(rootElement)
|
||||
|
||||
if (customEvent.isDefaultPrevented()) {
|
||||
|
@ -60,10 +60,10 @@ module.exports = (config) => {
|
||||
thresholds: {
|
||||
emitWarning: false,
|
||||
global: {
|
||||
statements: 89,
|
||||
lines: 89,
|
||||
branches: 83,
|
||||
functions: 84
|
||||
statements: 90,
|
||||
branches: 84,
|
||||
functions: 87,
|
||||
lines: 90
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,9 @@
|
||||
"globals": {
|
||||
"bootstrap": false,
|
||||
"sinon": false,
|
||||
"Util": false
|
||||
"Util": false,
|
||||
"Alert": false,
|
||||
"Button": false
|
||||
},
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 5,
|
||||
|
@ -80,4 +80,43 @@ $(function () {
|
||||
})
|
||||
.bootstrapAlert('close')
|
||||
})
|
||||
|
||||
QUnit.test('close should use internal _element if no element provided', function (assert) {
|
||||
assert.expect(1)
|
||||
|
||||
var done = assert.async()
|
||||
var $el = $('<div/>')
|
||||
var $alert = $el.bootstrapAlert()
|
||||
var alertInstance = $alert.data('bs.alert')
|
||||
|
||||
$alert.one('closed.bs.alert', function () {
|
||||
assert.ok('alert closed')
|
||||
done()
|
||||
})
|
||||
|
||||
alertInstance.close()
|
||||
})
|
||||
|
||||
QUnit.test('dispose should remove data and the element', function (assert) {
|
||||
assert.expect(2)
|
||||
|
||||
var $el = $('<div/>')
|
||||
var $alert = $el.bootstrapAlert()
|
||||
|
||||
assert.ok(typeof $alert.data('bs.alert') !== 'undefined')
|
||||
|
||||
$alert.data('bs.alert').dispose()
|
||||
|
||||
assert.ok(typeof $alert.data('bs.button') === 'undefined')
|
||||
})
|
||||
|
||||
QUnit.test('should return alert version', function (assert) {
|
||||
assert.expect(1)
|
||||
|
||||
if (typeof Alert !== 'undefined') {
|
||||
assert.ok(typeof Alert.VERSION === 'string')
|
||||
} else {
|
||||
assert.notOk()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
@ -172,4 +172,27 @@ $(function () {
|
||||
assert.ok($btn.is(':not(.active)'), 'button did not become active')
|
||||
assert.ok(!$input.is(':checked'), 'checkbox did not get checked')
|
||||
})
|
||||
|
||||
QUnit.test('dispose should remove data and the element', function (assert) {
|
||||
assert.expect(2)
|
||||
|
||||
var $el = $('<div/>')
|
||||
var $button = $el.bootstrapButton()
|
||||
|
||||
assert.ok(typeof $button.data('bs.button') !== 'undefined')
|
||||
|
||||
$button.data('bs.button').dispose()
|
||||
|
||||
assert.ok(typeof $button.data('bs.button') === 'undefined')
|
||||
})
|
||||
|
||||
QUnit.test('should return button version', function (assert) {
|
||||
assert.expect(1)
|
||||
|
||||
if (typeof Button !== 'undefined') {
|
||||
assert.ok(typeof Button.VERSION === 'string')
|
||||
} else {
|
||||
assert.notOk()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
@ -940,4 +940,116 @@ $(function () {
|
||||
|
||||
$dropdown.trigger('click')
|
||||
})
|
||||
|
||||
QUnit.test('should call Popper.js and detect navbar on update', function (assert) {
|
||||
assert.expect(3)
|
||||
|
||||
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()
|
||||
|
||||
var dropdown = $dropdown.data('bs.dropdown')
|
||||
dropdown.toggle()
|
||||
assert.ok(dropdown._popper)
|
||||
|
||||
var spyPopper = sinon.spy(dropdown._popper, 'scheduleUpdate')
|
||||
var spyDetectNavbar = sinon.spy(dropdown, '_detectNavbar')
|
||||
dropdown.update()
|
||||
|
||||
assert.ok(spyPopper.called)
|
||||
assert.ok(spyDetectNavbar.called)
|
||||
})
|
||||
|
||||
QUnit.test('should just detect navbar on update', 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 $dropdown = $(dropdownHTML)
|
||||
.appendTo('#qunit-fixture')
|
||||
.find('[data-toggle="dropdown"]')
|
||||
.bootstrapDropdown()
|
||||
|
||||
var dropdown = $dropdown.data('bs.dropdown')
|
||||
var spyDetectNavbar = sinon.spy(dropdown, '_detectNavbar')
|
||||
|
||||
dropdown.update()
|
||||
|
||||
assert.notOk(dropdown._popper)
|
||||
assert.ok(spyDetectNavbar.called)
|
||||
})
|
||||
|
||||
QUnit.test('should dispose dropdown with Popper', function (assert) {
|
||||
assert.expect(6)
|
||||
|
||||
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()
|
||||
|
||||
var dropdown = $dropdown.data('bs.dropdown')
|
||||
dropdown.toggle()
|
||||
|
||||
assert.ok(dropdown._popper)
|
||||
assert.ok(dropdown._menu !== null)
|
||||
assert.ok(dropdown._element !== null)
|
||||
var spyDestroy = sinon.spy(dropdown._popper, 'destroy')
|
||||
|
||||
dropdown.dispose()
|
||||
|
||||
assert.ok(spyDestroy.called)
|
||||
assert.ok(dropdown._menu === null)
|
||||
assert.ok(dropdown._element === null)
|
||||
})
|
||||
|
||||
QUnit.test('should dispose dropdown', function (assert) {
|
||||
assert.expect(5)
|
||||
|
||||
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()
|
||||
|
||||
var dropdown = $dropdown.data('bs.dropdown')
|
||||
|
||||
assert.notOk(dropdown._popper)
|
||||
assert.ok(dropdown._menu !== null)
|
||||
assert.ok(dropdown._element !== null)
|
||||
|
||||
dropdown.dispose()
|
||||
|
||||
assert.ok(dropdown._menu === null)
|
||||
assert.ok(dropdown._element === null)
|
||||
})
|
||||
})
|
||||
|
@ -953,4 +953,33 @@ $(function () {
|
||||
$trigger.trigger($.Event('click'))
|
||||
}, 200)
|
||||
})
|
||||
|
||||
QUnit.test('should call Popper.js to update', function (assert) {
|
||||
assert.expect(2)
|
||||
|
||||
var $tooltip = $('<a href="#" rel="tooltip" data-trigger="click" title="Another tooltip"/>')
|
||||
.appendTo('#qunit-fixture')
|
||||
.bootstrapTooltip()
|
||||
|
||||
var tooltip = $tooltip.data('bs.tooltip')
|
||||
tooltip.show()
|
||||
assert.ok(tooltip._popper)
|
||||
|
||||
var spyPopper = sinon.spy(tooltip._popper, 'scheduleUpdate')
|
||||
tooltip.update()
|
||||
assert.ok(spyPopper.called)
|
||||
})
|
||||
|
||||
QUnit.test('should not call Popper.js to update', function (assert) {
|
||||
assert.expect(1)
|
||||
|
||||
var $tooltip = $('<a href="#" rel="tooltip" data-trigger="click" title="Another tooltip"/>')
|
||||
.appendTo('#qunit-fixture')
|
||||
.bootstrapTooltip()
|
||||
|
||||
var tooltip = $tooltip.data('bs.tooltip')
|
||||
tooltip.update()
|
||||
|
||||
assert.ok(tooltip._popper === null)
|
||||
})
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user