0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-04 16:24:22 +01:00
Bootstrap/js/tests/unit/affix.js

63 lines
1.8 KiB
JavaScript
Raw Normal View History

2012-07-23 03:28:39 +02:00
$(function () {
2014-03-17 08:12:55 +01:00
'use strict';
2012-07-23 03:28:39 +02:00
module('affix plugin')
2014-02-13 08:55:12 +01:00
test('should be defined on jquery object', function () {
ok($(document.body).affix, 'affix method is defined')
})
module('affix', {
2014-03-17 08:12:55 +01:00
setup: function () {
// Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode
$.fn.bootstrapAffix = $.fn.affix.noConflict()
},
2014-03-17 08:12:55 +01:00
teardown: function () {
$.fn.affix = $.fn.bootstrapAffix
delete $.fn.bootstrapAffix
}
})
test('should provide no conflict', function () {
ok(!$.fn.affix, 'affix was set back to undefined (org value)')
})
2014-02-13 08:55:12 +01:00
test('should return element', function () {
ok($(document.body).bootstrapAffix()[0] == document.body, 'document.body returned')
2014-02-13 08:55:12 +01:00
})
test('should exit early if element is not visible', function () {
var $affix = $('<div style="display: none"></div>').bootstrapAffix()
2014-02-13 08:55:12 +01:00
$affix.data('bs.affix').checkPosition()
ok(!$affix.hasClass('affix'), 'affix class was not added')
})
test('should trigger affixed event after affix', function () {
stop()
var template = $('<div id="affixTarget"><ul><li>Please affix</li><li>And unaffix</li></ul></div><div id="affixAfter" style="height: 20000px; display:block;"></div>')
template.appendTo('body')
$('#affixTarget').bootstrapAffix({
2014-02-13 08:55:12 +01:00
offset: $('#affixTarget ul').position()
})
$('#affixTarget')
2014-03-01 17:19:50 +01:00
.on('affix.bs.affix', function () {
2014-02-13 08:55:12 +01:00
ok(true, 'affix event triggered')
2014-03-01 17:19:50 +01:00
}).on('affixed.bs.affix', function () {
2014-03-17 08:12:55 +01:00
ok(true, 'affixed event triggered')
2014-02-13 08:55:12 +01:00
$('#affixTarget').remove()
$('#affixAfter').remove()
start()
2012-07-23 03:28:39 +02:00
})
2014-02-13 08:55:12 +01:00
setTimeout(function () {
window.scrollTo(0, document.body.scrollHeight)
2014-05-29 06:35:22 +02:00
setTimeout(function () {
window.scroll(0, 0)
}, 0)
2014-03-17 08:12:55 +01:00
}, 0)
2014-02-13 08:55:12 +01:00
})
})