Skip to content

Commit

Permalink
Added unit tests for issue jquery-archive#2835 - pagechangefailed not…
Browse files Browse the repository at this point in the history
… triggered when changing to non-existent internal page.
  • Loading branch information
jblas committed Oct 26, 2011
1 parent b69215c commit b71c974
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/unit/navigation/index.html
Expand Up @@ -39,6 +39,7 @@ <h2 id="qunit-userAgent"></h2>

<div id="foo" data-nstest-role="page" class="foo-class">
<a href="#bar" data-nstest-transition="flip"></a>
<a id="bad-internal-page-link" href="#non-existent-page"></a>
</div>

<div id="prefetch" data-nstest-role="page">
Expand Down
45 changes: 45 additions & 0 deletions tests/unit/navigation/navigation_core.js
Expand Up @@ -980,6 +980,51 @@
]);
});

asyncTest( "navigate to non-existent internal page throws pagechangefailed", function(){
var pagechangefailed = false,
pageChangeFailedCB = function( e ) {
pagechangefailed = true;
}

$( document ).bind( "pagechangefailed", pageChangeFailedCB );

$.testHelper.pageSequence([
// open our test page
function(){
// Make sure there's only one copy of the first-page in the DOM to begin with.
ok( $.mobile.firstPage.hasClass( "first-page" ), "first page has expected class" );
same( $( ".first-page" ).length, 1, "first page was not duplicated" );

// Navigate to any page except the first page of the application.
$.testHelper.openPage("#foo");
},

function(){
var $foo = $( "#foo" );
ok( $.mobile.activePage[ 0 ] === $foo[ 0 ], "navigated successfully to #foo" );
same( pagechangefailed, false, "no page change failures" );

// Now navigate to a non-existent page.
$foo.find( "#bad-internal-page-link" ).click();
},

function(){
// Make sure a pagechangefailed event was triggered.
same( pagechangefailed, true, "pagechangefailed dispatched" );

// Make sure we didn't navigate away from #foo.
ok( $.mobile.activePage[ 0 ] === $( "#foo" )[ 0 ], "did not navigate away from #foo" );

// Now make sure opening the page didn't result in page duplication.
same( $( ".first-page" ).length, 1, "first page was not duplicated" );

$( document ).unbind( "pagechangefailed", pageChangeFailedCB );

start();
}
]);
});

asyncTest( "prefetched links with data rel dialog result in a dialog", function() {
$.testHelper.pageSequence([
// open our test page
Expand Down

0 comments on commit b71c974

Please sign in to comment.