jquery-ui/tests/unit/accordion/accordion_core.js

49 lines
2.3 KiB
JavaScript
Raw Normal View History

2011-01-24 20:45:29 +00:00
(function( $ ) {
2011-08-04 13:53:13 +00:00
module( "accordion: core", accordion_setupTeardown() );
$.each( { div: "#list1", ul: "#navigation", dl: "#accordion-dl" }, function( type, selector ) {
test( "markup structure: " + type, function() {
expect( 4 );
2011-04-15 15:29:26 +00:00
var element = $( selector ).accordion();
ok( element.hasClass( "ui-accordion" ), "main element is .ui-accordion" );
equal( element.find( ".ui-accordion-header" ).length, 3,
".ui-accordion-header elements exist, correct number" );
2011-04-15 15:29:26 +00:00
equal( element.find( ".ui-accordion-content" ).length, 3,
".ui-accordion-content elements exist, correct number" );
deepEqual( element.find( ".ui-accordion-header" ).next().get(),
2011-04-15 15:29:26 +00:00
element.find( ".ui-accordion-content" ).get(),
"content panels come immediately after headers" );
});
2011-01-25 03:40:03 +00:00
});
2011-01-24 20:45:29 +00:00
test( "handle click on header-descendant", function() {
2011-06-13 18:51:13 +00:00
expect( 1 );
2011-04-15 15:29:26 +00:00
var element = $( "#navigation" ).accordion();
2011-01-24 20:45:29 +00:00
$( "#navigation h2:eq(1) a" ).click();
2011-04-15 15:29:26 +00:00
accordion_state( element, 0, 1, 0 );
});
2011-01-24 20:45:29 +00:00
test( "accessibility", function () {
expect( 13 );
2011-04-15 15:29:26 +00:00
var element = $( "#list1" ).accordion().accordion( "option", "active", 1 );
var headers = element.find( ".ui-accordion-header" );
2011-01-24 20:45:29 +00:00
equal( headers.eq( 1 ).attr( "tabindex" ), 0, "active header should have tabindex=0" );
equal( headers.eq( 0 ).attr( "tabindex" ), -1, "inactive header should have tabindex=-1" );
equal( element.attr( "role" ), "tablist", "main role" );
equal( headers.attr( "role" ), "tab", "tab roles" );
equal( headers.next().attr( "role" ), "tabpanel", "tabpanel roles" );
equal( headers.eq( 1 ).attr( "aria-expanded" ), "true", "active tab has aria-expanded" );
equal( headers.eq( 0 ).attr( "aria-expanded" ), "false", "inactive tab has aria-expanded" );
equal( headers.eq( 1 ).attr( "aria-selected" ), "true", "active tab has aria-selected" );
equal( headers.eq( 0 ).attr( "aria-selected" ), "false", "inactive tab has aria-selected" );
2011-04-15 15:29:26 +00:00
element.accordion( "option", "active", 0 );
equal( headers.eq( 0 ).attr( "aria-expanded" ), "true", "newly active tab has aria-expanded" );
equal( headers.eq( 1 ).attr( "aria-expanded" ), "false", "newly inactive tab has aria-expanded" );
equal( headers.eq( 0 ).attr( "aria-selected" ), "true", "active tab has aria-selected" );
equal( headers.eq( 1 ).attr( "aria-selected" ), "false", "inactive tab has aria-selected" );
});
2011-01-24 20:45:29 +00:00
}( jQuery ) );