Skip to content
Permalink
Browse files

Accordion: More tests.

  • Loading branch information
scottgonzalez committed Jan 25, 2011
1 parent 63c72ab commit 06d61f5f235f4869bc251ebd1e1e768c56297636
Showing with 94 additions and 25 deletions.
  1. +12 −0 tests/unit/accordion/accordion_core.js
  2. +82 −25 tests/unit/accordion/accordion_events.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();
@@ -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 ) );

0 comments on commit 06d61f5

Please sign in to comment.
You can’t perform that action at this time.