2 * mobile navigation base tag unit tests
5 var baseDir = $.mobile.path.parseUrl($("base").attr("href")).directory,
6 contentDir = $.mobile.path.makePathAbsolute("../content/", baseDir);
8 module('jquery.mobile.navigation.js - base tag', {
10 if ( location.hash ) {
12 $(document).one("pagechange", function() {
20 asyncTest( "can navigate between internal and external pages", function(){
21 $.testHelper.pageSequence([
23 // Navigate from default internal page to another internal page.
24 $.testHelper.openPage( "#internal-page-2" );
28 // Verify that we are on the 2nd internal page.
29 $.testHelper.assertUrlLocation({
30 push: location.pathname + "#internal-page-2",
31 hash: "internal-page-2",
32 report: "navigate to internal page"
35 // Navigate to a page that is in the base directory. Note that the application
36 // document and this new page are *NOT* in the same directory.
37 $("#internal-page-2 .bp1").click();
41 // Verify that we are on the expected page.
42 $.testHelper.assertUrlLocation({
43 hashOrPush: baseDir + "base-page-1.html",
44 report: "navigate from internal page to page in base directory"
47 // Navigate to another page in the same directory as the current page.
48 $("#base-page-1 .bp2").click();
52 // Verify that we are on the expected page.
53 $.testHelper.assertUrlLocation({
54 hashOrPush: baseDir + "base-page-2.html",
55 report: "navigate from base directory page to another base directory page"
58 // Navigate to another page in a directory that is the sibling of the base.
59 $("#base-page-2 .cp1").click();
63 // Verify that we are on the expected page.
64 $.testHelper.assertUrlLocation({
65 hashOrPush: contentDir + "content-page-1.html",
66 report: "navigate from base directory page to a page in a different directory hierarchy"
69 // Navigate to another page in a directory that is the sibling of the base.
70 $("#content-page-1 .cp2").click();
74 // Verify that we are on the expected page.
75 $.testHelper.assertUrlLocation({
76 hashOrPush: contentDir + "content-page-2.html",
77 report: "navigate to another page within the same non-base directory hierarchy"
80 // Navigate to an internal page.
81 $("#content-page-2 .ip1").click();
85 // Verify that we are on the expected page.
86 // the hash based nav result (hash:) is dictate by the fact that #internal-page-1
87 // is the original root page element
88 $.testHelper.assertUrlLocation({
89 hashOrPush: location.pathname + location.search,
90 report: "navigate from a page in a non-base directory to an internal page"
93 // Try calling changePage() directly with a relative path.
94 $.mobile.changePage("base-page-1.html");
98 // Verify that we are on the expected page.
99 $.testHelper.assertUrlLocation({
100 hashOrPush: baseDir + "base-page-1.html",
101 report: "call changePage() with a filename (no path)"
104 // Try calling changePage() directly with a relative path.
105 $.mobile.changePage("../content/content-page-1.html");
109 // Verify that we are on the expected page.
110 $.testHelper.assertUrlLocation({
111 hashOrPush: contentDir + "content-page-1.html",
112 report: "call changePage() with a relative path containing up-level references"
115 // Try calling changePage() with an id
116 $.mobile.changePage("content-page-2.html");
120 // Verify that we are on the expected page.
121 $.testHelper.assertUrlLocation({
122 hashOrPush: contentDir + "content-page-2.html",
123 report: "call changePage() with a relative path should resolve relative to current page"
126 // test that an internal page works
131 // Verify that we are on the expected page.
132 $.testHelper.assertUrlLocation({
133 hash: "internal-page-2",
134 push: location.pathname + "#internal-page-2",
135 report: "call changePage() with a page id"
138 // Try calling changePage() with an id
139 $.mobile.changePage("internal-page-1");
143 // Verify that we are on the expected page.
144 $.testHelper.assertUrlLocation({
145 hash: "internal-page-2",
146 push: location.pathname + "#internal-page-2",
147 report: "calling changePage() with a page id that is not prefixed with '#' should not change page"
150 // Previous load should have failed and left us on internal-page-2.
156 asyncTest( "internal form with no action submits to document URL", function(){
157 $.testHelper.pageSequence([
158 // open our test page
160 $.testHelper.openPage( "#internal-no-action-form-page" );
164 $( "#internal-no-action-form-page form" ).eq( 0 ).submit();
168 $.testHelper.assertUrlLocation({
169 hashOrPush: location.pathname + "?foo=1&bar=2",
170 report: "hash should match document url and not base url"
178 asyncTest( "external page form with no action submits to external page URL", function(){
179 $.testHelper.pageSequence([
181 // Go to an external page that has a form.
182 $("#internal-page-1 .cp1").click();
186 // Make sure we actually navigated to the external page.
187 $.testHelper.assertUrlLocation({
188 hashOrPush: contentDir + "content-page-1.html",
189 report: "should be on content-page-1.html"
192 // Now submit the form in the external page.
193 $("#content-page-1 form").eq(0).submit();
197 $.testHelper.assertUrlLocation({
198 hashOrPush: contentDir + "content-page-1.html?foo=1&bar=2",
199 report: "hash should match page url and not document url"