jquery-mobile/tests/unit/navigation/navigation_transitions.js
2011-01-29 22:50:48 -08:00

86 lines
No EOL
2.2 KiB
JavaScript

/*
* mobile navigation unit tests
*/
(function($){
var perspective = "ui-mobile-viewport-perspective",
transitioning = "ui-mobile-viewport-transitioning",
animationCompleteFn = $.fn.animationComplete,
removeBodyClasses = function(){
$("body").removeClass([perspective, transitioning].join(" "));
},
removePageTransClasses = function(){
$("[data-role='page']").removeClass("in out fade slide flip reverse pop");
};
module('jquery.mobile.navigation.js', {
setup: function(){
//stub to prevent class removal
$.fn.animationComplete = function(){};
},
teardown: function(){
// unmock animation complete
$.fn.animationComplete = animationCompleteFn;
// required cleanup from animation complete mocking
removeBodyClasses();
}
});
test( "changePage applys perspective class to mobile viewport for flip", function(){
$("#foo > a").click();
ok($("body").hasClass(perspective), "has perspective class");
});
test( "changePage does not apply perspective class to mobile viewport for transitions other than flip", function(){
$("#bar > a").click();
ok(!$("body").hasClass(perspective), "doesn't have perspective class");
});
test( "changePage applys transition class to mobile viewport for default transition", function(){
$("#baz > a").click();
ok($("body").hasClass(transitioning), "has transitioning class");
});
test( "explicit transition preferred for page navigation reversal (ie back)", function(){
$.fn.animationComplete = function(){};
setTimeout(function(){
$("#fade-trans > a").click();
}, 300);
setTimeout(function(){
$("#flip-trans > a").click();
}, 600);
//guarantee that we check only the newest changes
removePageTransClasses();
$("#fade-trans > a").click();
stop();
setTimeout(function(){
ok($("#flip-trans").hasClass("fade"), "has fade class");
start();
}, 900);
});
test( "default transition is slide", function(){
//guarantee that we check only the newest changes
removePageTransClasses();
$("#default-trans > a").click();
stop();
setTimeout(function(){
ok($("#no-trans").hasClass("slide"), "has slide class");
start();
}, 900);
});
})(jQuery);