jquery-mobile/tests/unit/navigation/navigation_base.js

155 lines
5 KiB
JavaScript

/*
* mobile navigation base tag unit tests
*/
(function($){
var baseDir = $.mobile.path.parseUrl($("base").attr("href")).directory,
contentDir = $.mobile.path.makePathAbsolute("../content/", baseDir);
module('jquery.mobile.navigation.js - base tag', {
setup: function(){
if ( location.hash ) {
stop();
$(document).one("changepage", function() {
start();
} );
location.hash = "";
}
}
});
asyncTest( "can navigate between internal and external pages", function(){
$.testHelper.pageSequence([
function(){
// Navigate from default internal page to another internal page.
$.testHelper.openPage("#internal-page-2");
},
function(){
// Verify that we are on the 2nd internal page.
same(location.hash, "#internal-page-2", "navigate to internal page");
// Navigate to a page that is in the base directory. Note that the application
// document and this new page are *NOT* in the same directory.
$("#internal-page-2 .bp1").click();
},
function(){
// Verify that we are on the expected page.
same(location.hash, "#" + baseDir + "base-page-1.html", "navigate from internal page to page in base directory");
// Navigate to another page in the same directory as the current page.
$("#base-page-1 .bp2").click();
},
function(){
// Verify that we are on the expected page.
same(location.hash, "#" + baseDir + "base-page-2.html", "navigate from base directory page to another base directory page");
// Navigate to another page in a directory that is the sibling of the base.
$("#base-page-2 .cp1").click();
},
function(){
// Verify that we are on the expected page.
same(location.hash, "#" + contentDir + "content-page-1.html", "navigate from base directory page to a page in a different directory hierarchy");
// Navigate to another page in a directory that is the sibling of the base.
$("#content-page-1 .cp2").click();
},
function(){
// Verify that we are on the expected page.
same(location.hash, "#" + contentDir + "content-page-2.html", "navigate to another page within the same non-base directory hierarchy");
// Navigate to an internal page.
$("#content-page-2 .ip1").click();
},
function(){
// Verify that we are on the expected page.
same(location.hash, "#internal-page-1", "navigate from a page in a non-base directory to an internal page");
// Try calling changePage() directly with a relative path.
$.mobile.changePage("base-page-1.html");
},
function(){
// Verify that we are on the expected page.
same(location.hash, "#" + baseDir + "base-page-1.html", "call changePage() with a filename (no path)");
// Try calling changePage() directly with a relative path.
$.mobile.changePage("../content/content-page-1.html");
},
function(){
// Verify that we are on the expected page.
same(location.hash, "#" + contentDir + "content-page-1.html", "call changePage() with a relative path containing up-level references");
// Try calling changePage() with an id
$.mobile.changePage("content-page-2.html");
},
function(){
// Verify that we are on the expected page.
same(location.hash, "#" + contentDir + "content-page-2.html", "call changePage() with a relative path should resolve relative to current page");
// test that an internal page works
$("a.ip2").click();
},
function(){
// Verify that we are on the expected page.
same(location.hash, "#internal-page-2", "call changePage() with a page id");
// Try calling changePage() with an id
$.mobile.changePage("internal-page-1");
},
function(){
// Previous load should have failed and left us on internal-page-2.
same(location.hash, "#internal-page-2", "calling changePage() with a page id that is not prefixed with '#' should not change page");
start();
}]);
});
asyncTest( "internal form with no action submits to document URL", function(){
$.testHelper.pageSequence([
// open our test page
function(){
$.testHelper.openPage("#internal-no-action-form-page");
},
function(){
$("#internal-no-action-form-page form").eq(0).submit();
},
function(){
same(location.hash, "#" + location.pathname + "?foo=1&bar=2", "hash should match document url and not base url");
start();
}
]);
});
asyncTest( "external page form with no action submits to external page URL", function(){
$.testHelper.pageSequence([
function(){
// Go to an external page that has a form.
$("#internal-page-1 .cp1").click();
},
function(){
// Make sure we actually navigated to the external page.
same(location.hash, "#" + contentDir + "content-page-1.html", "should be on content-page-1.html");
// Now submit the form in the external page.
$("#content-page-1 form").eq(0).submit();
},
function(){
same(location.hash, "#" + contentDir + "content-page-1.html?foo=1&bar=2", "hash should match page url and not document url");
start();
}]);
});
})(jQuery);