From 020f4b7db6d87174059f252f98e93155cffa1f3e Mon Sep 17 00:00:00 2001 From: John Bender Date: Mon, 16 Jan 2012 16:20:07 -0800 Subject: [PATCH] seperate transition tests, whitespace --- tests/unit/navigation/index.html | 1 - .../unit/navigation/navigation_transitions.js | 90 +++--- tests/unit/navigation/transition-tests.html | 285 ++++++++++++++++++ 3 files changed, 334 insertions(+), 42 deletions(-) create mode 100644 tests/unit/navigation/transition-tests.html diff --git a/tests/unit/navigation/index.html b/tests/unit/navigation/index.html index 8b14d037..dd2bc7ae 100644 --- a/tests/unit/navigation/index.html +++ b/tests/unit/navigation/index.html @@ -17,7 +17,6 @@ - diff --git a/tests/unit/navigation/navigation_transitions.js b/tests/unit/navigation/navigation_transitions.js index e2c304cc..029d1885 100644 --- a/tests/unit/navigation/navigation_transitions.js +++ b/tests/unit/navigation/navigation_transitions.js @@ -19,11 +19,11 @@ isTransitioningIn = function(page){ return page.hasClass("in") && isTransitioning(page); }, - + disableMaxTransWidth = function(){ $.mobile.maxTransitionWidth = false; }, - + enableMaxTransWidth = function(){ $.mobile.maxTransitionWidth = defaultMaxTrans; }, @@ -36,15 +36,15 @@ fromQueue = []; toQueue = []; }, - + onFromComplete = function( f ){ fromQueue.push( f ); }, - + onToComplete = function( f ){ toQueue.push( f ); }, - + //wipe all urls clearUrlHistory = function(){ @@ -55,9 +55,11 @@ module('jquery.mobile.navigation.js', { setup: function(){ + + // disable this option so we can test transitions regardless of window width disableMaxTransWidth(); - + //stub to allow callback before function is returned to transition handler $.fn.animationComplete = function( callback ){ animationCompleteFn.call( this, function(){ @@ -72,6 +74,17 @@ resetQueues(); clearUrlHistory(); + + if ( location.hash !== "#harmless-default-page" ) { + stop(); + + $(document).one("pagechange", function() { + start(); + } ); + + location.hash = "#harmless-default-page"; + } + }, teardown: function(){ @@ -80,52 +93,51 @@ enableMaxTransWidth(); } }); - - /* - NOTES: - Our default transition handler now has either one or two animationComplete calls - two if there are two pages in play (from and to) + + /* + NOTES: + Our default transition handler now has either one or two animationComplete calls - two if there are two pages in play (from and to) To is required, so each async function must call start() onToComplete, not onFromComplete. */ - + asyncTest( "changePage applies perspective class to mobile viewport for flip", function(){ expect(1); - + onToComplete( function( el ){ ok($("body").hasClass(perspective), "has perspective class"); start(); } ); - - $("#foo > a").click(); + $("#foo > a").click(); }); - + asyncTest( "changePage does not apply perspective class to mobile viewport for transitions other than flip", function(){ expect(1); - + onToComplete( function( el ){ ok(!$("body").hasClass(perspective), "doesn't have perspective class"); start(); } ); - + $("#bar > a").click(); }); - + asyncTest( "changePage applies transition class to mobile viewport for default transition", function(){ expect(1); - + onToComplete( function( el ){ ok($("body").hasClass(transitioning), "has transitioning class"); start(); } ); - + $("#baz > a").click(); }); - + asyncTest( "explicit transition preferred for page navigation reversal (ie back)", function(){ expect( 1 ); - + onToComplete(function(){ $("#flip-trans > a").click(); onToComplete(function(){ @@ -136,7 +148,7 @@ }); }); }); - + $("#fade-trans > a").click(); }); @@ -145,7 +157,7 @@ ok($("#no-trans").hasClass("fade"), "has fade class"); start(); }) - + $("#default-trans > a").click(); }); @@ -164,7 +176,7 @@ ok(!isTransitioningIn(firstPage), "first page transition should be complete"); ok(isTransitioningIn(secondPage), "second page should begin transitioning"); start(); - + }); }); }); @@ -175,7 +187,7 @@ ok($("#no-trans-dialog").hasClass("pop"), "has pop class" ); start(); }); - + $("#default-trans-dialog > a").click(); }); @@ -183,39 +195,35 @@ $.fn.animationComplete = animationCompleteFn; equals($("#foo").animationComplete(function(){})[0], $("#foo")[0]); }); - - + + // reusable function for a few tests below function testTransitionMaxWidth( val, expected ){ expect( 1 ); - + $.mobile.maxTransitionWidth = val; - + var transitionOccurred = false; - + onToComplete(function(){ transitionOccurred = true; }); - - + + return setTimeout(function(){ ok( transitionOccurred === expected, (expected ? "" : "no ") + "transition occurred" ); start(); }, 5000); - + $.mobile.changePage( $(".ui-page:not(.ui-page-active)").first() ); - + } - + asyncTest( "maxTransitionWidth property disables transitions when value is less than browser width", function(){ testTransitionMaxWidth( $( window ).width() - 1, false ); }); - + asyncTest( "maxTransitionWidth property disables transitions when value is false", function(){ testTransitionMaxWidth( false, false ); }); - - - - })(jQuery); diff --git a/tests/unit/navigation/transition-tests.html b/tests/unit/navigation/transition-tests.html new file mode 100644 index 00000000..f537956f --- /dev/null +++ b/tests/unit/navigation/transition-tests.html @@ -0,0 +1,285 @@ + + + + + + jQuery Mobile Navigation Test Suite + + + + + + + + + + + + + + + + +

jQuery Mobile Navigation Test Suite

+

+

+
    +
+ +
+
+ +
+ + +
+ +
+ Prefetch test +
+ +
+
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+
+
+ +
+
+ +
+
+
+ +
+ +
+ +
+
+ +
+ + Page 2 + +
+ +
+ + Page 1 + + Dialog +
+ +
+
+

Dialog

+
+
+ +
+
+ Dialog +
+
+ +
+
+ Page 2 +
+
+ +
+ Go Back +
+ + +
+
+ Dialog +
+
+ +
+
+ Dialog 2 +
+
+ +
+
+ +
+
+ second page +
+
+ +
+
+ file path page +
+
+ +
+ test + test + test +
+ +
+

Title Heading

+
+ +
+

Title Heading

+
+ + + + + +
+ + go + go + go + go + go + go + + + + go + go + go + go + go + go + + + + go + go + go + go + go + go + + + + go + go + go + go + go + go + +
+ +
+
page didn't change!
+
+ +
+
+
+ + +
+ External page containing form with no action. +
+
+ +
+
+ page2 +
+
+ +
+
+ href button + back button +
+
+ + + +
+ foo +
+ +
+ + + +
+ + static link + +
+ +