From 06d61f5f235f4869bc251ebd1e1e768c56297636 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Scott=20Gonz=C3=A1lez?= Date: Mon, 24 Jan 2011 22:40:03 -0500 Subject: [PATCH] Accordion: More tests. --- tests/unit/accordion/accordion_core.js | 12 +++ 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 ) ); -- 2.39.5