diff --git a/tests/unit/core/core.js b/tests/unit/core/core.js index 3d8e7a09..ceb23607 100644 --- a/tests/unit/core/core.js +++ b/tests/unit/core/core.js @@ -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); \ No newline at end of file diff --git a/tests/unit/core/core_scroll.js b/tests/unit/core/core_scroll.js index ba3a007d..8724684e 100644 --- a/tests/unit/core/core_scroll.js +++ b/tests/unit/core/core_scroll.js @@ -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(){ - $("
").appendTo("body"); - }, + module(libName, { + setup: function(){ + $("
").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);