From: Scott González Date: Tue, 27 Mar 2012 22:05:51 +0000 (-0400) Subject: Accordion: Added animation tests. X-Git-Tag: 1.9m7~1 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4a6692a57aa156dcaa916af66b36f767a25e37c3;p=jquery-ui.git Accordion: Added animation tests. --- diff --git a/tests/unit/accordion/accordion_options.js b/tests/unit/accordion/accordion_options.js index 74a9a3177..2b7176394 100644 --- a/tests/unit/accordion/accordion_options.js +++ b/tests/unit/accordion/accordion_options.js @@ -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 );