jquery-mobile/tests/unit/core/core_scroll.js

68 lines
1.6 KiB
JavaScript

/*
* mobile core unit tests
*/
(function($){
var libName = "jquery.mobile.core.js",
scrollTimeout = 20, // TODO expose timing as an attribute
scrollStartEnabledTimeout = 150;
module(libName, {
setup: function(){
$("<div id='scroll-testing' style='height: 1000px'></div>").appendTo("body");
},
teardown: function(){
$("#scroll-testing").remove();
window.fizz = '';
}
});
var scrollUp = function( pos ){
$(window).scrollTop(1000);
ok($(window).scrollTop() > 0, $(window).scrollTop());
$.mobile.silentScroll(pos);
};
asyncTest( "silent scroll scrolls the page to the top by default", function(){
scrollUp();
setTimeout(function(){
same($(window).scrollTop(), 0);
start();
}, scrollTimeout);
});
asyncTest( "silent scroll scrolls the page to the passed y position", function(){
var pos = 10;
scrollUp(pos);
setTimeout(function(){
same($(window).scrollTop(), pos);
start();
}, scrollTimeout);
});
// NOTE may be brittle depending on timing
asyncTest( "silent scroll takes at least 20 ms to scroll to the top", function(){
scrollUp();
setTimeout(function(){
ok($(window).scrollTop() != 0, "scrolltop position should not be zero");
start();
}, scrollTimeout - 5);
});
asyncTest( "scrolling marks scrollstart as disabled for 150 ms", function(){
$.event.special.scrollstart.enabled = true;
scrollUp();
ok(!$.event.special.scrollstart.enabled);
setTimeout(function(){
ok($.event.special.scrollstart.enabled);
start();
}, scrollStartEnabledTimeout);
});
//TODO test that silentScroll is called on window load
})(jQuery);