]> source.dussan.org Git - jquery-ui.git/commitdiff
Accordion: Added animation tests.
authorScott González <scott.gonzalez@gmail.com>
Tue, 27 Mar 2012 22:05:51 +0000 (18:05 -0400)
committerScott González <scott.gonzalez@gmail.com>
Tue, 27 Mar 2012 22:05:51 +0000 (18:05 -0400)
tests/unit/accordion/accordion_options.js

index 74a9a31771b23ff54856928a92ff28dba037c9ab..2b7176394339a642ad65e2d1d12eead5582c01e4 100644 (file)
@@ -75,7 +75,175 @@ if ( $.uiBackCompat === false ) {
        });
 }
 
-// TODO: add animation tests
+test( "{ animate: false }", function() {
+       expect( 3 );
+       var element = $( "#list1" ).accordion({
+                       animate: false
+               }),
+               panels = element.find( ".ui-accordion-content" );
+               animate = $.fn.animate;
+       $.fn.animate = function() {
+               ok( false, ".animate() called" );
+       };
+
+       ok( panels.eq( 0 ).is( ":visible" ), "first panel visible" );
+       element.accordion( "option", "active", 1 );
+       ok( panels.eq( 0 ).is( ":hidden" ), "first panel hidden" );
+       ok( panels.eq( 1 ).is( ":visible" ), "second panel visible" );
+       $.fn.animate = animate;
+});
+
+asyncTest( "{ animate: Number }", function() {
+       expect( 7 );
+       var element = $( "#list1" ).accordion({
+                       animate: 100
+               }),
+               panels = element.find( ".ui-accordion-content" );
+               animate = $.fn.animate;
+       // called twice (both panels)
+       $.fn.animate = function( props, duration, easing ) {
+               equal( duration, 100, "correct duration" );
+               equal( easing, undefined, "default easing" );
+               animate.apply( this, arguments );
+       };
+
+       ok( panels.eq( 0 ).is( ":visible" ), "first panel visible" );
+       element.accordion( "option", "active", 1 );
+       panels.promise().done(function() {
+               ok( panels.eq( 0 ).is( ":hidden" ), "first panel hidden" );
+               ok( panels.eq( 1 ).is( ":visible" ), "second panel visible" );
+               $.fn.animate = animate;
+               start();
+       });
+});
+
+asyncTest( "{ animate: String }", function() {
+       expect( 7 );
+       var element = $( "#list1" ).accordion({
+               animate: "linear"
+       }),
+       panels = element.find( ".ui-accordion-content" );
+       animate = $.fn.animate;
+       // called twice (both panels)
+       $.fn.animate = function( props, duration, easing ) {
+               equal( duration, undefined, "default duration" );
+               equal( easing, "linear", "correct easing" );
+               animate.apply( this, arguments );
+       };
+
+       ok( panels.eq( 0 ).is( ":visible" ), "first panel visible" );
+       element.accordion( "option", "active", 1 );
+       panels.promise().done(function() {
+               ok( panels.eq( 0 ).is( ":hidden" ), "first panel hidden" );
+               ok( panels.eq( 1 ).is( ":visible" ), "second panel visible" );
+               $.fn.animate = animate;
+               start();
+       });
+});
+
+asyncTest( "{ animate: {} }", function() {
+       expect( 7 );
+       var element = $( "#list1" ).accordion({
+               animate: {}
+       }),
+       panels = element.find( ".ui-accordion-content" );
+       animate = $.fn.animate;
+       // called twice (both panels)
+       $.fn.animate = function( props, duration, easing ) {
+               equal( duration, undefined, "default duration" );
+               equal( easing, undefined, "default easing" );
+               animate.apply( this, arguments );
+       };
+
+       ok( panels.eq( 0 ).is( ":visible" ), "first panel visible" );
+       element.accordion( "option", "active", 1 );
+       panels.promise().done(function() {
+               ok( panels.eq( 0 ).is( ":hidden" ), "first panel hidden" );
+               ok( panels.eq( 1 ).is( ":visible" ), "second panel visible" );
+               $.fn.animate = animate;
+               start();
+       });
+});
+
+asyncTest( "{ animate: { duration, easing } }", function() {
+       expect( 7 );
+       var element = $( "#list1" ).accordion({
+               animate: { duration: 100, easing: "linear" }
+       }),
+       panels = element.find( ".ui-accordion-content" );
+       animate = $.fn.animate;
+       // called twice (both panels)
+       $.fn.animate = function( props, duration, easing ) {
+               equal( duration, 100, "correct duration" );
+               equal( easing, "linear", "correct easing" );
+               animate.apply( this, arguments );
+       };
+
+       ok( panels.eq( 0 ).is( ":visible" ), "first panel visible" );
+       element.accordion( "option", "active", 1 );
+       panels.promise().done(function() {
+               ok( panels.eq( 0 ).is( ":hidden" ), "first panel hidden" );
+               ok( panels.eq( 1 ).is( ":visible" ), "second panel visible" );
+               $.fn.animate = animate;
+               start();
+       });
+});
+
+asyncTest( "{ animate: { duration, easing } }, animate down", function() {
+       expect( 7 );
+       var element = $( "#list1" ).accordion({
+               active: 1,
+               animate: { duration: 100, easing: "linear" }
+       }),
+       panels = element.find( ".ui-accordion-content" );
+       animate = $.fn.animate;
+       // called twice (both panels)
+       $.fn.animate = function( props, duration, easing ) {
+               equal( duration, 100, "correct duration" );
+               equal( easing, "linear", "correct easing" );
+               animate.apply( this, arguments );
+       };
+
+       ok( panels.eq( 1 ).is( ":visible" ), "first panel visible" );
+       element.accordion( "option", "active", 0 );
+       panels.promise().done(function() {
+               ok( panels.eq( 1 ).is( ":hidden" ), "first panel hidden" );
+               ok( panels.eq( 0 ).is( ":visible" ), "second panel visible" );
+               $.fn.animate = animate;
+               start();
+       });
+});
+
+asyncTest( "{ animate: { duration, easing, down } }, animate down", function() {
+       expect( 7 );
+       var element = $( "#list1" ).accordion({
+               active: 1,
+               animate: {
+                       duration: 100,
+                       easing: "linear",
+                       down: {
+                               easing: "swing"
+                       }
+               }
+       }),
+       panels = element.find( ".ui-accordion-content" );
+       animate = $.fn.animate;
+       // called twice (both panels)
+       $.fn.animate = function( props, duration, easing ) {
+               equal( duration, 100, "correct duration" );
+               equal( easing, "swing", "correct easing" );
+               animate.apply( this, arguments );
+       };
+
+       ok( panels.eq( 1 ).is( ":visible" ), "first panel visible" );
+       element.accordion( "option", "active", 0 );
+       panels.promise().done(function() {
+               ok( panels.eq( 1 ).is( ":hidden" ), "first panel hidden" );
+               ok( panels.eq( 0 ).is( ":visible" ), "second panel visible" );
+               $.fn.animate = animate;
+               start();
+       });
+});
 
 test( "{ collapsible: false }", function() {
        expect( 4 );