mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-03-17 06:20:26 +00:00
added immediate function to prevent scoping issues in core unit tests
This commit is contained in:
parent
b671753039
commit
e30ece11ac
2 changed files with 193 additions and 189 deletions
|
|
@ -2,148 +2,148 @@
|
|||
* mobile core unit tests
|
||||
*/
|
||||
|
||||
var libName = "jquery.mobile.core.js",
|
||||
setGradeA = function(value) { $.support.mediaquery = value; },
|
||||
extendFn = $.extend;
|
||||
(function($){
|
||||
var libName = "jquery.mobile.core.js",
|
||||
setGradeA = function(value) { $.support.mediaquery = value; },
|
||||
extendFn = $.extend;
|
||||
|
||||
module(libName, {
|
||||
setup: function(){
|
||||
// NOTE reset for gradeA tests
|
||||
$('html').removeClass('ui-mobile');
|
||||
module(libName, {
|
||||
setup: function(){
|
||||
// NOTE reset for gradeA tests
|
||||
$('html').removeClass('ui-mobile');
|
||||
|
||||
// NOTE reset for pageLoading tests
|
||||
$('.ui-loader').remove();
|
||||
},
|
||||
teardown: function(){
|
||||
$.extend = extendFn;
|
||||
}
|
||||
});
|
||||
|
||||
$.testHelper.excludeFileProtocol(function(){
|
||||
test( "grade A browser support media queries", function(){
|
||||
setGradeA(false);
|
||||
$.testHelper.reloadLib(libName);
|
||||
ok(!$.mobile.gradeA());
|
||||
|
||||
setGradeA(true);
|
||||
$.testHelper.reloadLib(libName);
|
||||
ok($.mobile.gradeA());
|
||||
// NOTE reset for pageLoading tests
|
||||
$('.ui-loader').remove();
|
||||
},
|
||||
teardown: function(){
|
||||
$.extend = extendFn;
|
||||
}
|
||||
});
|
||||
|
||||
test( "loading the core library triggers mobilinit on the document", function(){
|
||||
expect( 1 );
|
||||
$.testHelper.excludeFileProtocol(function(){
|
||||
test( "grade A browser support media queries", function(){
|
||||
setGradeA(false);
|
||||
$.testHelper.reloadLib(libName);
|
||||
ok(!$.mobile.gradeA());
|
||||
|
||||
$(window.document).bind('mobileinit', function(event){
|
||||
ok(true);
|
||||
setGradeA(true);
|
||||
$.testHelper.reloadLib(libName);
|
||||
ok($.mobile.gradeA());
|
||||
});
|
||||
|
||||
$.testHelper.reloadLib(libName);
|
||||
});
|
||||
test( "loading the core library triggers mobilinit on the document", function(){
|
||||
expect( 1 );
|
||||
|
||||
test( "enhancments are skipped when the browser is not grade A", function(){
|
||||
setGradeA(false);
|
||||
$.testHelper.reloadLib(libName);
|
||||
$(window.document).bind('mobileinit', function(event){
|
||||
ok(true);
|
||||
});
|
||||
|
||||
//NOTE easiest way to check for enhancements, not the most obvious
|
||||
ok(!$("html").hasClass("ui-mobile"));
|
||||
});
|
||||
|
||||
test( "enhancments are added when the browser is grade A", function(){
|
||||
setGradeA(true);
|
||||
$.testHelper.reloadLib(libName);
|
||||
|
||||
ok($("html").hasClass("ui-mobile"));
|
||||
});
|
||||
|
||||
|
||||
//TODO lots of duplication
|
||||
test( "pageLoading doesn't add the dialog to the page when loading message is false", function(){
|
||||
$.testHelper.alterExtend({loadingMessage: false});
|
||||
$.testHelper.reloadLib(libName);
|
||||
$.mobile.pageLoading(false);
|
||||
ok(!$(".ui-loader").length);
|
||||
});
|
||||
|
||||
test( "pageLoading doesn't add the dialog to the page when done is passed as true", function(){
|
||||
$.testHelper.alterExtend({loadingMessage: true});
|
||||
$.testHelper.reloadLib(libName);
|
||||
|
||||
// TODO add post reload callback
|
||||
$('.ui-loader').remove();
|
||||
|
||||
$.mobile.pageLoading(true);
|
||||
ok(!$(".ui-loader").length);
|
||||
});
|
||||
|
||||
test( "pageLoading adds the dialog to the page when done is true", function(){
|
||||
$.testHelper.alterExtend({loadingMessage: true});
|
||||
$.testHelper.reloadLib(libName);
|
||||
$.mobile.pageLoading(false);
|
||||
ok($(".ui-loader").length);
|
||||
});
|
||||
|
||||
var metaViewportSelector = "head meta[name=viewport]",
|
||||
setViewPortContent = function(value){
|
||||
$(metaViewportSelector).remove();
|
||||
$.testHelper.alterExtend({metaViewportContent: value});
|
||||
$.testHelper.reloadLib(libName);
|
||||
};
|
||||
|
||||
test( "meta view port element is added to head when defined on mobile", function(){
|
||||
setViewPortContent("width=device-width");
|
||||
same($(metaViewportSelector).length, 1);
|
||||
});
|
||||
|
||||
test( "meta view port element not added to head when not defined on mobile", function(){
|
||||
setViewPortContent(false);
|
||||
same($(metaViewportSelector).length, 0);
|
||||
});
|
||||
|
||||
var findFirstPage = function() {
|
||||
return $("[data-role='page']").first();
|
||||
};
|
||||
|
||||
test( "active page and start page should be set to the fist page in the selected set", function(){
|
||||
var firstPage = findFirstPage();
|
||||
$.testHelper.reloadLib(libName);
|
||||
|
||||
same($.mobile.startPage, firstPage);
|
||||
same($.mobile.activePage, firstPage);
|
||||
});
|
||||
|
||||
test( "mobile viewport class is defined on the first page's parent", function(){
|
||||
var firstPage = findFirstPage();
|
||||
$.testHelper.reloadLib(libName);
|
||||
|
||||
ok(firstPage.parent().hasClass('ui-mobile-viewport'));
|
||||
});
|
||||
|
||||
test( "mobile page container is the first page's parent", function(){
|
||||
var firstPage = findFirstPage();
|
||||
$.testHelper.reloadLib(libName);
|
||||
|
||||
same($.mobile.pageContainer, firstPage.parent());
|
||||
});
|
||||
|
||||
test( "page loading is called on document ready", function(){
|
||||
expect( 2 );
|
||||
|
||||
$.testHelper.alterExtend({ pageLoading: function(){
|
||||
ok("called");
|
||||
}});
|
||||
|
||||
$.testHelper.reloadLib(libName);
|
||||
});
|
||||
|
||||
test( "hashchange triggered on document ready with single argument: true", function(){
|
||||
expect( 2 );
|
||||
|
||||
$(window).bind("hashchange", function(ev, arg){
|
||||
same(arg, true);
|
||||
$.testHelper.reloadLib(libName);
|
||||
});
|
||||
|
||||
$.testHelper.reloadLib(libName);
|
||||
});
|
||||
test( "enhancments are skipped when the browser is not grade A", function(){
|
||||
setGradeA(false);
|
||||
$.testHelper.reloadLib(libName);
|
||||
|
||||
//TODO test that silentScroll is called on window load
|
||||
});
|
||||
//NOTE easiest way to check for enhancements, not the most obvious
|
||||
ok(!$("html").hasClass("ui-mobile"));
|
||||
});
|
||||
|
||||
test( "enhancments are added when the browser is grade A", function(){
|
||||
setGradeA(true);
|
||||
$.testHelper.reloadLib(libName);
|
||||
|
||||
ok($("html").hasClass("ui-mobile"));
|
||||
});
|
||||
|
||||
|
||||
//TODO lots of duplication
|
||||
test( "pageLoading doesn't add the dialog to the page when loading message is false", function(){
|
||||
$.testHelper.alterExtend({loadingMessage: false});
|
||||
$.testHelper.reloadLib(libName);
|
||||
$.mobile.pageLoading(false);
|
||||
ok(!$(".ui-loader").length);
|
||||
});
|
||||
|
||||
test( "pageLoading doesn't add the dialog to the page when done is passed as true", function(){
|
||||
$.testHelper.alterExtend({loadingMessage: true});
|
||||
$.testHelper.reloadLib(libName);
|
||||
|
||||
// TODO add post reload callback
|
||||
$('.ui-loader').remove();
|
||||
|
||||
$.mobile.pageLoading(true);
|
||||
ok(!$(".ui-loader").length);
|
||||
});
|
||||
|
||||
test( "pageLoading adds the dialog to the page when done is true", function(){
|
||||
$.testHelper.alterExtend({loadingMessage: true});
|
||||
$.testHelper.reloadLib(libName);
|
||||
$.mobile.pageLoading(false);
|
||||
ok($(".ui-loader").length);
|
||||
});
|
||||
|
||||
var metaViewportSelector = "head meta[name=viewport]",
|
||||
setViewPortContent = function(value){
|
||||
$(metaViewportSelector).remove();
|
||||
$.testHelper.alterExtend({metaViewportContent: value});
|
||||
$.testHelper.reloadLib(libName);
|
||||
};
|
||||
|
||||
test( "meta view port element is added to head when defined on mobile", function(){
|
||||
setViewPortContent("width=device-width");
|
||||
same($(metaViewportSelector).length, 1);
|
||||
});
|
||||
|
||||
test( "meta view port element not added to head when not defined on mobile", function(){
|
||||
setViewPortContent(false);
|
||||
same($(metaViewportSelector).length, 0);
|
||||
});
|
||||
|
||||
var findFirstPage = function() {
|
||||
return $("[data-role='page']").first();
|
||||
};
|
||||
|
||||
test( "active page and start page should be set to the fist page in the selected set", function(){
|
||||
var firstPage = findFirstPage();
|
||||
$.testHelper.reloadLib(libName);
|
||||
|
||||
same($.mobile.startPage, firstPage);
|
||||
same($.mobile.activePage, firstPage);
|
||||
});
|
||||
|
||||
test( "mobile viewport class is defined on the first page's parent", function(){
|
||||
var firstPage = findFirstPage();
|
||||
$.testHelper.reloadLib(libName);
|
||||
|
||||
ok(firstPage.parent().hasClass('ui-mobile-viewport'));
|
||||
});
|
||||
|
||||
test( "mobile page container is the first page's parent", function(){
|
||||
var firstPage = findFirstPage();
|
||||
$.testHelper.reloadLib(libName);
|
||||
|
||||
same($.mobile.pageContainer, firstPage.parent());
|
||||
});
|
||||
|
||||
test( "page loading is called on document ready", function(){
|
||||
expect( 2 );
|
||||
|
||||
$.testHelper.alterExtend({ pageLoading: function(){
|
||||
ok("called");
|
||||
}});
|
||||
|
||||
$.testHelper.reloadLib(libName);
|
||||
});
|
||||
|
||||
test( "hashchange triggered on document ready with single argument: true", function(){
|
||||
expect( 2 );
|
||||
|
||||
$(window).bind("hashchange", function(ev, arg){
|
||||
same(arg, true);
|
||||
});
|
||||
|
||||
$.testHelper.reloadLib(libName);
|
||||
});
|
||||
});
|
||||
})(jQuery);
|
||||
|
|
@ -2,71 +2,75 @@
|
|||
* mobile core unit tests
|
||||
*/
|
||||
|
||||
var libName = "jquery.mobile.core.js",
|
||||
scrollTimeout = 20, // TODO expose timing as an attribute
|
||||
scrollStartEnabledTimeout = 150;
|
||||
(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");
|
||||
},
|
||||
module(libName, {
|
||||
setup: function(){
|
||||
$("<div id='scroll-testing' style='height: 1000px'></div>").appendTo("body");
|
||||
},
|
||||
|
||||
teardown: function(){
|
||||
$("#scroll-testing").remove();
|
||||
}
|
||||
});
|
||||
teardown: function(){
|
||||
$("#scroll-testing").remove();
|
||||
}
|
||||
});
|
||||
|
||||
var scrollUp = function( pos ){
|
||||
$(window).scrollTop(1000);
|
||||
ok($(window).scrollTop() > 0);
|
||||
var scrollUp = function( pos ){
|
||||
$(window).scrollTop(1000);
|
||||
ok($(window).scrollTop() > 0);
|
||||
|
||||
if(pos) {
|
||||
$.mobile.silentScroll(pos);
|
||||
} else {
|
||||
$.mobile.silentScroll();
|
||||
}
|
||||
};
|
||||
if(pos) {
|
||||
$.mobile.silentScroll(pos);
|
||||
} else {
|
||||
$.mobile.silentScroll();
|
||||
}
|
||||
};
|
||||
|
||||
test( "silent scroll scrolls the page to the top by default", function(){
|
||||
scrollUp();
|
||||
test( "silent scroll scrolls the page to the top by default", function(){
|
||||
scrollUp();
|
||||
|
||||
stop();
|
||||
setTimeout(function(){
|
||||
same($(window).scrollTop(), 0);
|
||||
start();
|
||||
}, scrollTimeout);
|
||||
});
|
||||
stop();
|
||||
setTimeout(function(){
|
||||
same($(window).scrollTop(), 0);
|
||||
start();
|
||||
}, scrollTimeout);
|
||||
});
|
||||
|
||||
test( "silent scroll scrolls the page to the passed y position", function(){
|
||||
var pos = 10;
|
||||
scrollUp(pos);
|
||||
test( "silent scroll scrolls the page to the passed y position", function(){
|
||||
var pos = 10;
|
||||
scrollUp(pos);
|
||||
|
||||
stop();
|
||||
setTimeout(function(){
|
||||
same($(window).scrollTop(), pos);
|
||||
start();
|
||||
}, scrollTimeout);
|
||||
});
|
||||
stop();
|
||||
setTimeout(function(){
|
||||
same($(window).scrollTop(), pos);
|
||||
start();
|
||||
}, scrollTimeout);
|
||||
});
|
||||
|
||||
// NOTE may be brittle depending on timing
|
||||
test( "silent scroll takes at least 20 ms to scroll to the top", function(){
|
||||
scrollUp();
|
||||
// NOTE may be brittle depending on timing
|
||||
test( "silent scroll takes at least 20 ms to scroll to the top", function(){
|
||||
scrollUp();
|
||||
|
||||
stop();
|
||||
setTimeout(function(){
|
||||
ok($(window).scrollTop() != 0);
|
||||
start();
|
||||
}, scrollTimeout - 1);
|
||||
});
|
||||
stop();
|
||||
setTimeout(function(){
|
||||
ok($(window).scrollTop() != 0);
|
||||
start();
|
||||
}, scrollTimeout - 1);
|
||||
});
|
||||
|
||||
test( "scrolling marks scrollstart as disabled for 150 ms", function(){
|
||||
$.event.special.scrollstart.enabled = true;
|
||||
scrollUp();
|
||||
ok(!$.event.special.scrollstart.enabled);
|
||||
test( "scrolling marks scrollstart as disabled for 150 ms", function(){
|
||||
$.event.special.scrollstart.enabled = true;
|
||||
scrollUp();
|
||||
ok(!$.event.special.scrollstart.enabled);
|
||||
|
||||
stop();
|
||||
setTimeout(function(){
|
||||
ok($.event.special.scrollstart.enabled);
|
||||
start();
|
||||
}, scrollStartEnabledTimeout);
|
||||
});
|
||||
stop();
|
||||
setTimeout(function(){
|
||||
ok($.event.special.scrollstart.enabled);
|
||||
start();
|
||||
}, scrollStartEnabledTimeout);
|
||||
});
|
||||
|
||||
//TODO test that silentScroll is called on window load
|
||||
})(jQuery);
|
||||
|
|
|
|||
Loading…
Reference in a new issue