2 * mobile navigation base tag unit tests
5 var baseDir = $.mobile.path.parseUrl($("base").attr("href")).directory,
6 contentDir = $.mobile.path.makePathAbsolute("../content/", baseDir),
7 home = location.pathname + location.search;
9 module('jquery.mobile.navigation.js - base tag', {
11 if ( location.hash ) {
13 $(document).one("pagechange", function() {
21 asyncTest( "can navigate between internal and external pages", function(){
22 $.testHelper.pageSequence([
24 // Navigate from default internal page to another internal page.
25 $.testHelper.openPage( "#internal-page-2" );
29 // Verify that we are on the 2nd internal page.
30 $.testHelper.assertUrlLocation({
31 push: home + "#internal-page-2",
32 hash: "internal-page-2",
33 report: "navigate to internal page"
36 // Navigate to a page that is in the base directory. Note that the application
37 // document and this new page are *NOT* in the same directory.
38 $("#internal-page-2 .bp1").click();
42 // Verify that we are on the expected page.
43 $.testHelper.assertUrlLocation({
44 hashOrPush: baseDir + "base-page-1.html",
45 report: "navigate from internal page to page in base directory"
48 // Navigate to another page in the same directory as the current page.
49 $("#base-page-1 .bp2").click();
53 // Verify that we are on the expected page.
54 $.testHelper.assertUrlLocation({
55 hashOrPush: baseDir + "base-page-2.html",
56 report: "navigate from base directory page to another base directory page"
59 // Navigate to another page in a directory that is the sibling of the base.
60 $("#base-page-2 .cp1").click();
64 // Verify that we are on the expected page.
65 $.testHelper.assertUrlLocation({
66 hashOrPush: contentDir + "content-page-1.html",
67 report: "navigate from base directory page to a page in a different directory hierarchy"
70 // Navigate to another page in a directory that is the sibling of the base.
71 $("#content-page-1 .cp2").click();
75 // Verify that we are on the expected page.
76 $.testHelper.assertUrlLocation({
77 hashOrPush: contentDir + "content-page-2.html",
78 report: "navigate to another page within the same non-base directory hierarchy"
81 // Navigate to an internal page.
82 $("#content-page-2 .ip1").click();
86 // Verify that we are on the expected page.
87 // the hash based nav result (hash:) is dictate by the fact that #internal-page-1
88 // is the original root page element
89 $.testHelper.assertUrlLocation({
91 report: "navigate from a page in a non-base directory to an internal page"
94 // Try calling changePage() directly with a relative path.
95 $.mobile.changePage("base-page-1.html");
99 // Verify that we are on the expected page.
100 $.testHelper.assertUrlLocation({
101 hashOrPush: baseDir + "base-page-1.html",
102 report: "call changePage() with a filename (no path)"
105 // Try calling changePage() directly with a relative path.
106 $.mobile.changePage("../content/content-page-1.html");
110 // Verify that we are on the expected page.
111 $.testHelper.assertUrlLocation({
112 hashOrPush: contentDir + "content-page-1.html",
113 report: "call changePage() with a relative path containing up-level references"
116 // Try calling changePage() with an id
117 $.mobile.changePage("content-page-2.html");
121 // Verify that we are on the expected page.
122 $.testHelper.assertUrlLocation({
123 hashOrPush: contentDir + "content-page-2.html",
124 report: "call changePage() with a relative path should resolve relative to current page"
127 // test that an internal page works
132 // Verify that we are on the expected page.
133 $.testHelper.assertUrlLocation({
134 hash: "internal-page-2",
135 push: home + "#internal-page-2",
136 report: "call changePage() with a page id"
139 // Try calling changePage() with an id
140 $.mobile.changePage("internal-page-1");
144 // Verify that we are on the expected page.
145 $.testHelper.assertUrlLocation({
146 hash: "internal-page-2",
147 push: home + "#internal-page-2",
148 report: "calling changePage() with a page id that is not prefixed with '#' should not change page"
151 // Previous load should have failed and left us on internal-page-2.
157 asyncTest( "internal form with no action submits to document URL", function(){
158 $.testHelper.pageSequence([
159 // open our test page
161 $.testHelper.openPage( "#internal-no-action-form-page" );
165 $( "#internal-no-action-form-page form" ).eq( 0 ).submit();
169 $.testHelper.assertUrlLocation({
170 hashOrPush: location.pathname + "?foo=1&bar=2",
171 report: "hash should match document url and not base url"
179 asyncTest( "external page form with no action submits to external page URL", function(){
180 $.testHelper.pageSequence([
182 // Go to an external page that has a form.
183 $("#internal-page-1 .cp1").click();
187 // Make sure we actually navigated to the external page.
188 $.testHelper.assertUrlLocation({
189 hashOrPush: contentDir + "content-page-1.html",
190 report: "should be on content-page-1.html"
193 // Now submit the form in the external page.
194 $("#content-page-1 form").eq(0).submit();
198 $.testHelper.assertUrlLocation({
199 hashOrPush: contentDir + "content-page-1.html?foo=1&bar=2",
200 report: "hash should match page url and not document url"