mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-05-09 23:24:44 +00:00
re arranged tests for mobile init
This commit is contained in:
parent
a64a44504b
commit
2704975095
6 changed files with 186 additions and 137 deletions
|
|
@ -9,36 +9,39 @@
|
|||
|
||||
(function( $, window, undefined ) {
|
||||
var $html = $( "html" ),
|
||||
$head = $( "head" );
|
||||
$head = $( "head" ),
|
||||
$window = $( window );
|
||||
|
||||
// find and enhance the pages in the dom and transition to the first page.
|
||||
$.mobile.initializePage = function(){
|
||||
//find present pages
|
||||
var $pages = $( "[data-role='page']" );
|
||||
$.extend($.mobile, {
|
||||
// find and enhance the pages in the dom and transition to the first page.
|
||||
initializePage: function(){
|
||||
//find present pages
|
||||
var $pages = $( "[data-role='page']" );
|
||||
|
||||
//add dialogs, set data-url attrs
|
||||
$pages.add( "[data-role='dialog']" ).each(function(){
|
||||
$(this).attr( "data-url", $(this).attr( "id" ));
|
||||
});
|
||||
//add dialogs, set data-url attrs
|
||||
$pages.add( "[data-role='dialog']" ).each(function(){
|
||||
$(this).attr( "data-url", $(this).attr( "id" ));
|
||||
});
|
||||
|
||||
//define first page in dom case one backs out to the directory root (not always the first page visited, but defined as fallback)
|
||||
$.mobile.firstPage = $pages.first();
|
||||
//define first page in dom case one backs out to the directory root (not always the first page visited, but defined as fallback)
|
||||
$.mobile.firstPage = $pages.first();
|
||||
|
||||
//define page container
|
||||
$.mobile.pageContainer = $pages.first().parent().addClass( "ui-mobile-viewport" );
|
||||
//define page container
|
||||
$.mobile.pageContainer = $pages.first().parent().addClass( "ui-mobile-viewport" );
|
||||
|
||||
//cue page loading message
|
||||
$.mobile.pageLoading();
|
||||
//cue page loading message
|
||||
$.mobile.pageLoading();
|
||||
|
||||
// if hashchange listening is disabled or there's no hash deeplink, change to the first page in the DOM
|
||||
if( !$.mobile.hashListeningEnabled || !$.mobile.path.stripHash( location.hash ) ){
|
||||
$.mobile.changePage( $.mobile.firstPage, false, true, false, true );
|
||||
// if hashchange listening is disabled or there's no hash deeplink, change to the first page in the DOM
|
||||
if( !$.mobile.hashListeningEnabled || !$.mobile.path.stripHash( location.hash ) ){
|
||||
$.mobile.changePage( $.mobile.firstPage, false, true, false, true );
|
||||
}
|
||||
// otherwise, trigger a hashchange to load a deeplink
|
||||
else {
|
||||
$window.trigger( "hashchange", [ true ] );
|
||||
}
|
||||
}
|
||||
// otherwise, trigger a hashchange to load a deeplink
|
||||
else {
|
||||
$window.trigger( "hashchange", [ true ] );
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
//trigger mobileinit event - useful hook for configuring $.mobile settings before they're used
|
||||
$( window.document ).trigger( "mobileinit" );
|
||||
|
|
|
|||
|
|
@ -8,15 +8,11 @@
|
|||
extendFn = $.extend;
|
||||
|
||||
module(libName, {
|
||||
setup: function(){
|
||||
// NOTE reset for gradeA tests
|
||||
$('html').removeClass('ui-mobile');
|
||||
teardown: function(){
|
||||
$.extend = extendFn;
|
||||
|
||||
// NOTE reset for pageLoading tests
|
||||
$('.ui-loader').remove();
|
||||
},
|
||||
teardown: function(){
|
||||
$.extend = extendFn;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -31,32 +27,6 @@
|
|||
ok($.mobile.gradeA());
|
||||
});
|
||||
|
||||
test( "loading the core library triggers mobilinit on the document", function(){
|
||||
expect( 1 );
|
||||
|
||||
$(window.document).bind('mobileinit', function(event){
|
||||
ok(true);
|
||||
});
|
||||
|
||||
$.testHelper.reloadLib(libName);
|
||||
});
|
||||
|
||||
test( "enhancments are skipped when the browser is not grade A", function(){
|
||||
setGradeA(false);
|
||||
$.testHelper.reloadLib(libName);
|
||||
|
||||
//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});
|
||||
|
|
@ -81,69 +51,6 @@
|
|||
$.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.firstPage, 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(){
|
||||
$.testHelper.alterExtend({ pageLoading: function(){
|
||||
start();
|
||||
ok("called");
|
||||
}});
|
||||
|
||||
stop();
|
||||
$.testHelper.reloadLib(libName);
|
||||
});
|
||||
|
||||
test( "hashchange triggered on document ready with single argument: true", function(){
|
||||
$(window).bind("hashchange", function(ev, arg){
|
||||
same(arg, true);
|
||||
start();
|
||||
});
|
||||
|
||||
stop();
|
||||
$.testHelper.reloadLib(libName);
|
||||
});
|
||||
});
|
||||
})(jQuery);
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
/*
|
||||
* mobile core unit tests
|
||||
*/
|
||||
|
||||
(function($){
|
||||
var mobilePage = undefined;
|
||||
module('jquery.mobile.core.js');
|
||||
|
||||
// NOTE important to use $.fn.one here to make sure library reloads don't fire
|
||||
// the event before the test check below
|
||||
$(document).one("mobileinit", function(){
|
||||
mobilePage = $.mobile.page;
|
||||
});
|
||||
|
||||
test( "mobile.page is available when mobile init is fired", function(){
|
||||
ok(mobilePage !== undefined, "$.mobile.page is defined");
|
||||
});
|
||||
})(jQuery);
|
||||
|
|
@ -6,8 +6,8 @@
|
|||
|
||||
<script type="text/javascript" src="../../../js/jquery.js"></script>
|
||||
<script type="text/javascript" src="../../../external/qunit.js"></script>
|
||||
<script type="text/javascript" src="core_mobileinit.js"></script>
|
||||
<script type="text/javascript" src="../../../js/"></script>
|
||||
<!-- added explicitly for library reloading (see testHelper ) -->
|
||||
<script type="text/javascript" src="../../../js/jquery.mobile.core.js"></script>
|
||||
<script type="text/javascript" src="../../jquery.testHelper.js"></script>
|
||||
<link rel="stylesheet" href="../../../themes/default" />
|
||||
|
|
|
|||
32
tests/unit/init/index.html
Normal file
32
tests/unit/init/index.html
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>jQuery Mobile Init Test Suite</title>
|
||||
|
||||
<script type="text/javascript" src="../../../js/jquery.js"></script>
|
||||
<script type="text/javascript" src="../../../external/qunit.js"></script>
|
||||
<script type="text/javascript" src="../../jquery.testHelper.js"></script>
|
||||
<script type="text/javascript" src="init_core.js"></script>
|
||||
<script type="text/javascript" src="../../../js/"></script>
|
||||
<!-- added explicitly for library reloading (see testHelper ) -->
|
||||
<script type="text/javascript" src="../../../js/jquery.mobile.init.js"></script>
|
||||
<link rel="stylesheet" href="../../../themes/default" />
|
||||
<link rel="stylesheet" href="../../../external/qunit.css" type="text/css"/>
|
||||
|
||||
<script type="text/javascript" src="core.js"></script>
|
||||
<script type="text/javascript" src="core_scroll.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1 id="qunit-header">jQuery Mobile Init Test Suite</h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
<ol id="qunit-tests">
|
||||
</ol>
|
||||
|
||||
<div data-role="page">
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
125
tests/unit/init/init_core.js
Normal file
125
tests/unit/init/init_core.js
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
/*
|
||||
* mobile init tests
|
||||
*/
|
||||
|
||||
(function($){
|
||||
var mobilePage = undefined, mobileSelect = undefined,
|
||||
libName = 'jquery.mobile.init.js',
|
||||
setGradeA = function(value) { $.mobile.gradeA = function(){ return value; }; },
|
||||
extendFn = $.extend;
|
||||
|
||||
module(libName, {
|
||||
setup: function(){
|
||||
// NOTE reset for gradeA tests
|
||||
$('html').removeClass('ui-mobile');
|
||||
},
|
||||
teardown: function(){
|
||||
$.extend = extendFn;
|
||||
}
|
||||
});
|
||||
|
||||
// NOTE important to use $.fn.one here to make sure library reloads don't fire
|
||||
// the event before the test check below
|
||||
$(document).one("mobileinit", function(){
|
||||
mobilePage = $.mobile.page;
|
||||
mobileSelect = $.mobile.selectmenu;
|
||||
});
|
||||
|
||||
test( "mobile.page is available when mobile init is fired", function(){
|
||||
ok(mobilePage !== undefined, "$.mobile.page is defined");
|
||||
});
|
||||
|
||||
test( "mobile.selectmenu is available when mobile init is fired", function(){
|
||||
ok(mobileSelect !== undefined, "$.mobile.selectmenu is defined");
|
||||
});
|
||||
|
||||
$.testHelper.excludeFileProtocol(function(){
|
||||
test( "loading the init library triggers mobilinit on the document", function(){
|
||||
expect( 1 );
|
||||
|
||||
$(window.document).bind('mobileinit', function(event){
|
||||
ok(true);
|
||||
});
|
||||
|
||||
$.testHelper.reloadLib(libName);
|
||||
});
|
||||
|
||||
test( "enhancments are skipped when the browser is not grade A", function(){
|
||||
setGradeA(false);
|
||||
$.testHelper.reloadLib(libName);
|
||||
|
||||
//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"));
|
||||
});
|
||||
|
||||
var metaViewportSelector = "head meta[name=viewport]",
|
||||
setViewPortContent = function(value){
|
||||
$(metaViewportSelector).remove();
|
||||
$.mobile.metaViewportContent = value;
|
||||
$.testHelper.reloadLib( libName );
|
||||
};
|
||||
|
||||
test( "meta view port element not added to head when not defined on mobile", function(){
|
||||
setViewPortContent(false);
|
||||
same($(metaViewportSelector).length, 0);
|
||||
});
|
||||
|
||||
test( "meta view port element is added to head when defined on mobile", function(){
|
||||
setViewPortContent("width=device-width");
|
||||
same($(metaViewportSelector).length, 1);
|
||||
});
|
||||
|
||||
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.firstPage, 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(){
|
||||
$.testHelper.alterExtend({ pageLoading: function(){
|
||||
start();
|
||||
ok("called");
|
||||
}});
|
||||
|
||||
stop();
|
||||
$.testHelper.reloadLib(libName);
|
||||
});
|
||||
|
||||
test( "hashchange triggered on document ready with single argument: true", function(){
|
||||
$(window).bind("hashchange", function(ev, arg){
|
||||
same(arg, true);
|
||||
start();
|
||||
});
|
||||
|
||||
stop();
|
||||
$.testHelper.reloadLib(libName);
|
||||
});
|
||||
});
|
||||
})(jQuery);
|
||||
Loading…
Reference in a new issue