Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit 2cfacc4

Browse files
committed
Changes to get the navigation_core and navigation_helpers tests to pass again:
- Modified changePage() click test so that it expects changePage() to be called twice. - Added changePage() test that makes sure it is called once when it is invoked with a page element instead of a URL. - Added siteDirectory path to be used with some tests which assumed that the tests directory was at the top-level of the server site.
1 parent 5ba2cc9 commit 2cfacc4

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

tests/unit/navigation/navigation_core.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
*/
44
(function($){
55
var changePageFn = $.mobile.changePage,
6-
originalTitle = document.title;
6+
originalTitle = document.title,
7+
siteDirectory = location.pathname.replace(/[^/]+$/, "");
78
module('jquery.mobile.navigation.js', {
89
setup: function(){
910
$.mobile.urlHistory.stack = [];
@@ -14,7 +15,7 @@
1415
}
1516
});
1617

17-
asyncTest( "changepage will only run once when a new page is visited", function(){
18+
asyncTest( "changepage runs once when called with an element", function(){
1819
var called = 0,
1920
newChangePage = function(a,b,c,d,e){
2021
changePageFn( a,b,c,d,e );
@@ -25,11 +26,33 @@
2526
// avoid initial page load triggering changePage early
2627
function(){
2728
$.mobile.changePage = newChangePage;
28-
$('#foo a').click();
29+
newChangePage($("#bar"));
2930
},
3031

3132
function(){
3233
ok(called == 1, "change page should be called once");
34+
$.mobile.changePage = changePageFn;
35+
start();
36+
}], 500);
37+
});
38+
39+
asyncTest( "changepage runs twice when triggered by a link", function(){
40+
var called = 0,
41+
newChangePage = function(a,b,c,d,e){
42+
changePageFn( a,b,c,d,e );
43+
called ++;
44+
};
45+
46+
$.testHelper.sequence([
47+
// avoid initial page load triggering changePage early
48+
function(){
49+
$.mobile.changePage = newChangePage;
50+
$('#foo a').click();
51+
},
52+
53+
function(){
54+
ok(called == 2, "change page should be called twice");
55+
$.mobile.changePage = changePageFn;
3356
start();
3457
}], 500);
3558
});
@@ -166,7 +189,7 @@
166189
};
167190

168191
test( "when loading a page where data-url is not defined on a sub element hash defaults to the url", function(){
169-
testDataUrlHash("#non-data-url a", new RegExp("^#/tests/unit/navigation/data-url-tests/non-data-url.html$"));
192+
testDataUrlHash("#non-data-url a", new RegExp("^#" + siteDirectory + "data-url-tests/non-data-url.html$"));
170193
});
171194

172195
test( "data url works for nested paths", function(){

tests/unit/navigation/navigation_helpers.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* mobile navigation unit tests
33
*/
44
(function($){
5+
var siteDirectory = location.pathname.replace(/[^/]+$/, "");
6+
57
module('jquery.mobile.navigation.js', {
68
setup: function(){
79
location.hash = "";
@@ -40,16 +42,16 @@
4042
same( $.mobile.path.makeAbsolute("test.html"), "bar/test.html", "prefixes path with absolute base path from hash");
4143

4244
$.mobile.path.set("bar");
43-
same( $.mobile.path.makeAbsolute("test.html"), "/tests/unit/navigation/test.html", "returns the absolute path unaltered ignoring non path hash");
45+
same( $.mobile.path.makeAbsolute("test.html"), siteDirectory + "test.html", "returns the absolute path unaltered ignoring non path hash");
4446

4547
$.mobile.path.set("bar/bing/bang");
4648
same( $.mobile.path.makeAbsolute("?foo=bar&bak=baz"), "bar/bing/bang?foo=bar&bak=baz", "appends query string paths to current path");
4749

4850
$.mobile.path.set("");
49-
same( $.mobile.path.makeAbsolute("?foo=bar&bak=baz"), "/tests/unit/navigation/?foo=bar&bak=baz", "uses pathname for empty hash");
51+
same( $.mobile.path.makeAbsolute("?foo=bar&bak=baz"), siteDirectory + "?foo=bar&bak=baz", "uses pathname for empty hash");
5052

5153
$.mobile.path.set("bar");
52-
same( $.mobile.path.makeAbsolute("?foo=bar&bak=baz"), "/tests/unit/navigation/?foo=bar&bak=baz", "uses pathname for embedded pages");
54+
same( $.mobile.path.makeAbsolute("?foo=bar&bak=baz"), siteDirectory + "?foo=bar&bak=baz", "uses pathname for embedded pages");
5355

5456
$.mobile.path.set("bar/bing?foo=bar");
5557
same( $.mobile.path.makeAbsolute("?foo=bar&bak=baz"), "bar/bing?foo=bar&bak=baz", "prevents addition of many sets of query params");

0 commit comments

Comments
 (0)