'
var $html = $(html)
$html
.appendTo('#qunit-fixture')
.bootstrapCarousel()
var $firstItem = $('#firstItem')
setTimeout(function () {
assert.ok($firstItem.hasClass('active'))
$html
.bootstrapCarousel('dispose')
.attr('style', 'visibility: hidden;')
.bootstrapCarousel()
setTimeout(function () {
assert.ok($firstItem.hasClass('active'))
done()
}, 80)
}, 80)
})
QUnit.test('Should not go to the next item when the parent of the carousel is not visible', function (assert) {
assert.expect(2)
var done = assert.async()
var html = '
' +
'
' +
'
' +
'
' +
'
![]()
' +
'
' +
'
' +
'
![]()
' +
'
' +
'
' +
'
![]()
' +
'
' +
'
‹' +
'
›' +
'
' +
'
'
var $html = $(html)
$html.appendTo('#qunit-fixture')
var $parent = $html.find('#parent')
var $carousel = $html.find('#myCarousel')
$carousel.bootstrapCarousel()
var $firstItem = $('#firstItem')
setTimeout(function () {
assert.ok($firstItem.hasClass('active'))
$carousel.bootstrapCarousel('dispose')
$parent.attr('style', 'visibility: hidden;')
$carousel.bootstrapCarousel()
setTimeout(function () {
assert.ok($firstItem.hasClass('active'))
done()
}, 80)
}, 80)
})
})
unit/button.js 0000666 00000016260 15016752676 0007424 0 ustar 00 $(function () {
'use strict'
QUnit.module('button plugin')
QUnit.test('should be defined on jquery object', function (assert) {
assert.expect(1)
assert.ok($(document.body).button, 'button method is defined')
})
QUnit.module('button', {
beforeEach: function () {
// Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode
$.fn.bootstrapButton = $.fn.button.noConflict()
},
afterEach: function () {
$.fn.button = $.fn.bootstrapButton
delete $.fn.bootstrapButton
}
})
QUnit.test('should provide no conflict', function (assert) {
assert.expect(1)
assert.strictEqual(typeof $.fn.button, 'undefined', 'button was set back to undefined (org value)')
})
QUnit.test('should return jquery collection containing the element', function (assert) {
assert.expect(2)
var $el = $('
')
var $button = $el.bootstrapButton()
assert.ok($button instanceof $, 'returns jquery collection')
assert.strictEqual($button[0], $el[0], 'collection contains element')
})
QUnit.test('should toggle active', function (assert) {
assert.expect(2)
var $btn = $('
')
assert.ok(!$btn.hasClass('active'), 'btn does not have active class')
$btn.bootstrapButton('toggle')
assert.ok($btn.hasClass('active'), 'btn has class active')
})
QUnit.test('should toggle active when btn children are clicked', function (assert) {
assert.expect(2)
var $btn = $('
')
var $inner = $('
')
$btn
.append($inner)
.appendTo('#qunit-fixture')
assert.ok(!$btn.hasClass('active'), 'btn does not have active class')
$inner.trigger('click')
assert.ok($btn.hasClass('active'), 'btn has class active')
})
QUnit.test('should toggle aria-pressed', function (assert) {
assert.expect(2)
var $btn = $('
')
assert.strictEqual($btn.attr('aria-pressed'), 'false', 'btn aria-pressed state is false')
$btn.bootstrapButton('toggle')
assert.strictEqual($btn.attr('aria-pressed'), 'true', 'btn aria-pressed state is true')
})
QUnit.test('should toggle aria-pressed on buttons with container', function (assert) {
assert.expect(1)
var groupHTML = '
' +
'' +
'' +
'
'
$('#qunit-fixture').append(groupHTML)
$('#btn1').bootstrapButton('toggle')
assert.strictEqual($('#btn1').attr('aria-pressed'), 'true')
})
QUnit.test('should toggle aria-pressed when btn children are clicked', function (assert) {
assert.expect(2)
var $btn = $('
')
var $inner = $('
')
$btn
.append($inner)
.appendTo('#qunit-fixture')
assert.strictEqual($btn.attr('aria-pressed'), 'false', 'btn aria-pressed state is false')
$inner.trigger('click')
assert.strictEqual($btn.attr('aria-pressed'), 'true', 'btn aria-pressed state is true')
})
QUnit.test('should trigger input change event when toggled button has input field', function (assert) {
assert.expect(1)
var done = assert.async()
var groupHTML = '
' +
'' +
'
'
var $group = $(groupHTML).appendTo('#qunit-fixture')
$group.find('input').on('change', function (e) {
e.preventDefault()
assert.ok(true, 'change event fired')
done()
})
$group.find('label').trigger('click')
})
QUnit.test('should check for closest matching toggle', function (assert) {
assert.expect(12)
var groupHTML = '
' +
'' +
'' +
'' +
'
'
var $group = $(groupHTML).appendTo('#qunit-fixture')
var $btn1 = $group.children().eq(0)
var $btn2 = $group.children().eq(1)
assert.ok($btn1.hasClass('active'), 'btn1 has active class')
assert.ok($btn1.find('input').prop('checked'), 'btn1 is checked')
assert.ok(!$btn2.hasClass('active'), 'btn2 does not have active class')
assert.ok(!$btn2.find('input').prop('checked'), 'btn2 is not checked')
$btn2.find('input').trigger('click')
assert.ok(!$btn1.hasClass('active'), 'btn1 does not have active class')
assert.ok(!$btn1.find('input').prop('checked'), 'btn1 is not checked')
assert.ok($btn2.hasClass('active'), 'btn2 has active class')
assert.ok($btn2.find('input').prop('checked'), 'btn2 is checked')
$btn2.find('input').trigger('click') // Clicking an already checked radio should not un-check it
assert.ok(!$btn1.hasClass('active'), 'btn1 does not have active class')
assert.ok(!$btn1.find('input').prop('checked'), 'btn1 is not checked')
assert.ok($btn2.hasClass('active'), 'btn2 has active class')
assert.ok($btn2.find('input').prop('checked'), 'btn2 is checked')
})
QUnit.test('should not add aria-pressed on labels for radio/checkbox inputs in a data-toggle="buttons" group', function (assert) {
assert.expect(2)
var groupHTML = '
' +
'' +
'' +
'
'
var $group = $(groupHTML).appendTo('#qunit-fixture')
var $btn1 = $group.children().eq(0)
var $btn2 = $group.children().eq(1)
$btn1.find('input').trigger('click')
assert.ok($btn1.is(':not([aria-pressed])'), 'label for nested checkbox input has not been given an aria-pressed attribute')
$btn2.find('input').trigger('click')
assert.ok($btn2.is(':not([aria-pressed])'), 'label for nested radio input has not been given an aria-pressed attribute')
})
QUnit.test('should handle disabled attribute on non-button elements', function (assert) {
assert.expect(2)
var groupHTML = '
' +
'' +
'
'
var $group = $(groupHTML).appendTo('#qunit-fixture')
var $btn = $group.children().eq(0)
var $input = $btn.children().eq(0)
$btn.trigger('click')
assert.ok($btn.is(':not(.active)'), 'button did not become active')
assert.ok(!$input.is(':checked'), 'checkbox did not get checked')
})
})
unit/collapse.js 0000666 00000102411 15016752676 0007705 0 ustar 00 $(function () {
'use strict'
QUnit.module('collapse plugin')
QUnit.test('should be defined on jquery object', function (assert) {
assert.expect(1)
assert.ok($(document.body).collapse, 'collapse method is defined')
})
QUnit.module('collapse', {
beforeEach: function () {
// Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode
$.fn.bootstrapCollapse = $.fn.collapse.noConflict()
},
afterEach: function () {
$.fn.collapse = $.fn.bootstrapCollapse
delete $.fn.bootstrapCollapse
}
})
QUnit.test('should provide no conflict', function (assert) {
assert.expect(1)
assert.strictEqual(typeof $.fn.collapse, 'undefined', 'collapse was set back to undefined (org value)')
})
QUnit.test('should throw explicit error on undefined method', function (assert) {
assert.expect(1)
var $el = $('
')
$el.bootstrapCollapse()
try {
$el.bootstrapCollapse('noMethod')
} catch (err) {
assert.strictEqual(err.message, 'No method named "noMethod"')
}
})
QUnit.test('should return jquery collection containing the element', function (assert) {
assert.expect(2)
var $el = $('
')
var $collapse = $el.bootstrapCollapse()
assert.ok($collapse instanceof $, 'returns jquery collection')
assert.strictEqual($collapse[0], $el[0], 'collection contains element')
})
QUnit.test('should show a collapsed element', function (assert) {
assert.expect(2)
var $el = $('
').bootstrapCollapse('show')
assert.ok($el.hasClass('show'), 'has class "show"')
assert.ok(!/height/i.test($el.attr('style')), 'has height reset')
})
QUnit.test('should show multiple collapsed elements', function (assert) {
assert.expect(4)
var done = assert.async()
var $target = $('
').appendTo('#qunit-fixture')
var $el = $('
').appendTo('#qunit-fixture')
var $el2 = $('
').appendTo('#qunit-fixture')
$el.one('shown.bs.collapse', function () {
assert.ok($el.hasClass('show'), 'has class "show"')
assert.ok(!/height/i.test($el.attr('style')), 'has height reset')
})
$el2.one('shown.bs.collapse', function () {
assert.ok($el2.hasClass('show'), 'has class "show"')
assert.ok(!/height/i.test($el2.attr('style')), 'has height reset')
done()
})
$target.trigger('click')
})
QUnit.test('should collapse only the first collapse', function (assert) {
assert.expect(2)
var done = assert.async()
var html = [
'
',
'
'
].join('')
$(html).appendTo('#qunit-fixture')
var $el1 = $('#collapse1')
var $el2 = $('#collapse2')
$el1.one('shown.bs.collapse', function () {
assert.ok($el1.hasClass('show'))
assert.ok($el2.hasClass('show'))
done()
}).bootstrapCollapse('show')
})
QUnit.test('should hide a collapsed element', function (assert) {
assert.expect(1)
var $el = $('
').bootstrapCollapse('hide')
assert.ok(!$el.hasClass('show'), 'does not have class "show"')
})
QUnit.test('should not fire shown when show is prevented', function (assert) {
assert.expect(1)
var done = assert.async()
$('
')
.on('show.bs.collapse', function (e) {
e.preventDefault()
assert.ok(true, 'show event fired')
done()
})
.on('shown.bs.collapse', function () {
assert.ok(false, 'shown event fired')
})
.bootstrapCollapse('show')
})
QUnit.test('should reset style to auto after finishing opening collapse', function (assert) {
assert.expect(2)
var done = assert.async()
$('
')
.on('show.bs.collapse', function () {
assert.strictEqual(this.style.height, '0px', 'height is 0px')
})
.on('shown.bs.collapse', function () {
assert.strictEqual(this.style.height, '', 'height is auto')
done()
})
.bootstrapCollapse('show')
})
QUnit.test('should reset style to auto after finishing closing collapse', function (assert) {
assert.expect(1)
var done = assert.async()
$('
')
.on('shown.bs.collapse', function () {
$(this).bootstrapCollapse('hide')
})
.on('hidden.bs.collapse', function () {
assert.strictEqual(this.style.height, '', 'height is auto')
done()
})
.bootstrapCollapse('show')
})
QUnit.test('should remove "collapsed" class from target when collapse is shown', function (assert) {
assert.expect(1)
var done = assert.async()
var $target = $('
').appendTo('#qunit-fixture')
$('
')
.appendTo('#qunit-fixture')
.on('shown.bs.collapse', function () {
assert.ok(!$target.hasClass('collapsed'), 'target does not have collapsed class')
done()
})
$target.trigger('click')
})
QUnit.test('should add "collapsed" class to target when collapse is hidden', function (assert) {
assert.expect(1)
var done = assert.async()
var $target = $('
').appendTo('#qunit-fixture')
$('
')
.appendTo('#qunit-fixture')
.on('hidden.bs.collapse', function () {
assert.ok($target.hasClass('collapsed'), 'target has collapsed class')
done()
})
$target.trigger('click')
})
QUnit.test('should remove "collapsed" class from all triggers targeting the collapse when the collapse is shown', function (assert) {
assert.expect(2)
var done = assert.async()
var $target = $('
').appendTo('#qunit-fixture')
var $alt = $('
').appendTo('#qunit-fixture')
$('
')
.appendTo('#qunit-fixture')
.on('shown.bs.collapse', function () {
assert.ok(!$target.hasClass('collapsed'), 'target trigger does not have collapsed class')
assert.ok(!$alt.hasClass('collapsed'), 'alt trigger does not have collapsed class')
done()
})
$target.trigger('click')
})
QUnit.test('should add "collapsed" class to all triggers targeting the collapse when the collapse is hidden', function (assert) {
assert.expect(2)
var done = assert.async()
var $target = $('
').appendTo('#qunit-fixture')
var $alt = $('
').appendTo('#qunit-fixture')
$('
')
.appendTo('#qunit-fixture')
.on('hidden.bs.collapse', function () {
assert.ok($target.hasClass('collapsed'), 'target has collapsed class')
assert.ok($alt.hasClass('collapsed'), 'alt trigger has collapsed class')
done()
})
$target.trigger('click')
})
QUnit.test('should not close a collapse when initialized with "show" option if already shown', function (assert) {
assert.expect(0)
var done = assert.async()
var $test = $('
')
.appendTo('#qunit-fixture')
.on('hide.bs.collapse', function () {
assert.ok(false)
})
$test.bootstrapCollapse('show')
setTimeout(done, 0)
})
QUnit.test('should open a collapse when initialized with "show" option if not already shown', function (assert) {
assert.expect(1)
var done = assert.async()
var $test = $('
')
.appendTo('#qunit-fixture')
.on('show.bs.collapse', function () {
assert.ok(true)
})
$test.bootstrapCollapse('show')
setTimeout(done, 0)
})
QUnit.test('should not show a collapse when initialized with "hide" option if already hidden', function (assert) {
assert.expect(0)
var done = assert.async()
$('
')
.appendTo('#qunit-fixture')
.on('show.bs.collapse', function () {
assert.ok(false, 'showing a previously-uninitialized hidden collapse when the "hide" method is called')
})
.bootstrapCollapse('hide')
setTimeout(done, 0)
})
QUnit.test('should hide a collapse when initialized with "hide" option if not already hidden', function (assert) {
assert.expect(1)
var done = assert.async()
$('
')
.appendTo('#qunit-fixture')
.on('hide.bs.collapse', function () {
assert.ok(true, 'hiding a previously-uninitialized shown collapse when the "hide" method is called')
})
.bootstrapCollapse('hide')
setTimeout(done, 0)
})
QUnit.test('should remove "collapsed" class from active accordion target', function (assert) {
assert.expect(3)
var done = assert.async()
var accordionHTML = '
'
var $groups = $(accordionHTML).appendTo('#qunit-fixture').find('.card')
var $target1 = $('
').appendTo($groups.eq(0))
$('
').appendTo($groups.eq(0))
var $target2 = $('
').appendTo($groups.eq(1))
$('
').appendTo($groups.eq(1))
var $target3 = $('
').appendTo($groups.eq(2))
$('
')
.appendTo($groups.eq(2))
.on('shown.bs.collapse', function () {
assert.ok($target1.hasClass('collapsed'), 'inactive target 1 does have class "collapsed"')
assert.ok($target2.hasClass('collapsed'), 'inactive target 2 does have class "collapsed"')
assert.ok(!$target3.hasClass('collapsed'), 'active target 3 does not have class "collapsed"')
done()
})
$target3.trigger('click')
})
QUnit.test('should allow dots in data-parent', function (assert) {
assert.expect(3)
var done = assert.async()
var accordionHTML = '
'
var $groups = $(accordionHTML).appendTo('#qunit-fixture').find('.card')
var $target1 = $('
').appendTo($groups.eq(0))
$('
').appendTo($groups.eq(0))
var $target2 = $('
').appendTo($groups.eq(1))
$('
').appendTo($groups.eq(1))
var $target3 = $('
').appendTo($groups.eq(2))
$('
')
.appendTo($groups.eq(2))
.on('shown.bs.collapse', function () {
assert.ok($target1.hasClass('collapsed'), 'inactive target 1 does have class "collapsed"')
assert.ok($target2.hasClass('collapsed'), 'inactive target 2 does have class "collapsed"')
assert.ok(!$target3.hasClass('collapsed'), 'active target 3 does not have class "collapsed"')
done()
})
$target3.trigger('click')
})
QUnit.test('should set aria-expanded="true" on trigger/control when collapse is shown', function (assert) {
assert.expect(1)
var done = assert.async()
var $target = $('
').appendTo('#qunit-fixture')
$('
')
.appendTo('#qunit-fixture')
.on('shown.bs.collapse', function () {
assert.strictEqual($target.attr('aria-expanded'), 'true', 'aria-expanded on target is "true"')
done()
})
$target.trigger('click')
})
QUnit.test('should set aria-expanded="false" on trigger/control when collapse is hidden', function (assert) {
assert.expect(1)
var done = assert.async()
var $target = $('
').appendTo('#qunit-fixture')
$('
')
.appendTo('#qunit-fixture')
.on('hidden.bs.collapse', function () {
assert.strictEqual($target.attr('aria-expanded'), 'false', 'aria-expanded on target is "false"')
done()
})
$target.trigger('click')
})
QUnit.test('should set aria-expanded="true" on all triggers targeting the collapse when the collapse is shown', function (assert) {
assert.expect(2)
var done = assert.async()
var $target = $('
').appendTo('#qunit-fixture')
var $alt = $('
').appendTo('#qunit-fixture')
$('
')
.appendTo('#qunit-fixture')
.on('shown.bs.collapse', function () {
assert.strictEqual($target.attr('aria-expanded'), 'true', 'aria-expanded on trigger/control is "true"')
assert.strictEqual($alt.attr('aria-expanded'), 'true', 'aria-expanded on alternative trigger/control is "true"')
done()
})
$target.trigger('click')
})
QUnit.test('should set aria-expanded="false" on all triggers targeting the collapse when the collapse is hidden', function (assert) {
assert.expect(2)
var done = assert.async()
var $target = $('
').appendTo('#qunit-fixture')
var $alt = $('
').appendTo('#qunit-fixture')
$('
')
.appendTo('#qunit-fixture')
.on('hidden.bs.collapse', function () {
assert.strictEqual($target.attr('aria-expanded'), 'false', 'aria-expanded on trigger/control is "false"')
assert.strictEqual($alt.attr('aria-expanded'), 'false', 'aria-expanded on alternative trigger/control is "false"')
done()
})
$target.trigger('click')
})
QUnit.test('should change aria-expanded from active accordion trigger/control to "false" and set the trigger/control for the newly active one to "true"', function (assert) {
assert.expect(3)
var done = assert.async()
var accordionHTML = '
'
var $groups = $(accordionHTML).appendTo('#qunit-fixture').find('.card')
var $target1 = $('
').appendTo($groups.eq(0))
$('
').appendTo($groups.eq(0))
var $target2 = $('
').appendTo($groups.eq(1))
$('
').appendTo($groups.eq(1))
var $target3 = $('
').appendTo($groups.eq(2))
$('
')
.appendTo($groups.eq(2))
.on('shown.bs.collapse', function () {
assert.strictEqual($target1.attr('aria-expanded'), 'false', 'inactive trigger/control 1 has aria-expanded="false"')
assert.strictEqual($target2.attr('aria-expanded'), 'false', 'inactive trigger/control 2 has aria-expanded="false"')
assert.strictEqual($target3.attr('aria-expanded'), 'true', 'active trigger/control 3 has aria-expanded="true"')
done()
})
$target3.trigger('click')
})
QUnit.test('should not fire show event if show is prevented because other element is still transitioning', function (assert) {
assert.expect(1)
var done = assert.async()
var accordionHTML = '
'
var showFired = false
var $groups = $(accordionHTML).appendTo('#qunit-fixture').find('.card')
var $target1 = $('
').appendTo($groups.eq(0))
$('
')
.appendTo($groups.eq(0))
.on('show.bs.collapse', function () {
showFired = true
})
var $target2 = $('
').appendTo($groups.eq(1))
var $body2 = $('
').appendTo($groups.eq(1))
$target2.trigger('click')
$body2
.toggleClass('show collapsing')
.data('bs.collapse')._isTransitioning = 1
$target1.trigger('click')
setTimeout(function () {
assert.ok(!showFired, 'show event did not fire')
done()
}, 1)
})
QUnit.test('should add "collapsed" class to target when collapse is hidden via manual invocation', function (assert) {
assert.expect(1)
var done = assert.async()
var $target = $('
').appendTo('#qunit-fixture')
$('
')
.appendTo('#qunit-fixture')
.on('hidden.bs.collapse', function () {
assert.ok($target.hasClass('collapsed'))
done()
})
.bootstrapCollapse('hide')
})
QUnit.test('should remove "collapsed" class from target when collapse is shown via manual invocation', function (assert) {
assert.expect(1)
var done = assert.async()
var $target = $('
').appendTo('#qunit-fixture')
$('
')
.appendTo('#qunit-fixture')
.on('shown.bs.collapse', function () {
assert.ok(!$target.hasClass('collapsed'))
done()
})
.bootstrapCollapse('show')
})
QUnit.test('should allow accordion to use children other than card', function (assert) {
assert.expect(4)
var done = assert.async()
var accordionHTML = '
'
$(accordionHTML).appendTo('#qunit-fixture')
var $trigger = $('#linkTrigger')
var $triggerTwo = $('#linkTriggerTwo')
var $collapseOne = $('#collapseOne')
var $collapseTwo = $('#collapseTwo')
$collapseOne.on('shown.bs.collapse', function () {
assert.ok($collapseOne.hasClass('show'), '#collapseOne is shown')
assert.ok(!$collapseTwo.hasClass('show'), '#collapseTwo is not shown')
$collapseTwo.on('shown.bs.collapse', function () {
assert.ok(!$collapseOne.hasClass('show'), '#collapseOne is not shown')
assert.ok($collapseTwo.hasClass('show'), '#collapseTwo is shown')
done()
})
$triggerTwo.trigger($.Event('click'))
})
$trigger.trigger($.Event('click'))
})
QUnit.test('should allow accordion to contain nested elements', function (assert) {
assert.expect(4)
var done = assert.async()
var accordionHTML = '
'
$(accordionHTML).appendTo('#qunit-fixture')
var $trigger = $('#linkTrigger')
var $triggerTwo = $('#linkTriggerTwo')
var $collapseOne = $('#collapseOne')
var $collapseTwo = $('#collapseTwo')
$collapseOne.on('shown.bs.collapse', function () {
assert.ok($collapseOne.hasClass('show'), '#collapseOne is shown')
assert.ok(!$collapseTwo.hasClass('show'), '#collapseTwo is not shown')
$collapseTwo.on('shown.bs.collapse', function () {
assert.ok(!$collapseOne.hasClass('show'), '#collapseOne is not shown')
assert.ok($collapseTwo.hasClass('show'), '#collapseTwo is shown')
done()
})
$triggerTwo.trigger($.Event('click'))
})
$trigger.trigger($.Event('click'))
})
QUnit.test('should allow accordion to target multiple elements', function (assert) {
assert.expect(8)
var done = assert.async()
var accordionHTML = '
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
'
$(accordionHTML).appendTo('#qunit-fixture')
var $trigger = $('#linkTriggerOne')
var $triggerTwo = $('#linkTriggerTwo')
var $collapseOneOne = $('#collapseOneOne')
var $collapseOneTwo = $('#collapseOneTwo')
var $collapseTwoOne = $('#collapseTwoOne')
var $collapseTwoTwo = $('#collapseTwoTwo')
var collapsedElements = {
one : false,
two : false
}
function firstTest() {
assert.ok($collapseOneOne.hasClass('show'), '#collapseOneOne is shown')
assert.ok($collapseOneTwo.hasClass('show'), '#collapseOneTwo is shown')
assert.ok(!$collapseTwoOne.hasClass('show'), '#collapseTwoOne is not shown')
assert.ok(!$collapseTwoTwo.hasClass('show'), '#collapseTwoTwo is not shown')
$triggerTwo.trigger($.Event('click'))
}
function secondTest() {
assert.ok(!$collapseOneOne.hasClass('show'), '#collapseOneOne is not shown')
assert.ok(!$collapseOneTwo.hasClass('show'), '#collapseOneTwo is not shown')
assert.ok($collapseTwoOne.hasClass('show'), '#collapseTwoOne is shown')
assert.ok($collapseTwoTwo.hasClass('show'), '#collapseTwoTwo is shown')
done()
}
$collapseOneOne.on('shown.bs.collapse', function () {
if (collapsedElements.one) {
firstTest()
} else {
collapsedElements.one = true
}
})
$collapseOneTwo.on('shown.bs.collapse', function () {
if (collapsedElements.one) {
firstTest()
} else {
collapsedElements.one = true
}
})
$collapseTwoOne.on('shown.bs.collapse', function () {
if (collapsedElements.two) {
secondTest()
} else {
collapsedElements.two = true
}
})
$collapseTwoTwo.on('shown.bs.collapse', function () {
if (collapsedElements.two) {
secondTest()
} else {
collapsedElements.two = true
}
})
$trigger.trigger($.Event('click'))
})
QUnit.test('should collapse accordion children but not nested accordion children', function (assert) {
assert.expect(9)
var done = assert.async()
$('
').appendTo('#qunit-fixture')
var $trigger = $('#linkTrigger')
var $triggerTwo = $('#linkTriggerTwo')
var $nestedTrigger = $('#nestedLinkTrigger')
var $collapseOne = $('#collapseOne')
var $collapseTwo = $('#collapseTwo')
var $nestedCollapseOne = $('#nestedCollapseOne')
$collapseOne.one('shown.bs.collapse', function () {
assert.ok($collapseOne.hasClass('show'), '#collapseOne is shown')
assert.ok(!$collapseTwo.hasClass('show'), '#collapseTwo is not shown')
assert.ok(!$('#nestedCollapseOne').hasClass('show'), '#nestedCollapseOne is not shown')
$nestedCollapseOne.one('shown.bs.collapse', function () {
assert.ok($collapseOne.hasClass('show'), '#collapseOne is shown')
assert.ok(!$collapseTwo.hasClass('show'), '#collapseTwo is not shown')
assert.ok($nestedCollapseOne.hasClass('show'), '#nestedCollapseOne is shown')
$collapseTwo.one('shown.bs.collapse', function () {
assert.ok(!$collapseOne.hasClass('show'), '#collapseOne is not shown')
assert.ok($collapseTwo.hasClass('show'), '#collapseTwo is shown')
assert.ok($nestedCollapseOne.hasClass('show'), '#nestedCollapseOne is shown')
done()
})
$triggerTwo.trigger($.Event('click'))
})
$nestedTrigger.trigger($.Event('click'))
})
$trigger.trigger($.Event('click'))
})
QUnit.test('should not prevent event for input', function (assert) {
assert.expect(3)
var done = assert.async()
var $target = $('
').appendTo('#qunit-fixture')
$('
')
.appendTo('#qunit-fixture')
.on('shown.bs.collapse', function () {
assert.ok($(this).hasClass('show'))
assert.ok($target.attr('aria-expanded') === 'true')
assert.ok($target.prop('checked'))
done()
})
$target.trigger($.Event('click'))
})
QUnit.test('should add "collapsed" class to triggers only when all the targeted collapse are hidden', function (assert) {
assert.expect(9)
var done = assert.async()
var $trigger1 = $('
').appendTo('#qunit-fixture')
var $trigger2 = $('
').appendTo('#qunit-fixture')
var $trigger3 = $('
').appendTo('#qunit-fixture')
var $target1 = $('
').appendTo('#qunit-fixture')
var $target2 = $('
').appendTo('#qunit-fixture')
$target2.one('shown.bs.collapse', function () {
assert.ok(!$trigger1.hasClass('collapsed'), 'trigger1 does not have collapsed class')
assert.ok(!$trigger2.hasClass('collapsed'), 'trigger2 does not have collapsed class')
assert.ok(!$trigger3.hasClass('collapsed'), 'trigger3 does not have collapsed class')
$target2.one('hidden.bs.collapse', function () {
assert.ok(!$trigger1.hasClass('collapsed'), 'trigger1 does not have collapsed class')
assert.ok($trigger2.hasClass('collapsed'), 'trigger2 has collapsed class')
assert.ok(!$trigger3.hasClass('collapsed'), 'trigger3 does not have collapsed class')
$target1.one('hidden.bs.collapse', function () {
assert.ok($trigger1.hasClass('collapsed'), 'trigger1 has collapsed class')
assert.ok($trigger2.hasClass('collapsed'), 'trigger2 has collapsed class')
assert.ok($trigger3.hasClass('collapsed'), 'trigger3 has collapsed class')
done()
})
$trigger1.trigger('click')
})
$trigger2.trigger('click')
})
$trigger3.trigger('click')
})
QUnit.test('should set aria-expanded="true" to triggers targeting shown collaspe and aria-expanded="false" only when all the targeted collapses are shown', function (assert) {
assert.expect(9)
var done = assert.async()
var $trigger1 = $('
').appendTo('#qunit-fixture')
var $trigger2 = $('
').appendTo('#qunit-fixture')
var $trigger3 = $('
').appendTo('#qunit-fixture')
var $target1 = $('
').appendTo('#qunit-fixture')
var $target2 = $('
').appendTo('#qunit-fixture')
$target2.one('shown.bs.collapse', function () {
assert.strictEqual($trigger1.attr('aria-expanded'), 'true', 'aria-expanded on trigger1 is "true"')
assert.strictEqual($trigger2.attr('aria-expanded'), 'true', 'aria-expanded on trigger2 is "true"')
assert.strictEqual($trigger3.attr('aria-expanded'), 'true', 'aria-expanded on trigger3 is "true"')
$target2.one('hidden.bs.collapse', function () {
assert.strictEqual($trigger1.attr('aria-expanded'), 'true', 'aria-expanded on trigger1 is "true"')
assert.strictEqual($trigger2.attr('aria-expanded'), 'false', 'aria-expanded on trigger2 is "false"')
assert.strictEqual($trigger3.attr('aria-expanded'), 'true', 'aria-expanded on trigger3 is "true"')
$target1.one('hidden.bs.collapse', function () {
assert.strictEqual($trigger1.attr('aria-expanded'), 'false', 'aria-expanded on trigger1 is "fasle"')
assert.strictEqual($trigger2.attr('aria-expanded'), 'false', 'aria-expanded on trigger2 is "false"')
assert.strictEqual($trigger3.attr('aria-expanded'), 'false', 'aria-expanded on trigger3 is "false"')
done()
})
$trigger1.trigger('click')
})
$trigger2.trigger('click')
})
$trigger3.trigger('click')
})
QUnit.test('should not prevent interactions inside the collapse element', function (assert) {
assert.expect(2)
var done = assert.async()
var $target = $('
').appendTo('#qunit-fixture')
var htmlCollapse =
'
' +
' ' +
'
'
$(htmlCollapse)
.appendTo('#qunit-fixture')
.on('shown.bs.collapse', function () {
assert.ok($target.prop('checked'), '$trigger is checked')
var $testCheckbox = $('#testCheckbox')
$testCheckbox.trigger($.Event('click'))
setTimeout(function () {
assert.ok($testCheckbox.prop('checked'), '$testCheckbox is checked too')
done()
}, 5)
})
$target.trigger($.Event('click'))
})
QUnit.test('should allow jquery object in parent config', function (assert) {
assert.expect(1)
var html =
'
'
$(html).appendTo('#qunit-fixture')
try {
$('[data-toggle="collapse"]').bootstrapCollapse({
parent: $('.my-collapse')
})
assert.ok(true, 'collapse correctly created')
} catch (err) {
assert.ok(false, 'collapse not created')
}
})
QUnit.test('should allow DOM object in parent config', function (assert) {
assert.expect(1)
var html =
'
'
$(html).appendTo('#qunit-fixture')
try {
$('[data-toggle="collapse"]').bootstrapCollapse({
parent: $('.my-collapse')[0]
})
assert.ok(true, 'collapse correctly created')
} catch (err) {
assert.ok(false, 'collapse not created')
}
})
})
unit/popover.js 0000666 00000037664 15016752676 0007616 0 ustar 00 $(function () {
'use strict'
QUnit.module('popover plugin')
QUnit.test('should be defined on jquery object', function (assert) {
assert.expect(1)
assert.ok($(document.body).popover, 'popover method is defined')
})
QUnit.module('popover', {
beforeEach: function () {
// Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode
$.fn.bootstrapPopover = $.fn.popover.noConflict()
},
afterEach: function () {
$.fn.popover = $.fn.bootstrapPopover
delete $.fn.bootstrapPopover
$('.popover').remove()
}
})
QUnit.test('should provide no conflict', function (assert) {
assert.expect(1)
assert.strictEqual(typeof $.fn.popover, 'undefined', 'popover was set back to undefined (org value)')
})
QUnit.test('should throw explicit error on undefined method', function (assert) {
assert.expect(1)
var $el = $('
')
$el.bootstrapPopover()
try {
$el.bootstrapPopover('noMethod')
} catch (err) {
assert.strictEqual(err.message, 'No method named "noMethod"')
}
})
QUnit.test('should return jquery collection containing the element', function (assert) {
assert.expect(2)
var $el = $('
')
var $popover = $el.bootstrapPopover()
assert.ok($popover instanceof $, 'returns jquery collection')
assert.strictEqual($popover[0], $el[0], 'collection contains element')
})
QUnit.test('should render popover element', function (assert) {
assert.expect(2)
var done = assert.async()
$('
@mdo')
.appendTo('#qunit-fixture')
.on('shown.bs.popover', function () {
assert.notEqual($('.popover').length, 0, 'popover was inserted')
$(this).bootstrapPopover('hide')
})
.on('hidden.bs.popover', function () {
assert.strictEqual($('.popover').length, 0, 'popover removed')
done()
})
.bootstrapPopover('show')
})
QUnit.test('should store popover instance in popover data object', function (assert) {
assert.expect(1)
var $popover = $('
@mdo').bootstrapPopover()
assert.ok($popover.data('bs.popover'), 'popover instance exists')
})
QUnit.test('should store popover trigger in popover instance data object', function (assert) {
assert.expect(1)
var $popover = $('
@ResentedHook')
.appendTo('#qunit-fixture')
.bootstrapPopover()
$popover.bootstrapPopover('show')
assert.ok($('.popover').data('bs.popover'), 'popover trigger stored in instance data')
})
QUnit.test('should get title and content from options', function (assert) {
assert.expect(4)
var $popover = $('
@fat')
.appendTo('#qunit-fixture')
.bootstrapPopover({
title: function () {
return '@fat'
},
content: function () {
return 'loves writing tests (╯°□°)╯︵ ┻━┻'
}
})
$popover.bootstrapPopover('show')
assert.notEqual($('.popover').length, 0, 'popover was inserted')
assert.strictEqual($('.popover .popover-header').text(), '@fat', 'title correctly inserted')
assert.strictEqual($('.popover .popover-body').text(), 'loves writing tests (╯°□°)╯︵ ┻━┻', 'content correctly inserted')
$popover.bootstrapPopover('hide')
assert.strictEqual($('.popover').length, 0, 'popover was removed')
})
QUnit.test('should allow DOMElement title and content (html: true)', function (assert) {
assert.expect(5)
var title = document.createTextNode('@glebm <3 writing tests')
var content = $('
¯\\_(ツ)_/¯').get(0)
var $popover = $('
')
.appendTo('#qunit-fixture')
.bootstrapPopover({
html: true,
title: title,
content: content
})
$popover.bootstrapPopover('show')
assert.notEqual($('.popover').length, 0, 'popover inserted')
assert.strictEqual($('.popover .popover-header').text(), '@glebm <3 writing tests', 'title inserted')
assert.ok($.contains($('.popover').get(0), title), 'title node moved, not copied')
// toLowerCase because IE8 will return
...
assert.strictEqual($('.popover .popover-body').html().toLowerCase(), '
¯\\_(ツ)_/¯', 'content inserted')
assert.ok($.contains($('.popover').get(0), content), 'content node moved, not copied')
})
QUnit.test('should allow DOMElement title and content (html: false)', function (assert) {
assert.expect(5)
var title = document.createTextNode('@glebm <3 writing tests')
var content = $('
¯\\_(ツ)_/¯').get(0)
var $popover = $('
')
.appendTo('#qunit-fixture')
.bootstrapPopover({
title: title,
content: content
})
$popover.bootstrapPopover('show')
assert.notEqual($('.popover').length, 0, 'popover inserted')
assert.strictEqual($('.popover .popover-header').text(), '@glebm <3 writing tests', 'title inserted')
assert.ok(!$.contains($('.popover').get(0), title), 'title node copied, not moved')
assert.strictEqual($('.popover .popover-body').html(), '¯\\_(ツ)_/¯', 'content inserted')
assert.ok(!$.contains($('.popover').get(0), content), 'content node copied, not moved')
})
QUnit.test('should not duplicate HTML object', function (assert) {
assert.expect(6)
var $div = $('
').html('loves writing tests (╯°□°)╯︵ ┻━┻')
var $popover = $('
@fat')
.appendTo('#qunit-fixture')
.bootstrapPopover({
html: true,
content: function () {
return $div
}
})
$popover.bootstrapPopover('show')
assert.notEqual($('.popover').length, 0, 'popover was inserted')
assert.equal($('.popover .popover-body').html(), $div[0].outerHTML, 'content correctly inserted')
$popover.bootstrapPopover('hide')
assert.strictEqual($('.popover').length, 0, 'popover was removed')
$popover.bootstrapPopover('show')
assert.notEqual($('.popover').length, 0, 'popover was inserted')
assert.equal($('.popover .popover-body').html(), $div[0].outerHTML, 'content correctly inserted')
$popover.bootstrapPopover('hide')
assert.strictEqual($('.popover').length, 0, 'popover was removed')
})
QUnit.test('should get title and content from attributes', function (assert) {
assert.expect(4)
var $popover = $('
@mdo')
.appendTo('#qunit-fixture')
.bootstrapPopover()
.bootstrapPopover('show')
assert.notEqual($('.popover').length, 0, 'popover was inserted')
assert.strictEqual($('.popover .popover-header').text(), '@mdo', 'title correctly inserted')
assert.strictEqual($('.popover .popover-body').text(), 'loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻', 'content correctly inserted')
$popover.bootstrapPopover('hide')
assert.strictEqual($('.popover').length, 0, 'popover was removed')
})
QUnit.test('should get title and content from attributes ignoring options passed via js', function (assert) {
assert.expect(4)
var $popover = $('
@mdo')
.appendTo('#qunit-fixture')
.bootstrapPopover({
title: 'ignored title option',
content: 'ignored content option'
})
.bootstrapPopover('show')
assert.notEqual($('.popover').length, 0, 'popover was inserted')
assert.strictEqual($('.popover .popover-header').text(), '@mdo', 'title correctly inserted')
assert.strictEqual($('.popover .popover-body').text(), 'loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻', 'content correctly inserted')
$popover.bootstrapPopover('hide')
assert.strictEqual($('.popover').length, 0, 'popover was removed')
})
QUnit.test('should respect custom template', function (assert) {
assert.expect(3)
var $popover = $('
@fat')
.appendTo('#qunit-fixture')
.bootstrapPopover({
title: 'Test',
content: 'Test',
template: '
'
})
$popover.bootstrapPopover('show')
assert.notEqual($('.popover').length, 0, 'popover was inserted')
assert.ok($('.popover').hasClass('foobar'), 'custom class is present')
$popover.bootstrapPopover('hide')
assert.strictEqual($('.popover').length, 0, 'popover was removed')
})
QUnit.test('should destroy popover', function (assert) {
assert.expect(7)
var $popover = $('
')
.bootstrapPopover({
trigger: 'hover'
})
.on('click.foo', $.noop)
assert.ok($popover.data('bs.popover'), 'popover has data')
assert.ok($._data($popover[0], 'events').mouseover && $._data($popover[0], 'events').mouseout, 'popover has hover event')
assert.strictEqual($._data($popover[0], 'events').click[0].namespace, 'foo', 'popover has extra click.foo event')
$popover.bootstrapPopover('show')
$popover.bootstrapPopover('dispose')
assert.ok(!$popover.hasClass('show'), 'popover is hidden')
assert.ok(!$popover.data('popover'), 'popover does not have data')
assert.strictEqual($._data($popover[0], 'events').click[0].namespace, 'foo', 'popover still has click.foo')
assert.ok(!$._data($popover[0], 'events').mouseover && !$._data($popover[0], 'events').mouseout, 'popover does not have any events')
})
QUnit.test('should render popover element using delegated selector', function (assert) {
assert.expect(2)
var $div = $('
')
.appendTo('#qunit-fixture')
.bootstrapPopover({
selector: 'a',
trigger: 'click'
})
$div.find('a').trigger('click')
assert.notEqual($('.popover').length, 0, 'popover was inserted')
$div.find('a').trigger('click')
assert.strictEqual($('.popover').length, 0, 'popover was removed')
})
QUnit.test('should detach popover content rather than removing it so that event handlers are left intact', function (assert) {
assert.expect(1)
var $content = $('
').appendTo('#qunit-fixture')
var handlerCalled = false
$('.content-with-handler .btn').on('click', function () {
handlerCalled = true
})
var $div = $('
')
.appendTo('#qunit-fixture')
.bootstrapPopover({
html: true,
trigger: 'manual',
container: 'body',
content: function () {
return $content
}
})
var done = assert.async()
$div
.one('shown.bs.popover', function () {
$div
.one('hidden.bs.popover', function () {
$div
.one('shown.bs.popover', function () {
$('.content-with-handler .btn').trigger('click')
$div.bootstrapPopover('dispose')
assert.ok(handlerCalled, 'content\'s event handler still present')
done()
})
.bootstrapPopover('show')
})
.bootstrapPopover('hide')
})
.bootstrapPopover('show')
})
QUnit.test('should do nothing when an attempt is made to hide an uninitialized popover', function (assert) {
assert.expect(1)
var $popover = $('
some text')
.appendTo('#qunit-fixture')
.on('hidden.bs.popover shown.bs.popover', function () {
assert.ok(false, 'should not fire any popover events')
})
.bootstrapPopover('hide')
assert.strictEqual(typeof $popover.data('bs.popover'), 'undefined', 'should not initialize the popover')
})
QUnit.test('should fire inserted event', function (assert) {
assert.expect(2)
var done = assert.async()
$('
@Johann-S')
.appendTo('#qunit-fixture')
.on('inserted.bs.popover', function () {
assert.notEqual($('.popover').length, 0, 'popover was inserted')
assert.ok(true, 'inserted event fired')
done()
})
.bootstrapPopover({
title: 'Test',
content: 'Test'
})
.bootstrapPopover('show')
})
QUnit.test('should throw an error when show is called on hidden elements', function (assert) {
assert.expect(1)
var done = assert.async()
try {
$('
').bootstrapPopover('show')
} catch (err) {
assert.strictEqual(err.message, 'Please use show on visible elements')
done()
}
})
QUnit.test('should hide popovers when their containing modal is closed', function (assert) {
assert.expect(1)
var done = assert.async()
var templateHTML = '
' +
'
' +
'
' +
'
' +
'' +
'
' +
'
' +
'
' +
'
'
$(templateHTML).appendTo('#qunit-fixture')
$('#popover-test')
.on('shown.bs.popover', function () {
$('#modal-test').modal('hide')
})
.on('hide.bs.popover', function () {
assert.ok(true, 'popover hide')
done()
})
$('#modal-test')
.on('shown.bs.modal', function () {
$('#popover-test').bootstrapPopover('show')
})
.modal('show')
})
QUnit.test('should convert number to string without error for content and title', function (assert) {
assert.expect(2)
var done = assert.async()
var $popover = $('
@mdo')
.appendTo('#qunit-fixture')
.bootstrapPopover({
title: 5,
content: 7
})
.on('shown.bs.popover', function () {
assert.strictEqual($('.popover .popover-header').text(), '5')
assert.strictEqual($('.popover .popover-body').text(), '7')
done()
})
$popover.bootstrapPopover('show')
})
QUnit.test('popover should be shown right away after the call of disable/enable', function (assert) {
assert.expect(2)
var done = assert.async()
var $popover = $('
@mdo')
.appendTo('#qunit-fixture')
.bootstrapPopover({
title: 'Test popover',
content: 'with disable/enable'
})
.on('shown.bs.popover', function () {
assert.strictEqual($('.popover').hasClass('show'), true)
done()
})
$popover.bootstrapPopover('disable')
$popover.trigger($.Event('click'))
setTimeout(function () {
assert.strictEqual($('.popover').length === 0, true)
$popover.bootstrapPopover('enable')
$popover.trigger($.Event('click'))
}, 200)
})
QUnit.test('popover should call content function only once', function (assert) {
assert.expect(1)
var done = assert.async()
var nbCall = 0
$('
content
').appendTo('#qunit-fixture')
var $popover = $('
@Johann-S')
.appendTo('#qunit-fixture')
.bootstrapPopover({
content: function () {
nbCall++
return $('#popover').clone().show().get(0)
}
})
.on('shown.bs.popover', function () {
assert.strictEqual(nbCall, 1)
done()
})
$popover.trigger($.Event('click'))
})
})
unit/.eslintrc.json 0000666 00000001170 15016752676 0010341 0 ustar 00 {
"env": {
"es6": false,
"qunit": true,
"jquery": true
},
"globals": {
"Util": false
},
"parserOptions": {
"ecmaVersion": 5,
"sourceType": "script"
},
"extends": "../../../.eslintrc.json",
"rules": {
"no-console": "off",
// Best Practices
"consistent-return": "off",
"no-magic-numbers": "off",
"vars-on-top": "off",
// Stylistic Issues
"func-style": "off",
"spaced-comment": "off",
// ECMAScript 6
"no-var": "off",
"object-shorthand": "off",
"prefer-arrow-callback": "off",
"prefer-template": "off",
"prefer-rest-params": "off"
}
}
unit/tooltip.js 0000666 00000071742 15016752676 0007611 0 ustar 00 $(function () {
'use strict'
QUnit.module('tooltip plugin')
QUnit.test('should be defined on jquery object', function (assert) {
assert.expect(1)
assert.ok($(document.body).tooltip, 'tooltip method is defined')
})
QUnit.module('tooltip', {
beforeEach: function () {
// Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode
$.fn.bootstrapTooltip = $.fn.tooltip.noConflict()
},
afterEach: function () {
$.fn.tooltip = $.fn.bootstrapTooltip
delete $.fn.bootstrapTooltip
$('.tooltip').remove()
}
})
QUnit.test('should provide no conflict', function (assert) {
assert.expect(1)
assert.strictEqual(typeof $.fn.tooltip, 'undefined', 'tooltip was set back to undefined (org value)')
})
QUnit.test('should throw explicit error on undefined method', function (assert) {
assert.expect(1)
var $el = $('
')
$el.bootstrapTooltip()
try {
$el.bootstrapTooltip('noMethod')
} catch (err) {
assert.strictEqual(err.message, 'No method named "noMethod"')
}
})
QUnit.test('should return jquery collection containing the element', function (assert) {
assert.expect(2)
var $el = $('
')
var $tooltip = $el.bootstrapTooltip()
assert.ok($tooltip instanceof $, 'returns jquery collection')
assert.strictEqual($tooltip[0], $el[0], 'collection contains element')
})
QUnit.test('should expose default settings', function (assert) {
assert.expect(1)
assert.ok($.fn.bootstrapTooltip.Constructor.Default, 'defaults is defined')
})
QUnit.test('should empty title attribute', function (assert) {
assert.expect(1)
var $trigger = $('
').bootstrapTooltip()
assert.strictEqual($trigger.attr('title'), '', 'title attribute was emptied')
})
QUnit.test('should add data attribute for referencing original title', function (assert) {
assert.expect(1)
var $trigger = $('
').bootstrapTooltip()
assert.strictEqual($trigger.attr('data-original-title'), 'Another tooltip', 'original title preserved in data attribute')
})
QUnit.test('should add aria-describedby to the trigger on show', function (assert) {
assert.expect(3)
var $trigger = $('
')
.bootstrapTooltip()
.appendTo('#qunit-fixture')
.bootstrapTooltip('show')
var id = $('.tooltip').attr('id')
assert.strictEqual($('#' + id).length, 1, 'has a unique id')
assert.strictEqual($('.tooltip').attr('aria-describedby'), $trigger.attr('id'), 'tooltip id and aria-describedby on trigger match')
assert.ok($trigger[0].hasAttribute('aria-describedby'), 'trigger has aria-describedby')
})
QUnit.test('should remove aria-describedby from trigger on hide', function (assert) {
assert.expect(2)
var $trigger = $('
')
.bootstrapTooltip()
.appendTo('#qunit-fixture')
$trigger.bootstrapTooltip('show')
assert.ok($trigger[0].hasAttribute('aria-describedby'), 'trigger has aria-describedby')
$trigger.bootstrapTooltip('hide')
assert.ok(!$trigger[0].hasAttribute('aria-describedby'), 'trigger does not have aria-describedby')
})
QUnit.test('should assign a unique id tooltip element', function (assert) {
assert.expect(2)
$('
')
.appendTo('#qunit-fixture')
.bootstrapTooltip('show')
var id = $('.tooltip').attr('id')
assert.strictEqual($('#' + id).length, 1, 'tooltip has unique id')
assert.strictEqual(id.indexOf('tooltip'), 0, 'tooltip id has prefix')
})
QUnit.test('should place tooltips relative to placement option', function (assert) {
assert.expect(2)
var $tooltip = $('
')
.appendTo('#qunit-fixture')
.bootstrapTooltip({
placement: 'bottom'
})
$tooltip.bootstrapTooltip('show')
assert
.ok($('.tooltip')
.is('.fade.bs-tooltip-bottom.show'), 'has correct classes applied')
$tooltip.bootstrapTooltip('hide')
assert.strictEqual($tooltip.data('bs.tooltip').tip.parentNode, null, 'tooltip removed')
})
QUnit.test('should allow html entities', function (assert) {
assert.expect(2)
var $tooltip = $('
')
.appendTo('#qunit-fixture')
.bootstrapTooltip({
html: true
})
$tooltip.bootstrapTooltip('show')
assert.notEqual($('.tooltip b').length, 0, 'b tag was inserted')
$tooltip.bootstrapTooltip('hide')
assert.strictEqual($tooltip.data('bs.tooltip').tip.parentNode, null, 'tooltip removed')
})
QUnit.test('should allow DOMElement title (html: false)', function (assert) {
assert.expect(3)
var title = document.createTextNode('<3 writing tests')
var $tooltip = $('
')
.appendTo('#qunit-fixture')
.bootstrapTooltip({
title: title
})
$tooltip.bootstrapTooltip('show')
assert.notEqual($('.tooltip').length, 0, 'tooltip inserted')
assert.strictEqual($('.tooltip').text(), '<3 writing tests', 'title inserted')
assert.ok(!$.contains($('.tooltip').get(0), title), 'title node copied, not moved')
})
QUnit.test('should allow DOMElement title (html: true)', function (assert) {
assert.expect(3)
var title = document.createTextNode('<3 writing tests')
var $tooltip = $('
')
.appendTo('#qunit-fixture')
.bootstrapTooltip({
html: true,
title: title
})
$tooltip.bootstrapTooltip('show')
assert.notEqual($('.tooltip').length, 0, 'tooltip inserted')
assert.strictEqual($('.tooltip').text(), '<3 writing tests', 'title inserted')
assert.ok($.contains($('.tooltip').get(0), title), 'title node moved, not copied')
})
QUnit.test('should respect custom classes', function (assert) {
assert.expect(2)
var $tooltip = $('
')
.appendTo('#qunit-fixture')
.bootstrapTooltip({
template: '
'
})
$tooltip.bootstrapTooltip('show')
assert.ok($('.tooltip').hasClass('some-class'), 'custom class is present')
$tooltip.bootstrapTooltip('hide')
assert.strictEqual($tooltip.data('bs.tooltip').tip.parentNode, null, 'tooltip removed')
})
QUnit.test('should fire show event', function (assert) {
assert.expect(1)
var done = assert.async()
$('
')
.on('show.bs.tooltip', function () {
assert.ok(true, 'show event fired')
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should throw an error when show is called on hidden elements', function (assert) {
assert.expect(1)
var done = assert.async()
try {
$('
').bootstrapTooltip('show')
} catch (err) {
assert.strictEqual(err.message, 'Please use show on visible elements')
done()
}
})
QUnit.test('should fire inserted event', function (assert) {
assert.expect(2)
var done = assert.async()
$('
')
.appendTo('#qunit-fixture')
.on('inserted.bs.tooltip', function () {
assert.notEqual($('.tooltip').length, 0, 'tooltip was inserted')
assert.ok(true, 'inserted event fired')
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should fire shown event', function (assert) {
assert.expect(1)
var done = assert.async()
$('
')
.appendTo('#qunit-fixture')
.on('shown.bs.tooltip', function () {
assert.ok(true, 'shown was called')
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should not fire shown event when show was prevented', function (assert) {
assert.expect(1)
var done = assert.async()
$('
')
.on('show.bs.tooltip', function (e) {
e.preventDefault()
assert.ok(true, 'show event fired')
done()
})
.on('shown.bs.tooltip', function () {
assert.ok(false, 'shown event fired')
})
.bootstrapTooltip('show')
})
QUnit.test('should fire hide event', function (assert) {
assert.expect(1)
var done = assert.async()
$('
')
.appendTo('#qunit-fixture')
.on('shown.bs.tooltip', function () {
$(this).bootstrapTooltip('hide')
})
.on('hide.bs.tooltip', function () {
assert.ok(true, 'hide event fired')
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should fire hidden event', function (assert) {
assert.expect(1)
var done = assert.async()
$('
')
.appendTo('#qunit-fixture')
.on('shown.bs.tooltip', function () {
$(this).bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
assert.ok(true, 'hidden event fired')
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should not fire hidden event when hide was prevented', function (assert) {
assert.expect(1)
var done = assert.async()
$('
')
.appendTo('#qunit-fixture')
.on('shown.bs.tooltip', function () {
$(this).bootstrapTooltip('hide')
})
.on('hide.bs.tooltip', function (e) {
e.preventDefault()
assert.ok(true, 'hide event fired')
done()
})
.on('hidden.bs.tooltip', function () {
assert.ok(false, 'hidden event fired')
})
.bootstrapTooltip('show')
})
QUnit.test('should destroy tooltip', function (assert) {
assert.expect(7)
var $tooltip = $('
')
.bootstrapTooltip()
.on('click.foo', function () {}) // eslint-disable-line no-empty-function
assert.ok($tooltip.data('bs.tooltip'), 'tooltip has data')
assert.ok($._data($tooltip[0], 'events').mouseover && $._data($tooltip[0], 'events').mouseout, 'tooltip has hover events')
assert.strictEqual($._data($tooltip[0], 'events').click[0].namespace, 'foo', 'tooltip has extra click.foo event')
$tooltip.bootstrapTooltip('show')
$tooltip.bootstrapTooltip('dispose')
assert.ok(!$tooltip.hasClass('show'), 'tooltip is hidden')
assert.ok(!$._data($tooltip[0], 'bs.tooltip'), 'tooltip does not have data')
assert.strictEqual($._data($tooltip[0], 'events').click[0].namespace, 'foo', 'tooltip still has click.foo')
assert.ok(!$._data($tooltip[0], 'events').mouseover && !$._data($tooltip[0], 'events').mouseout, 'tooltip does not have hover events')
})
// QUnit.test('should show tooltip with delegate selector on click', function (assert) {
// assert.expect(2)
// var $div = $('
')
// .appendTo('#qunit-fixture')
// .bootstrapTooltip({
// selector: 'a[rel="tooltip"]',
// trigger: 'click'
// })
// $div.find('a').trigger('click')
// assert.ok($('.tooltip').is('.fade.in'), 'tooltip is faded in')
// $div.find('a').trigger('click')
// assert.strictEqual($div.data('bs.tooltip').tip.parentNode, null, 'tooltip removed')
// })
QUnit.test('should show tooltip when toggle is called', function (assert) {
assert.expect(1)
$('
')
.appendTo('#qunit-fixture')
.bootstrapTooltip({
trigger: 'manual'
})
.bootstrapTooltip('toggle')
assert.ok($('.tooltip').is('.fade.show'), 'tooltip is faded active')
})
QUnit.test('should hide previously shown tooltip when toggle is called on tooltip', function (assert) {
assert.expect(1)
$('
@ResentedHook')
.appendTo('#qunit-fixture')
.bootstrapTooltip({
trigger: 'manual'
})
.bootstrapTooltip('show')
$('.tooltip').bootstrapTooltip('toggle')
assert.ok($('.tooltip').not('.fade.show'), 'tooltip was faded out')
})
QUnit.test('should place tooltips inside body when container is body', function (assert) {
assert.expect(3)
var $tooltip = $('
')
.appendTo('#qunit-fixture')
.bootstrapTooltip({
container: 'body'
})
.bootstrapTooltip('show')
assert.notEqual($('body > .tooltip').length, 0, 'tooltip is direct descendant of body')
assert.strictEqual($('#qunit-fixture > .tooltip').length, 0, 'tooltip is not in parent')
$tooltip.bootstrapTooltip('hide')
assert.strictEqual($('body > .tooltip').length, 0, 'tooltip was removed from dom')
})
QUnit.test('should add position class before positioning so that position-specific styles are taken into account', function (assert) {
assert.expect(2)
var done = assert.async()
var styles = ''
var $styles = $(styles).appendTo('head')
var $container = $('
').appendTo('#qunit-fixture')
$('
')
.appendTo($container)
.bootstrapTooltip({
placement: 'right',
trigger: 'manual'
})
.on('inserted.bs.tooltip', function () {
var $tooltip = $($(this).data('bs.tooltip').tip)
assert.ok($tooltip.hasClass('bs-tooltip-right'))
assert.ok(typeof $tooltip.attr('style') === 'undefined')
$styles.remove()
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should use title attribute for tooltip text', function (assert) {
assert.expect(2)
var $tooltip = $('
')
.appendTo('#qunit-fixture')
.bootstrapTooltip()
$tooltip.bootstrapTooltip('show')
assert.strictEqual($('.tooltip').children('.tooltip-inner').text(), 'Simple tooltip', 'title from title attribute is set')
$tooltip.bootstrapTooltip('hide')
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
})
QUnit.test('should prefer title attribute over title option', function (assert) {
assert.expect(2)
var $tooltip = $('
')
.appendTo('#qunit-fixture')
.bootstrapTooltip({
title: 'This is a tooltip with some content'
})
$tooltip.bootstrapTooltip('show')
assert.strictEqual($('.tooltip').children('.tooltip-inner').text(), 'Simple tooltip', 'title is set from title attribute while preferred over title option')
$tooltip.bootstrapTooltip('hide')
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
})
QUnit.test('should use title option', function (assert) {
assert.expect(2)
var $tooltip = $('
')
.appendTo('#qunit-fixture')
.bootstrapTooltip({
title: 'This is a tooltip with some content'
})
$tooltip.bootstrapTooltip('show')
assert.strictEqual($('.tooltip').children('.tooltip-inner').text(), 'This is a tooltip with some content', 'title from title option is set')
$tooltip.bootstrapTooltip('hide')
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
})
QUnit.test('should not error when trying to show an top-placed tooltip that has been removed from the dom', function (assert) {
assert.expect(1)
var passed = true
var $tooltip = $('
')
.appendTo('#qunit-fixture')
.one('show.bs.tooltip', function () {
$(this).remove()
})
.bootstrapTooltip({
placement: 'top'
})
try {
$tooltip.bootstrapTooltip('show')
} catch (err) {
passed = false
console.log(err)
}
assert.ok(passed, '.tooltip(\'show\') should not throw an error if element no longer is in dom')
})
QUnit.test('should place tooltip on top of element', function (assert) {
assert.expect(1)
var done = assert.async()
var containerHTML = '
'
var $container = $(containerHTML)
.css({
position: 'absolute',
bottom: 0,
left: 0,
textAlign: 'right',
width: 300,
height: 300
})
.appendTo('#qunit-fixture')
$container
.find('a')
.css('margin-top', 200)
.bootstrapTooltip({
placement: 'top',
animate: false
})
.on('shown.bs.tooltip', function () {
var $tooltip = $($(this).data('bs.tooltip').tip)
if (/iPhone|iPad|iPod/.test(navigator.userAgent)) {
assert.ok(Math.round($tooltip.offset().top + $tooltip.outerHeight()) <= Math.round($(this).offset().top))
} else {
assert.ok(Math.round($tooltip.offset().top + $tooltip.outerHeight()) >= Math.round($(this).offset().top))
}
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should show tooltip if leave event hasn\'t occurred before delay expires', function (assert) {
assert.expect(2)
var done = assert.async()
var $tooltip = $('
')
.appendTo('#qunit-fixture')
.bootstrapTooltip({
delay: 150
})
setTimeout(function () {
assert.ok(!$('.tooltip').is('.fade.show'), '100ms: tooltip is not faded active')
}, 100)
setTimeout(function () {
assert.ok($('.tooltip').is('.fade.show'), '200ms: tooltip is faded active')
done()
}, 200)
$tooltip.trigger('mouseenter')
})
QUnit.test('should not show tooltip if leave event occurs before delay expires', function (assert) {
assert.expect(2)
var done = assert.async()
var $tooltip = $('
')
.appendTo('#qunit-fixture')
.bootstrapTooltip({
delay: 150
})
setTimeout(function () {
assert.ok(!$('.tooltip').is('.fade.show'), '100ms: tooltip not faded active')
$tooltip.trigger('mouseout')
}, 100)
setTimeout(function () {
assert.ok(!$('.tooltip').is('.fade.show'), '200ms: tooltip not faded active')
done()
}, 200)
$tooltip.trigger('mouseenter')
})
QUnit.test('should not hide tooltip if leave event occurs and enter event occurs within the hide delay', function (assert) {
assert.expect(3)
var done = assert.async()
var $tooltip = $('
')
.appendTo('#qunit-fixture')
.bootstrapTooltip({
delay: {
show: 0,
hide: 150
}
})
setTimeout(function () {
assert.ok($('.tooltip').is('.fade.show'), '1ms: tooltip faded active')
$tooltip.trigger('mouseout')
setTimeout(function () {
assert.ok($('.tooltip').is('.fade.show'), '100ms: tooltip still faded active')
$tooltip.trigger('mouseenter')
}, 100)
setTimeout(function () {
assert.ok($('.tooltip').is('.fade.show'), '200ms: tooltip still faded active')
done()
}, 200)
}, 0)
$tooltip.trigger('mouseenter')
})
QUnit.test('should not show tooltip if leave event occurs before delay expires', function (assert) {
assert.expect(2)
var done = assert.async()
var $tooltip = $('
')
.appendTo('#qunit-fixture')
.bootstrapTooltip({
delay: 150
})
setTimeout(function () {
assert.ok(!$('.tooltip').is('.fade.show'), '100ms: tooltip not faded active')
$tooltip.trigger('mouseout')
}, 100)
setTimeout(function () {
assert.ok(!$('.tooltip').is('.fade.show'), '200ms: tooltip not faded active')
done()
}, 200)
$tooltip.trigger('mouseenter')
})
QUnit.test('should not show tooltip if leave event occurs before delay expires, even if hide delay is 0', function (assert) {
assert.expect(2)
var done = assert.async()
var $tooltip = $('
')
.appendTo('#qunit-fixture')
.bootstrapTooltip({
delay: {
show: 150,
hide: 0
}
})
setTimeout(function () {
assert.ok(!$('.tooltip').is('.fade.show'), '100ms: tooltip not faded active')
$tooltip.trigger('mouseout')
}, 100)
setTimeout(function () {
assert.ok(!$('.tooltip').is('.fade.show'), '250ms: tooltip not faded active')
done()
}, 250)
$tooltip.trigger('mouseenter')
})
QUnit.test('should wait 200ms before hiding the tooltip', function (assert) {
assert.expect(3)
var done = assert.async()
var $tooltip = $('
')
.appendTo('#qunit-fixture')
.bootstrapTooltip({
delay: {
show: 0,
hide: 150
}
})
setTimeout(function () {
assert.ok($($tooltip.data('bs.tooltip').tip).is('.fade.show'), '1ms: tooltip faded active')
$tooltip.trigger('mouseout')
setTimeout(function () {
assert.ok($($tooltip.data('bs.tooltip').tip).is('.fade.show'), '100ms: tooltip still faded active')
}, 100)
setTimeout(function () {
assert.ok(!$($tooltip.data('bs.tooltip').tip).is('.show'), '200ms: tooltip removed')
done()
}, 200)
}, 0)
$tooltip.trigger('mouseenter')
})
QUnit.test('should not reload the tooltip on subsequent mouseenter events', function (assert) {
assert.expect(1)
var titleHtml = function () {
var uid = Util.getUID('tooltip')
return '
' + uid + '
' + uid + '
' + uid + '
'
}
var $tooltip = $('
some text')
.appendTo('#qunit-fixture')
$tooltip.bootstrapTooltip({
html: true,
animation: false,
trigger: 'hover',
delay: {
show: 0,
hide: 500
},
container: $tooltip,
title: titleHtml
})
$('#tt-outer').trigger('mouseenter')
var currentUid = $('#tt-content').text()
$('#tt-content').trigger('mouseenter')
assert.strictEqual(currentUid, $('#tt-content').text())
})
QUnit.test('should not reload the tooltip if the mouse leaves and re-enters before hiding', function (assert) {
assert.expect(4)
var titleHtml = function () {
var uid = Util.getUID('tooltip')
return '
' + uid + '
' + uid + '
' + uid + '
'
}
var $tooltip = $('
some text')
.appendTo('#qunit-fixture')
$tooltip.bootstrapTooltip({
html: true,
animation: false,
trigger: 'hover',
delay: {
show: 0,
hide: 500
},
title: titleHtml
})
var obj = $tooltip.data('bs.tooltip')
$('#tt-outer').trigger('mouseenter')
var currentUid = $('#tt-content').text()
$('#tt-outer').trigger('mouseleave')
assert.strictEqual(currentUid, $('#tt-content').text())
assert.ok(obj._hoverState === 'out', 'the tooltip hoverState should be set to "out"')
$('#tt-outer').trigger('mouseenter')
assert.ok(obj._hoverState === 'show', 'the tooltip hoverState should be set to "show"')
assert.strictEqual(currentUid, $('#tt-content').text())
})
QUnit.test('should do nothing when an attempt is made to hide an uninitialized tooltip', function (assert) {
assert.expect(1)
var $tooltip = $('
some text')
.appendTo('#qunit-fixture')
.on('hidden.bs.tooltip shown.bs.tooltip', function () {
assert.ok(false, 'should not fire any tooltip events')
})
.bootstrapTooltip('hide')
assert.strictEqual(typeof $tooltip.data('bs.tooltip'), 'undefined', 'should not initialize the tooltip')
})
QUnit.test('should not remove tooltip if multiple triggers are set and one is still active', function (assert) {
assert.expect(41)
var $el = $('
')
.appendTo('#qunit-fixture')
.bootstrapTooltip({
trigger: 'click hover focus',
animation: false
})
var tooltip = $el.data('bs.tooltip')
var $tooltip = $(tooltip.getTipElement())
function showingTooltip() {
return $tooltip.hasClass('show') || tooltip._hoverState === 'show'
}
var tests = [
['mouseenter', 'mouseleave'],
['focusin', 'focusout'],
['click', 'click'],
['mouseenter', 'focusin', 'focusout', 'mouseleave'],
['mouseenter', 'focusin', 'mouseleave', 'focusout'],
['focusin', 'mouseenter', 'mouseleave', 'focusout'],
['focusin', 'mouseenter', 'focusout', 'mouseleave'],
['click', 'focusin', 'mouseenter', 'focusout', 'mouseleave', 'click'],
['mouseenter', 'click', 'focusin', 'focusout', 'mouseleave', 'click'],
['mouseenter', 'focusin', 'click', 'click', 'mouseleave', 'focusout']
]
assert.ok(!showingTooltip())
$.each(tests, function (idx, triggers) {
for (var i = 0, len = triggers.length; i < len; i++) {
$el.trigger(triggers[i])
assert.equal(i < len - 1, showingTooltip())
}
})
})
QUnit.test('should show on first trigger after hide', function (assert) {
assert.expect(3)
var $el = $('
')
.appendTo('#qunit-fixture')
.bootstrapTooltip({
trigger: 'click hover focus',
animation: false
})
var tooltip = $el.data('bs.tooltip')
var $tooltip = $(tooltip.getTipElement())
function showingTooltip() {
return $tooltip.hasClass('show') || tooltip._hoverState === 'show'
}
$el.trigger('click')
assert.ok(showingTooltip(), 'tooltip is faded in')
$el.bootstrapTooltip('hide')
assert.ok(!showingTooltip(), 'tooltip was faded out')
$el.trigger('click')
assert.ok(showingTooltip(), 'tooltip is faded in again')
})
QUnit.test('should hide tooltip when their containing modal is closed', function (assert) {
assert.expect(1)
var done = assert.async()
var templateHTML = '
'
$(templateHTML).appendTo('#qunit-fixture')
$('#tooltipTest')
.bootstrapTooltip({
trigger: 'manuel'
})
.on('shown.bs.tooltip', function () {
$('#modal-test').modal('hide')
})
.on('hide.bs.tooltip', function () {
assert.ok(true, 'tooltip hide')
done()
})
$('#modal-test')
.on('shown.bs.modal', function () {
$('#tooltipTest').bootstrapTooltip('show')
})
.modal('show')
})
QUnit.test('should reset tip classes when hidden event triggered', function (assert) {
assert.expect(2)
var done = assert.async()
var $el = $('
')
.appendTo('#qunit-fixture')
.bootstrapTooltip('show')
.on('hidden.bs.tooltip', function () {
var tooltip = $el.data('bs.tooltip')
var $tooltip = $(tooltip.getTipElement())
assert.ok($tooltip.hasClass('tooltip'))
assert.ok($tooltip.hasClass('fade'))
done()
})
$el.bootstrapTooltip('hide')
})
QUnit.test('should convert number in title to string', function (assert) {
assert.expect(1)
var done = assert.async()
var $el = $('
')
.appendTo('#qunit-fixture')
.bootstrapTooltip('show')
.on('shown.bs.tooltip', function () {
var tooltip = $el.data('bs.tooltip')
var $tooltip = $(tooltip.getTipElement())
assert.strictEqual($tooltip.children().text(), '7')
done()
})
$el.bootstrapTooltip('show')
})
QUnit.test('tooltip should be shown right away after the call of disable/enable', function (assert) {
assert.expect(2)
var done = assert.async()
var $trigger = $('
')
.appendTo('#qunit-fixture')
.bootstrapTooltip()
.on('shown.bs.tooltip', function () {
assert.strictEqual($('.tooltip').hasClass('show'), true)
done()
})
$trigger.bootstrapTooltip('disable')
$trigger.trigger($.Event('click'))
setTimeout(function () {
assert.strictEqual($('.tooltip').length === 0, true)
$trigger.bootstrapTooltip('enable')
$trigger.trigger($.Event('click'))
}, 200)
})
})
unit/tab.js 0000666 00000040014 15016752676 0006651 0 ustar 00 $(function () {
'use strict'
QUnit.module('tabs plugin')
QUnit.test('should be defined on jquery object', function (assert) {
assert.expect(1)
assert.ok($(document.body).tab, 'tabs method is defined')
})
QUnit.module('tabs', {
beforeEach: function () {
// Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode
$.fn.bootstrapTab = $.fn.tab.noConflict()
},
afterEach: function () {
$.fn.tab = $.fn.bootstrapTab
delete $.fn.bootstrapTab
}
})
QUnit.test('should provide no conflict', function (assert) {
assert.expect(1)
assert.strictEqual(typeof $.fn.tab, 'undefined', 'tab was set back to undefined (org value)')
})
QUnit.test('should throw explicit error on undefined method', function (assert) {
assert.expect(1)
var $el = $('
')
$el.bootstrapTab()
try {
$el.bootstrapTab('noMethod')
} catch (err) {
assert.strictEqual(err.message, 'No method named "noMethod"')
}
})
QUnit.test('should return jquery collection containing the element', function (assert) {
assert.expect(2)
var $el = $('
')
var $tab = $el.bootstrapTab()
assert.ok($tab instanceof $, 'returns jquery collection')
assert.strictEqual($tab[0], $el[0], 'collection contains element')
})
QUnit.test('should activate element by tab id', function (assert) {
assert.expect(2)
var tabsHTML = '
'
$('
').appendTo('#qunit-fixture')
$(tabsHTML).find('li:last-child a').bootstrapTab('show')
assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'profile')
$(tabsHTML).find('li:first-child a').bootstrapTab('show')
assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'home')
})
QUnit.test('should activate element by tab id', function (assert) {
assert.expect(2)
var pillsHTML = '
'
$('
').appendTo('#qunit-fixture')
$(pillsHTML).find('li:last-child a').bootstrapTab('show')
assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'profile')
$(pillsHTML).find('li:first-child a').bootstrapTab('show')
assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'home')
})
QUnit.test('should activate element by tab id in ordered list', function (assert) {
assert.expect(2)
var pillsHTML = '
' +
'- Home
' +
'- Profile
' +
'
'
$('
').appendTo('#qunit-fixture')
$(pillsHTML).find('li:last-child a').bootstrapTab('show')
assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'profile')
$(pillsHTML).find('li:first-child a').bootstrapTab('show')
assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'home')
})
QUnit.test('should activate element by tab id in nav list', function (assert) {
assert.expect(2)
var tabsHTML = '
'
$('
').appendTo('#qunit-fixture')
$(tabsHTML).find('a:last-child').bootstrapTab('show')
assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'profile')
$(tabsHTML).find('a:first-child').bootstrapTab('show')
assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'home')
})
QUnit.test('should activate element by tab id in list group', function (assert) {
assert.expect(2)
var tabsHTML = '
'
$('
').appendTo('#qunit-fixture')
$(tabsHTML).find('a:last-child').bootstrapTab('show')
assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'profile')
$(tabsHTML).find('a:first-child').bootstrapTab('show')
assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'home')
})
QUnit.test('should not fire shown when show is prevented', function (assert) {
assert.expect(1)
var done = assert.async()
$('
')
.on('show.bs.tab', function (e) {
e.preventDefault()
assert.ok(true, 'show event fired')
done()
})
.on('shown.bs.tab', function () {
assert.ok(false, 'shown event fired')
})
.bootstrapTab('show')
})
QUnit.test('should not fire shown when tab is already active', function (assert) {
assert.expect(0)
var tabsHTML = '
' +
'
'
$(tabsHTML)
.find('a.active')
.on('shown.bs.tab', function () {
assert.ok(true, 'shown event fired')
})
.bootstrapTab('show')
})
QUnit.test('should not fire shown when tab is disabled', function (assert) {
assert.expect(0)
var tabsHTML = '
' +
'
'
$(tabsHTML)
.find('a.disabled')
.on('shown.bs.tab', function () {
assert.ok(true, 'shown event fired')
})
.bootstrapTab('show')
})
QUnit.test('show and shown events should reference correct relatedTarget', function (assert) {
assert.expect(2)
var done = assert.async()
var dropHTML =
'
'
$(dropHTML)
.find('ul > li:first-child a')
.bootstrapTab('show')
.end()
.find('ul > li:last-child a')
.on('show.bs.tab', function (e) {
assert.strictEqual(e.relatedTarget.hash, '#1-1', 'references correct element as relatedTarget')
})
.on('shown.bs.tab', function (e) {
assert.strictEqual(e.relatedTarget.hash, '#1-1', 'references correct element as relatedTarget')
done()
})
.bootstrapTab('show')
})
QUnit.test('should fire hide and hidden events', function (assert) {
assert.expect(2)
var done = assert.async()
var tabsHTML = '
'
$(tabsHTML)
.find('li:first-child a')
.on('hide.bs.tab', function () {
assert.ok(true, 'hide event fired')
})
.bootstrapTab('show')
.end()
.find('li:last-child a')
.bootstrapTab('show')
$(tabsHTML)
.find('li:first-child a')
.on('hidden.bs.tab', function () {
assert.ok(true, 'hidden event fired')
done()
})
.bootstrapTab('show')
.end()
.find('li:last-child a')
.bootstrapTab('show')
})
QUnit.test('should not fire hidden when hide is prevented', function (assert) {
assert.expect(1)
var done = assert.async()
var tabsHTML = '
'
$(tabsHTML)
.find('li:first-child a')
.on('hide.bs.tab', function (e) {
e.preventDefault()
assert.ok(true, 'hide event fired')
done()
})
.on('hidden.bs.tab', function () {
assert.ok(false, 'hidden event fired')
})
.bootstrapTab('show')
.end()
.find('li:last-child a')
.bootstrapTab('show')
})
QUnit.test('hide and hidden events contain correct relatedTarget', function (assert) {
assert.expect(2)
var done = assert.async()
var tabsHTML = '
'
$(tabsHTML)
.find('li:first-child a')
.on('hide.bs.tab', function (e) {
assert.strictEqual(e.relatedTarget.hash, '#profile', 'references correct element as relatedTarget')
})
.on('hidden.bs.tab', function (e) {
assert.strictEqual(e.relatedTarget.hash, '#profile', 'references correct element as relatedTarget')
done()
})
.bootstrapTab('show')
.end()
.find('li:last-child a')
.bootstrapTab('show')
})
QUnit.test('selected tab should have aria-selected', function (assert) {
assert.expect(8)
var tabsHTML = '
'
var $tabs = $(tabsHTML).appendTo('#qunit-fixture')
$tabs.find('li:first-child a').bootstrapTab('show')
assert.strictEqual($tabs.find('.active').attr('aria-selected'), 'true', 'shown tab has aria-selected = true')
assert.strictEqual($tabs.find('a:not(.active)').attr('aria-selected'), 'false', 'hidden tab has aria-selected = false')
$tabs.find('li:last-child a').trigger('click')
assert.strictEqual($tabs.find('.active').attr('aria-selected'), 'true', 'after click, shown tab has aria-selected = true')
assert.strictEqual($tabs.find('a:not(.active)').attr('aria-selected'), 'false', 'after click, hidden tab has aria-selected = false')
$tabs.find('li:first-child a').bootstrapTab('show')
assert.strictEqual($tabs.find('.active').attr('aria-selected'), 'true', 'shown tab has aria-selected = true')
assert.strictEqual($tabs.find('a:not(.active)').attr('aria-selected'), 'false', 'hidden tab has aria-selected = false')
$tabs.find('li:first-child a').trigger('click')
assert.strictEqual($tabs.find('.active').attr('aria-selected'), 'true', 'after second show event, shown tab still has aria-selected = true')
assert.strictEqual($tabs.find('a:not(.active)').attr('aria-selected'), 'false', 'after second show event, hidden tab has aria-selected = false')
})
QUnit.test('selected tab should deactivate previous selected tab', function (assert) {
assert.expect(2)
var tabsHTML = '
'
var $tabs = $(tabsHTML).appendTo('#qunit-fixture')
$tabs.find('li:last-child a').trigger('click')
assert.notOk($tabs.find('li:first-child a').hasClass('active'))
assert.ok($tabs.find('li:last-child a').hasClass('active'))
})
QUnit.test('selected tab should deactivate previous selected link in dropdown', function (assert) {
assert.expect(3)
var tabsHTML = '
'
var $tabs = $(tabsHTML).appendTo('#qunit-fixture')
$tabs.find('li:first-child a').trigger('click')
assert.ok($tabs.find('li:first-child a').hasClass('active'))
assert.notOk($tabs.find('li:last-child a').hasClass('active'))
assert.notOk($tabs.find('li:last-child .dropdown-menu a:first-child').hasClass('active'))
})
QUnit.test('Nested tabs', function (assert) {
assert.expect(2)
var done = assert.async()
var tabsHTML =
'
' +
'
' +
'
' +
'
Tab2 Content
' +
'
Tab3 Content
' +
'
'
$(tabsHTML).appendTo('#qunit-fixture')
$('#tabNested2').on('shown.bs.tab', function () {
assert.ok($('#x-tab1').hasClass('active'))
done()
})
$('#tab1').on('shown.bs.tab', function () {
assert.ok($('#x-tab1').hasClass('active'))
$('#tabNested2').trigger($.Event('click'))
})
.trigger($.Event('click'))
})
QUnit.test('should not remove fade class if no active pane is present', function (assert) {
assert.expect(6)
var done = assert.async()
var tabsHTML = '
' +
'
'
$(tabsHTML).appendTo('#qunit-fixture')
$('#tab-profile')
.on('shown.bs.tab', function () {
assert.ok($('#profile').hasClass('fade'))
assert.ok($('#profile').hasClass('show'))
$('#tab-home')
.on('shown.bs.tab', function () {
assert.ok($('#profile').hasClass('fade'))
assert.notOk($('#profile').hasClass('show'))
assert.ok($('#home').hasClass('fade'))
assert.ok($('#home').hasClass('show'))
done()
})
.trigger($.Event('click'))
})
.trigger($.Event('click'))
})
})
unit/alert.js 0000666 00000005310 15016752676 0007212 0 ustar 00 $(function () {
'use strict'
QUnit.module('alert plugin')
QUnit.test('should be defined on jquery object', function (assert) {
assert.expect(1)
assert.ok($(document.body).alert, 'alert method is defined')
})
QUnit.module('alert', {
beforeEach: function () {
// Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode
$.fn.bootstrapAlert = $.fn.alert.noConflict()
},
afterEach: function () {
$.fn.alert = $.fn.bootstrapAlert
delete $.fn.bootstrapAlert
}
})
QUnit.test('should provide no conflict', function (assert) {
assert.expect(1)
assert.strictEqual(typeof $.fn.alert, 'undefined', 'alert was set back to undefined (org value)')
})
QUnit.test('should return jquery collection containing the element', function (assert) {
assert.expect(2)
var $el = $('
')
var $alert = $el.bootstrapAlert()
assert.ok($alert instanceof $, 'returns jquery collection')
assert.strictEqual($alert[0], $el[0], 'collection contains element')
})
QUnit.test('should fade element out on clicking .close', function (assert) {
assert.expect(1)
var alertHTML = '
' +
'
×' +
'
Holy guacamole! Best check yo self, you\'re not looking too good.
' +
'
'
var $alert = $(alertHTML).bootstrapAlert().appendTo($('#qunit-fixture'))
$alert.find('.close').trigger('click')
assert.strictEqual($alert.hasClass('show'), false, 'remove .show class on .close click')
})
QUnit.test('should remove element when clicking .close', function (assert) {
assert.expect(2)
var alertHTML = '
' +
'
×' +
'
Holy guacamole! Best check yo self, you\'re not looking too good.
' +
'
'
var $alert = $(alertHTML).appendTo('#qunit-fixture').bootstrapAlert()
assert.notEqual($('#qunit-fixture').find('.alert').length, 0, 'element added to dom')
$alert.find('.close').trigger('click')
assert.strictEqual($('#qunit-fixture').find('.alert').length, 0, 'element removed from dom')
})
QUnit.test('should not fire closed when close is prevented', function (assert) {
assert.expect(1)
var done = assert.async()
$('
')
.on('close.bs.alert', function (e) {
e.preventDefault()
assert.ok(true, 'close event fired')
done()
})
.on('closed.bs.alert', function () {
assert.ok(false, 'closed event fired')
})
.bootstrapAlert('close')
})
})
unit/modal.js 0000666 00000062666 15016752676 0007220 0 ustar 00 $(function () {
'use strict'
QUnit.module('modal plugin')
QUnit.test('should be defined on jquery object', function (assert) {
assert.expect(1)
assert.ok($(document.body).modal, 'modal method is defined')
})
QUnit.module('modal', {
before: function () {
// Enable the scrollbar measurer
$('').appendTo('head')
// Function to calculate the scrollbar width which is then compared to the padding or margin changes
$.fn.getScrollbarWidth = function () {
var scrollDiv = document.createElement('div')
scrollDiv.className = 'modal-scrollbar-measure'
document.body.appendChild(scrollDiv)
var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth
document.body.removeChild(scrollDiv)
return scrollbarWidth
}
// Simulate scrollbars in PhantomJS
$('html').css('padding-right', '16px')
},
beforeEach: function () {
// Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode
$.fn.bootstrapModal = $.fn.modal.noConflict()
},
afterEach: function () {
$('.modal-backdrop, #modal-test').remove()
$(document.body).removeClass('modal-open')
$.fn.modal = $.fn.bootstrapModal
delete $.fn.bootstrapModal
}
})
QUnit.test('should provide no conflict', function (assert) {
assert.expect(1)
assert.strictEqual(typeof $.fn.modal, 'undefined', 'modal was set back to undefined (orig value)')
})
QUnit.test('should throw explicit error on undefined method', function (assert) {
assert.expect(1)
var $el = $('
')
$el.bootstrapModal()
try {
$el.bootstrapModal('noMethod')
} catch (err) {
assert.strictEqual(err.message, 'No method named "noMethod"')
}
})
QUnit.test('should return jquery collection containing the element', function (assert) {
assert.expect(2)
var $el = $('
')
var $modal = $el.bootstrapModal()
assert.ok($modal instanceof $, 'returns jquery collection')
assert.strictEqual($modal[0], $el[0], 'collection contains element')
})
QUnit.test('should expose defaults var for settings', function (assert) {
assert.expect(1)
assert.ok($.fn.bootstrapModal.Constructor.Default, 'default object exposed')
})
QUnit.test('should insert into dom when show method is called', function (assert) {
assert.expect(1)
var done = assert.async()
$('
')
.on('shown.bs.modal', function () {
assert.notEqual($('#modal-test').length, 0, 'modal inserted into dom')
done()
})
.bootstrapModal('show')
})
QUnit.test('should fire show event', function (assert) {
assert.expect(1)
var done = assert.async()
$('
')
.on('show.bs.modal', function () {
assert.ok(true, 'show event fired')
done()
})
.bootstrapModal('show')
})
QUnit.test('should not fire shown when show was prevented', function (assert) {
assert.expect(1)
var done = assert.async()
$('
')
.on('show.bs.modal', function (e) {
e.preventDefault()
assert.ok(true, 'show event fired')
done()
})
.on('shown.bs.modal', function () {
assert.ok(false, 'shown event fired')
})
.bootstrapModal('show')
})
QUnit.test('should hide modal when hide is called', function (assert) {
assert.expect(3)
var done = assert.async()
$('
')
.on('shown.bs.modal', function () {
assert.ok($('#modal-test').is(':visible'), 'modal visible')
assert.notEqual($('#modal-test').length, 0, 'modal inserted into dom')
$(this).bootstrapModal('hide')
})
.on('hidden.bs.modal', function () {
assert.ok(!$('#modal-test').is(':visible'), 'modal hidden')
done()
})
.bootstrapModal('show')
})
QUnit.test('should toggle when toggle is called', function (assert) {
assert.expect(3)
var done = assert.async()
$('
')
.on('shown.bs.modal', function () {
assert.ok($('#modal-test').is(':visible'), 'modal visible')
assert.notEqual($('#modal-test').length, 0, 'modal inserted into dom')
$(this).bootstrapModal('toggle')
})
.on('hidden.bs.modal', function () {
assert.ok(!$('#modal-test').is(':visible'), 'modal hidden')
done()
})
.bootstrapModal('toggle')
})
QUnit.test('should remove from dom when click [data-dismiss="modal"]', function (assert) {
assert.expect(3)
var done = assert.async()
$('
')
.on('shown.bs.modal', function () {
assert.ok($('#modal-test').is(':visible'), 'modal visible')
assert.notEqual($('#modal-test').length, 0, 'modal inserted into dom')
$(this).find('.close').trigger('click')
})
.on('hidden.bs.modal', function () {
assert.ok(!$('#modal-test').is(':visible'), 'modal hidden')
done()
})
.bootstrapModal('toggle')
})
QUnit.test('should allow modal close with "backdrop:false"', function (assert) {
assert.expect(2)
var done = assert.async()
$('
')
.on('shown.bs.modal', function () {
assert.ok($('#modal-test').is(':visible'), 'modal visible')
$(this).bootstrapModal('hide')
})
.on('hidden.bs.modal', function () {
assert.ok(!$('#modal-test').is(':visible'), 'modal hidden')
done()
})
.bootstrapModal('show')
})
QUnit.test('should close modal when clicking outside of modal-content', function (assert) {
assert.expect(3)
var done = assert.async()
$('
')
.on('shown.bs.modal', function () {
assert.notEqual($('#modal-test').length, 0, 'modal inserted into dom')
$('.contents').trigger('click')
assert.ok($('#modal-test').is(':visible'), 'modal visible')
$('#modal-test').trigger('click')
})
.on('hidden.bs.modal', function () {
assert.ok(!$('#modal-test').is(':visible'), 'modal hidden')
done()
})
.bootstrapModal('show')
})
QUnit.test('should not close modal when clicking outside of modal-content if data-backdrop="true"', function (assert) {
assert.expect(1)
var done = assert.async()
$('
')
.on('shown.bs.modal', function () {
$('#modal-test').trigger('click')
assert.ok($('#modal-test').is(':visible'), 'modal not hidden')
done()
})
.bootstrapModal('show')
})
QUnit.test('should close modal when escape key is pressed via keydown', function (assert) {
assert.expect(3)
var done = assert.async()
var $div = $('
')
$div
.on('shown.bs.modal', function () {
assert.ok($('#modal-test').length, 'modal inserted into dom')
assert.ok($('#modal-test').is(':visible'), 'modal visible')
$div.trigger($.Event('keydown', {
which: 27
}))
setTimeout(function () {
assert.ok(!$('#modal-test').is(':visible'), 'modal hidden')
$div.remove()
done()
}, 0)
})
.bootstrapModal('show')
})
QUnit.test('should not close modal when escape key is pressed via keyup', function (assert) {
assert.expect(3)
var done = assert.async()
var $div = $('
')
$div
.on('shown.bs.modal', function () {
assert.ok($('#modal-test').length, 'modal inserted into dom')
assert.ok($('#modal-test').is(':visible'), 'modal visible')
$div.trigger($.Event('keyup', {
which: 27
}))
setTimeout(function () {
assert.ok($div.is(':visible'), 'modal still visible')
$div.remove()
done()
}, 0)
})
.bootstrapModal('show')
})
QUnit.test('should trigger hide event once when clicking outside of modal-content', function (assert) {
assert.expect(1)
var done = assert.async()
var triggered
$('
')
.on('shown.bs.modal', function () {
triggered = 0
$('#modal-test').trigger('click')
})
.on('hide.bs.modal', function () {
triggered += 1
assert.strictEqual(triggered, 1, 'modal hide triggered once')
done()
})
.bootstrapModal('show')
})
QUnit.test('should remove aria-hidden attribute when shown, add it back when hidden', function (assert) {
assert.expect(3)
var done = assert.async()
$('
')
.on('shown.bs.modal', function () {
assert.notOk($('#modal-test').is('[aria-hidden]'), 'aria-hidden attribute removed')
$(this).bootstrapModal('hide')
})
.on('hidden.bs.modal', function () {
assert.ok($('#modal-test').is('[aria-hidden]'), 'aria-hidden attribute added')
assert.strictEqual($('#modal-test').attr('aria-hidden'), 'true', 'correct aria-hidden="true" added')
done()
})
.bootstrapModal('show')
})
QUnit.test('should close reopened modal with [data-dismiss="modal"] click', function (assert) {
assert.expect(2)
var done = assert.async()
$('
')
.one('shown.bs.modal', function () {
$('#close').trigger('click')
})
.one('hidden.bs.modal', function () {
// After one open-close cycle
assert.ok(!$('#modal-test').is(':visible'), 'modal hidden')
$(this)
.one('shown.bs.modal', function () {
$('#close').trigger('click')
})
.one('hidden.bs.modal', function () {
assert.ok(!$('#modal-test').is(':visible'), 'modal hidden')
done()
})
.bootstrapModal('show')
})
.bootstrapModal('show')
})
QUnit.test('should restore focus to toggling element when modal is hidden after having been opened via data-api', function (assert) {
assert.expect(1)
var done = assert.async()
var $toggleBtn = $('
').appendTo('#qunit-fixture')
$('
')
.on('hidden.bs.modal', function () {
setTimeout(function () {
assert.ok($(document.activeElement).is($toggleBtn), 'toggling element is once again focused')
done()
}, 0)
})
.on('shown.bs.modal', function () {
$('#close').trigger('click')
})
.appendTo('#qunit-fixture')
$toggleBtn.trigger('click')
})
QUnit.test('should not restore focus to toggling element if the associated show event gets prevented', function (assert) {
assert.expect(1)
var done = assert.async()
var $toggleBtn = $('
').appendTo('#qunit-fixture')
var $otherBtn = $('
').appendTo('#qunit-fixture')
$('
')
.one('show.bs.modal', function (e) {
e.preventDefault()
$otherBtn.trigger('focus')
setTimeout($.proxy(function () {
$(this).bootstrapModal('show')
}, this), 0)
})
.on('hidden.bs.modal', function () {
setTimeout(function () {
assert.ok($(document.activeElement).is($otherBtn), 'focus returned to toggling element')
done()
}, 0)
})
.on('shown.bs.modal', function () {
$('#close').trigger('click')
})
.appendTo('#qunit-fixture')
$toggleBtn.trigger('click')
})
QUnit.test('should adjust the inline padding of the modal when opening', function (assert) {
assert.expect(1)
var done = assert.async()
$('
')
.on('shown.bs.modal', function () {
var expectedPadding = $(this).getScrollbarWidth() + 'px'
var currentPadding = $(this).css('padding-right')
assert.strictEqual(currentPadding, expectedPadding, 'modal padding should be adjusted while opening')
done()
})
.bootstrapModal('show')
})
QUnit.test('should adjust the inline body padding when opening and restore when closing', function (assert) {
assert.expect(2)
var done = assert.async()
var $body = $(document.body)
var originalPadding = $body.css('padding-right')
$('
')
.on('hidden.bs.modal', function () {
var currentPadding = $body.css('padding-right')
assert.strictEqual(currentPadding, originalPadding, 'body padding should be reset after closing')
$body.removeAttr('style')
done()
})
.on('shown.bs.modal', function () {
var expectedPadding = parseFloat(originalPadding) + $(this).getScrollbarWidth() + 'px'
var currentPadding = $body.css('padding-right')
assert.strictEqual(currentPadding, expectedPadding, 'body padding should be adjusted while opening')
$(this).bootstrapModal('hide')
})
.bootstrapModal('show')
})
QUnit.test('should store the original body padding in data-padding-right before showing', function (assert) {
assert.expect(2)
var done = assert.async()
var $body = $(document.body)
var originalPadding = '0px'
$body.css('padding-right', originalPadding)
$('
')
.on('hidden.bs.modal', function () {
assert.strictEqual(typeof $body.data('padding-right'), 'undefined', 'data-padding-right should be cleared after closing')
$body.removeAttr('style')
done()
})
.on('shown.bs.modal', function () {
assert.strictEqual($body.data('padding-right'), originalPadding, 'original body padding should be stored in data-padding-right')
$(this).bootstrapModal('hide')
})
.bootstrapModal('show')
})
QUnit.test('should not adjust the inline body padding when it does not overflow', function (assert) {
assert.expect(1)
var done = assert.async()
var $body = $(document.body)
var originalPadding = $body.css('padding-right')
// Hide scrollbars to prevent the body overflowing
$body.css('overflow', 'hidden') // Real scrollbar (for in-browser testing)
$('html').css('padding-right', '0px') // Simulated scrollbar (for PhantomJS)
$('
')
.on('shown.bs.modal', function () {
var currentPadding = $body.css('padding-right')
assert.strictEqual(currentPadding, originalPadding, 'body padding should not be adjusted')
$(this).bootstrapModal('hide')
// Restore scrollbars
$body.css('overflow', 'auto')
$('html').css('padding-right', '16px')
done()
})
.bootstrapModal('show')
})
QUnit.test('should adjust the inline padding of fixed elements when opening and restore when closing', function (assert) {
assert.expect(2)
var done = assert.async()
var $element = $('
').appendTo('#qunit-fixture')
var originalPadding = $element.css('padding-right')
$('
')
.on('hidden.bs.modal', function () {
var currentPadding = $element.css('padding-right')
assert.strictEqual(currentPadding, originalPadding, 'fixed element padding should be reset after closing')
$element.remove()
done()
})
.on('shown.bs.modal', function () {
var expectedPadding = parseFloat(originalPadding) + $(this).getScrollbarWidth() + 'px'
var currentPadding = $element.css('padding-right')
assert.strictEqual(currentPadding, expectedPadding, 'fixed element padding should be adjusted while opening')
$(this).bootstrapModal('hide')
})
.bootstrapModal('show')
})
QUnit.test('should store the original padding of fixed elements in data-padding-right before showing', function (assert) {
assert.expect(2)
var done = assert.async()
var $element = $('
').appendTo('#qunit-fixture')
var originalPadding = '0px'
$element.css('padding-right', originalPadding)
$('
')
.on('hidden.bs.modal', function () {
assert.strictEqual(typeof $element.data('padding-right'), 'undefined', 'data-padding-right should be cleared after closing')
$element.remove()
done()
})
.on('shown.bs.modal', function () {
assert.strictEqual($element.data('padding-right'), originalPadding, 'original fixed element padding should be stored in data-padding-right')
$(this).bootstrapModal('hide')
})
.bootstrapModal('show')
})
QUnit.test('should adjust the inline margin of sticky elements when opening and restore when closing', function (assert) {
assert.expect(2)
var done = assert.async()
var $element = $('
').appendTo('#qunit-fixture')
var originalPadding = $element.css('margin-right')
$('
')
.on('hidden.bs.modal', function () {
var currentPadding = $element.css('margin-right')
assert.strictEqual(currentPadding, originalPadding, 'sticky element margin should be reset after closing')
$element.remove()
done()
})
.on('shown.bs.modal', function () {
var expectedPadding = parseFloat(originalPadding) - $(this).getScrollbarWidth() + 'px'
var currentPadding = $element.css('margin-right')
assert.strictEqual(currentPadding, expectedPadding, 'sticky element margin should be adjusted while opening')
$(this).bootstrapModal('hide')
})
.bootstrapModal('show')
})
QUnit.test('should store the original margin of sticky elements in data-margin-right before showing', function (assert) {
assert.expect(2)
var done = assert.async()
var $element = $('
').appendTo('#qunit-fixture')
var originalPadding = '0px'
$element.css('margin-right', originalPadding)
$('
')
.on('hidden.bs.modal', function () {
assert.strictEqual(typeof $element.data('margin-right'), 'undefined', 'data-margin-right should be cleared after closing')
$element.remove()
done()
})
.on('shown.bs.modal', function () {
assert.strictEqual($element.data('margin-right'), originalPadding, 'original sticky element margin should be stored in data-margin-right')
$(this).bootstrapModal('hide')
})
.bootstrapModal('show')
})
QUnit.test('should adjust the inline margin of the navbar-toggler when opening and restore when closing', function (assert) {
assert.expect(2)
var done = assert.async()
var $element = $('
').appendTo('#qunit-fixture')
var originalMargin = $element.css('margin-right')
$('
')
.on('hidden.bs.modal', function () {
var currentMargin = $element.css('margin-right')
assert.strictEqual(currentMargin, originalMargin, 'navbar-toggler margin should be reset after closing')
$element.remove()
done()
})
.on('shown.bs.modal', function () {
var expectedMargin = parseFloat(originalMargin) + $(this).getScrollbarWidth() + 'px'
var currentMargin = $element.css('margin-right')
assert.strictEqual(currentMargin, expectedMargin, 'navbar-toggler margin should be adjusted while opening')
$(this).bootstrapModal('hide')
})
.bootstrapModal('show')
})
QUnit.test('should store the original margin of the navbar-toggler in data-margin-right before showing', function (assert) {
assert.expect(2)
var done = assert.async()
var $element = $('
').appendTo('#qunit-fixture')
var originalMargin = '0px'
$element.css('margin-right', originalMargin)
$('
')
.on('hidden.bs.modal', function () {
assert.strictEqual(typeof $element.data('margin-right'), 'undefined', 'data-margin-right should be cleared after closing')
$element.remove()
done()
})
.on('shown.bs.modal', function () {
assert.strictEqual($element.data('margin-right'), originalMargin, 'original navbar-toggler margin should be stored in data-margin-right')
$(this).bootstrapModal('hide')
})
.bootstrapModal('show')
})
QUnit.test('should ignore values set via CSS when trying to restore body padding after closing', function (assert) {
assert.expect(1)
var done = assert.async()
var $body = $(document.body)
var $style = $('').appendTo('head')
$('
')
.on('hidden.bs.modal', function () {
assert.strictEqual($body.attr('style').indexOf('padding-right'), -1, 'body does not have inline padding set')
$style.remove()
done()
})
.on('shown.bs.modal', function () {
$(this).bootstrapModal('hide')
})
.bootstrapModal('show')
})
QUnit.test('should ignore other inline styles when trying to restore body padding after closing', function (assert) {
assert.expect(2)
var done = assert.async()
var $body = $(document.body)
var $style = $('').appendTo('head')
$body.css('color', 'red')
$('
')
.on('hidden.bs.modal', function () {
assert.strictEqual($body[0].style.paddingRight, '', 'body does not have inline padding set')
assert.strictEqual($body[0].style.color, 'red', 'body still has other inline styles set')
$body.removeAttr('style')
$style.remove()
done()
})
.on('shown.bs.modal', function () {
$(this).bootstrapModal('hide')
})
.bootstrapModal('show')
})
QUnit.test('should properly restore non-pixel inline body padding after closing', function (assert) {
assert.expect(1)
var done = assert.async()
var $body = $(document.body)
$body.css('padding-right', '5%')
$('
')
.on('hidden.bs.modal', function () {
assert.strictEqual($body[0].style.paddingRight, '5%', 'body does not have inline padding set')
$body.removeAttr('style')
done()
})
.on('shown.bs.modal', function () {
$(this).bootstrapModal('hide')
})
.bootstrapModal('show')
})
QUnit.test('should not follow link in area tag', function (assert) {
assert.expect(2)
var done = assert.async()
$('
')
.appendTo('#qunit-fixture')
$('
')
.appendTo('#qunit-fixture')
$('#test')
.on('click.bs.modal.data-api', function (event) {
assert.notOk(event.isDefaultPrevented(), 'navigating to href will happen')
setTimeout(function () {
assert.ok(event.isDefaultPrevented(), 'model shown instead of navigating to href')
done()
}, 1)
})
.trigger('click')
})
QUnit.test('should not parse target as html', function (assert) {
assert.expect(1)
var done = assert.async()
var $toggleBtn = $('
')
.appendTo('#qunit-fixture')
$toggleBtn.trigger('click')
setTimeout(function () {
assert.strictEqual($('#modal-test').length, 0, 'target has not been parsed and added to the document')
done()
}, 1)
})
QUnit.test('should not execute js from target', function (assert) {
assert.expect(0)
var done = assert.async()
// This toggle button contains XSS payload in its data-target
// Note: it uses the onerror handler of an img element to execute the js, because a simple script element does not work here
// a script element works in manual tests though, so here it is likely blocked by the qunit framework
var $toggleBtn = $('
')
.appendTo('#qunit-fixture')
// The XSS payload above does not have a closure over this function and cannot access the assert object directly
// However, it can send a click event to the following control button, which will then fail the assert
$('