diff options
author | Scott González <scott.gonzalez@gmail.com> | 2011-01-24 22:40:03 -0500 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2011-01-24 22:40:03 -0500 |
commit | 06d61f5f235f4869bc251ebd1e1e768c56297636 (patch) | |
tree | e722a0e5e2ae470d4b5a52c2648bbbe147615d10 /tests/unit | |
parent | 63c72aba0d898289b4cb536cd34fee80c15087d1 (diff) | |
download | jquery-ui-06d61f5f235f4869bc251ebd1e1e768c56297636.tar.gz jquery-ui-06d61f5f235f4869bc251ebd1e1e768c56297636.zip |
Accordion: More tests.
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/accordion/accordion_core.js | 12 | ||||
-rw-r--r-- | tests/unit/accordion/accordion_events.js | 107 |
2 files changed, 94 insertions, 25 deletions
diff --git a/tests/unit/accordion/accordion_core.js b/tests/unit/accordion/accordion_core.js index 601d2ed44..24dc0146b 100644 --- a/tests/unit/accordion/accordion_core.js +++ b/tests/unit/accordion/accordion_core.js @@ -2,6 +2,18 @@ module( "accordion: core", accordionSetupTeardown() ); +test( "markup structure", function() { + var ac = $( "#navigation" ).accordion(); + ok( ac.hasClass( "ui-accordion" ), "main element is .ui-accordion" ); + equal( ac.find( ".ui-accordion-header" ).length, 3, + ".ui-accordion-header elements exist, correct number" ); + equal( ac.find( ".ui-accordion-content" ).length, 3, + ".ui-accordion-content elements exist, correct number" ); + same( ac.find( ".ui-accordion-header" ).next().get(), + ac.find( ".ui-accordion-content" ).get(), + "content panels come immediately after headers" ); +}); + test( "handle click on header-descendant", function() { var ac = $( "#navigation" ).accordion(); $( "#navigation h2:eq(1) a" ).click(); diff --git a/tests/unit/accordion/accordion_events.js b/tests/unit/accordion/accordion_events.js index e0dbe82eb..463a277d8 100644 --- a/tests/unit/accordion/accordion_events.js +++ b/tests/unit/accordion/accordion_events.js @@ -2,31 +2,88 @@ module( "accordion: events", accordionSetupTeardown() ); -// TODO: verify correct elements in ui properties -// TODO: add tests for switching between active panels (not collapsed) -// TODO: add tests for changestart -// TODO: move change/changestart to deprecated tests (add activate/beforeactivate) -test( "accordionchange event, open closed and close again", function() { - expect( 8 ); - $( "#list1" ) - .accordion({ - active: false, - collapsible: true - }) - .one( "accordionchange", function( event, ui ) { - equals( ui.oldHeader.size(), 0 ); - equals( ui.oldContent.size(), 0 ); - equals( ui.newHeader.size(), 1 ); - equals( ui.newContent.size(), 1 ); - }) - .accordion( "option", "active", 0 ) - .one( "accordionchange", function( event, ui ) { - equals( ui.oldHeader.size(), 1 ); - equals( ui.oldContent.size(), 1 ); - equals( ui.newHeader.size(), 0 ); - equals( ui.newContent.size(), 0 ); - }) - .accordion( "option", "active", false ); +test( "changestart", function() { + expect( 20 ); + var ac = $( "#list1" ).accordion({ + active: false, + collapsible: true + }); + var headers = ac.find( ".ui-accordion-header" ); + var content = ac.find( ".ui-accordion-content" ); + + ac.one( "accordionchangestart", function( event, ui ) { + equals( ui.oldHeader.size(), 0 ); + equals( ui.oldContent.size(), 0 ); + equals( ui.newHeader.size(), 1 ); + strictEqual( ui.newHeader[ 0 ], headers[ 0 ] ); + equals( ui.newContent.size(), 1 ); + strictEqual( ui.newContent[ 0 ], content[ 0 ] ); + }); + ac.accordion( "option", "active", 0 ); + + ac.one( "accordionchangestart", function( event, ui ) { + equals( ui.oldHeader.size(), 1 ); + strictEqual( ui.oldHeader[ 0 ], headers[ 0 ] ); + equals( ui.oldContent.size(), 1 ); + strictEqual( ui.oldContent[ 0 ], content[ 0 ] ); + equals( ui.newHeader.size(), 1 ); + strictEqual( ui.newHeader[ 0 ], headers[ 1 ] ); + equals( ui.newContent.size(), 1 ); + strictEqual( ui.newContent[ 0 ], content[ 1 ] ); + }); + headers.eq( 1 ).click(); + + ac.one( "accordionchangestart", function( event, ui ) { + equals( ui.oldHeader.size(), 1 ); + strictEqual( ui.oldHeader[ 0 ], headers[ 1 ] ); + equals( ui.oldContent.size(), 1 ); + strictEqual( ui.oldContent[ 0 ], content[ 1 ] ); + equals( ui.newHeader.size(), 0 ); + equals( ui.newContent.size(), 0 ); + }); + ac.accordion( "option", "active", false ); +}); + +test( "change", function() { + expect( 20 ); + var ac = $( "#list1" ).accordion({ + active: false, + collapsible: true + }); + var headers = ac.find( ".ui-accordion-header" ); + var content = ac.find( ".ui-accordion-content" ); + + ac.one( "accordionchange", function( event, ui ) { + equals( ui.oldHeader.size(), 0 ); + equals( ui.oldContent.size(), 0 ); + equals( ui.newHeader.size(), 1 ); + strictEqual( ui.newHeader[ 0 ], headers[ 0 ] ); + equals( ui.newContent.size(), 1 ); + strictEqual( ui.newContent[ 0 ], content[ 0 ] ); + }); + ac.accordion( "option", "active", 0 ); + + ac.one( "accordionchange", function( event, ui ) { + equals( ui.oldHeader.size(), 1 ); + strictEqual( ui.oldHeader[ 0 ], headers[ 0 ] ); + equals( ui.oldContent.size(), 1 ); + strictEqual( ui.oldContent[ 0 ], content[ 0 ] ); + equals( ui.newHeader.size(), 1 ); + strictEqual( ui.newHeader[ 0 ], headers[ 1 ] ); + equals( ui.newContent.size(), 1 ); + strictEqual( ui.newContent[ 0 ], content[ 1 ] ); + }); + headers.eq( 1 ).click(); + + ac.one( "accordionchange", function( event, ui ) { + equals( ui.oldHeader.size(), 1 ); + strictEqual( ui.oldHeader[ 0 ], headers[ 1 ] ); + equals( ui.oldContent.size(), 1 ); + strictEqual( ui.oldContent[ 0 ], content[ 1 ] ); + equals( ui.newHeader.size(), 0 ); + equals( ui.newContent.size(), 0 ); + }); + ac.accordion( "option", "active", false ); }); }( jQuery ) ); |