This repository has been archived by the owner on Oct 8, 2021. It is now read-only.
/
navigation_base.js
209 lines (176 loc) · 5.97 KB
/
navigation_base.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
* mobile navigation base tag unit tests
*/
(function($){
var baseDir = $.mobile.path.parseUrl($("base").attr("href")).directory,
contentDir = $.mobile.path.makePathAbsolute("../content/", baseDir),
home = location.pathname + location.search;
module('jquery.mobile.navigation.js - base tag', {
setup: function(){
if ( location.hash ) {
stop();
$(document).one("pagechange", 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.
$.testHelper.assertUrlLocation({
push: home + "#internal-page-2",
hash: "internal-page-2",
report: "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.
$.testHelper.assertUrlLocation({
hashOrPush: baseDir + "base-page-1.html",
report: "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.
$.testHelper.assertUrlLocation({
hashOrPush: baseDir + "base-page-2.html",
report: "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.
$.testHelper.assertUrlLocation({
hashOrPush: contentDir + "content-page-1.html",
report: "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.
$.testHelper.assertUrlLocation({
hashOrPush: contentDir + "content-page-2.html",
report: "navigate to another page within the same non-base directory hierarchy"
});
// Navigate to an internal page.
console.log( $("#content-page-2 .ip1") );
window.foo = true;
$("#content-page-2 .ip1").click();
},
function(){
window.foo = false;
// Verify that we are on the expected page.
// the hash based nav result (hash:) is dictate by the fact that #internal-page-1
// is the original root page element
$.testHelper.assertUrlLocation({
hashOrPush: home,
report: "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.
$.testHelper.assertUrlLocation({
hashOrPush: baseDir + "base-page-1.html",
report: "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.
$.testHelper.assertUrlLocation({
hashOrPush: contentDir + "content-page-1.html",
report: "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.
$.testHelper.assertUrlLocation({
hashOrPush: contentDir + "content-page-2.html",
report: "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.
$.testHelper.assertUrlLocation({
hash: "internal-page-2",
push: home + "#internal-page-2",
report: "call changePage() with a page id"
});
// Try calling changePage() with an id
$.mobile.changePage("internal-page-1");
},
function(){
// Verify that we are on the expected page.
$.testHelper.assertUrlLocation({
hash: "internal-page-2",
push: home + "#internal-page-2",
report: "calling changePage() with a page id that is not prefixed with '#' should not change page"
});
// Previous load should have failed and left us on internal-page-2.
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(){
$.testHelper.assertUrlLocation({
hashOrPush: location.pathname + "?foo=1&bar=2",
report: "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.
$.testHelper.assertUrlLocation({
hashOrPush: contentDir + "content-page-1.html",
report: "should be on content-page-1.html"
});
// Now submit the form in the external page.
$("#content-page-1 form").eq(0).submit();
},
function(){
$.testHelper.assertUrlLocation({
hashOrPush: contentDir + "content-page-1.html?foo=1&bar=2",
report: "hash should match page url and not document url"
});
start();
}]);
});
})(jQuery);