Tabs: Shift to use no globals

This commit is contained in:
Amanpreet Singh 2016-04-06 19:18:50 +05:30
parent b5028f02bf
commit bfcd6358fe
5 changed files with 711 additions and 699 deletions

View File

@ -1,15 +1,16 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"./helper", "./helper",
"ui/widgets/tabs" "ui/widgets/tabs"
], function( $, testHelper ) { ], function( QUnit, $, testHelper ) {
var state = testHelper.state; var state = testHelper.state;
module( "tabs: core" ); QUnit.module( "tabs: core" );
test( "markup structure", function( assert ) { QUnit.test( "markup structure", function( assert ) {
expect( 20 ); assert.expect( 20 );
var element = $( "#tabs1" ).tabs(), var element = $( "#tabs1" ).tabs(),
tabList = element.find( "ul, ol" ), tabList = element.find( "ul, ol" ),
tabs = tabList.find( "li" ), tabs = tabList.find( "li" ),
@ -20,7 +21,7 @@ test( "markup structure", function( assert ) {
assert.hasClasses( element, "ui-tabs ui-widget ui-widget-content" ); assert.hasClasses( element, "ui-tabs ui-widget ui-widget-content" );
assert.lacksClasses( element, "ui-tabs-collapsible" ); assert.lacksClasses( element, "ui-tabs-collapsible" );
assert.hasClasses( tabList, "ui-tabs-nav ui-widget-header" ); assert.hasClasses( tabList, "ui-tabs-nav ui-widget-header" );
equal( tabList.length, 1, "The widget contains exactly one tab list" ); assert.equal( tabList.length, 1, "The widget contains exactly one tab list" );
assert.hasClasses( tabs[ 0 ], "ui-tabs-tab" ); assert.hasClasses( tabs[ 0 ], "ui-tabs-tab" );
assert.hasClasses( tabs[ 1 ], "ui-tabs-tab" ); assert.hasClasses( tabs[ 1 ], "ui-tabs-tab" );
assert.hasClasses( tabs[ 2 ], "ui-tabs-tab" ); assert.hasClasses( tabs[ 2 ], "ui-tabs-tab" );
@ -30,16 +31,16 @@ test( "markup structure", function( assert ) {
assert.hasClasses( tabs[ 1 ], "ui-tab" ); assert.hasClasses( tabs[ 1 ], "ui-tab" );
assert.hasClasses( tabs[ 2 ], "ui-tab" ); assert.hasClasses( tabs[ 2 ], "ui-tab" );
equal( tabs.length, 3, "There are exactly three tabs" ); assert.equal( tabs.length, 3, "There are exactly three tabs" );
assert.hasClasses( anchors[ 0 ], "ui-tabs-anchor" ); assert.hasClasses( anchors[ 0 ], "ui-tabs-anchor" );
assert.hasClasses( anchors[ 1 ], "ui-tabs-anchor" ); assert.hasClasses( anchors[ 1 ], "ui-tabs-anchor" );
assert.hasClasses( anchors[ 2 ], "ui-tabs-anchor" ); assert.hasClasses( anchors[ 2 ], "ui-tabs-anchor" );
equal( anchors.length, 3, "There are exactly 3 anchors" ); assert.equal( anchors.length, 3, "There are exactly 3 anchors" );
assert.hasClasses( active, "ui-tabs-active" ); assert.hasClasses( active, "ui-tabs-active" );
assert.hasClasses( panels[ 0 ], "ui-tabs-panel ui-widget-content" ); assert.hasClasses( panels[ 0 ], "ui-tabs-panel ui-widget-content" );
assert.hasClasses( panels[ 1 ], "ui-tabs-panel ui-widget-content" ); assert.hasClasses( panels[ 1 ], "ui-tabs-panel ui-widget-content" );
assert.hasClasses( panels[ 2 ], "ui-tabs-panel ui-widget-content" ); assert.hasClasses( panels[ 2 ], "ui-tabs-panel ui-widget-content" );
equal( panels.length, 3, "There are exactly 3 tab panels" ); assert.equal( panels.length, 3, "There are exactly 3 tab panels" );
} ); } );
$.each( { $.each( {
@ -48,8 +49,8 @@ $.each( {
"multiple lists, ol first": "#tabs5", "multiple lists, ol first": "#tabs5",
"empty list": "#tabs6" "empty list": "#tabs6"
}, function( type, selector ) { }, function( type, selector ) {
test( "markup structure: " + type, function( assert ) { QUnit.test( "markup structure: " + type, function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( selector ).tabs(); var element = $( selector ).tabs();
assert.hasClasses( element, "ui-tabs" ); assert.hasClasses( element, "ui-tabs" );
assert.hasClasses( $( selector + "-list" ), "ui-tabs-nav" ); assert.hasClasses( $( selector + "-list" ), "ui-tabs-nav" );
@ -57,50 +58,50 @@ $.each( {
} ); } );
// #5893 - Sublist in the tab list are considered as tab // #5893 - Sublist in the tab list are considered as tab
test( "nested list", function() { QUnit.test( "nested list", function( assert ) {
expect( 1 ); assert.expect( 1 );
var element = $( "#tabs6" ).tabs(); var element = $( "#tabs6" ).tabs();
equal( element.tabs( "instance" ).anchors.length, 2, "should contain 2 tab" ); assert.equal( element.tabs( "instance" ).anchors.length, 2, "should contain 2 tab" );
} ); } );
test( "disconnected from DOM", function() { QUnit.test( "disconnected from DOM", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( "#tabs1" ).remove().tabs(); var element = $( "#tabs1" ).remove().tabs();
equal( element.find( ".ui-tabs-nav" ).length, 1, "should initialize nav" ); assert.equal( element.find( ".ui-tabs-nav" ).length, 1, "should initialize nav" );
equal( element.find( ".ui-tabs-panel" ).length, 3, "should initialize panels" ); assert.equal( element.find( ".ui-tabs-panel" ).length, 3, "should initialize panels" );
} ); } );
test( "non-tab list items", function() { QUnit.test( "non-tab list items", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( "#tabs9" ).tabs(); var element = $( "#tabs9" ).tabs();
equal( element.tabs( "option", "active" ), 0, "defaults to first tab" ); assert.equal( element.tabs( "option", "active" ), 0, "defaults to first tab" );
equal( element.find( ".ui-tabs-nav li.ui-state-active" ).index(), 1, assert.equal( element.find( ".ui-tabs-nav li.ui-state-active" ).index(), 1,
"first actual tab is active" ); "first actual tab is active" );
} ); } );
test( "aria-controls", function() { QUnit.test( "aria-controls", function( assert ) {
expect( 7 ); assert.expect( 7 );
var element = $( "#tabs1" ).tabs(), var element = $( "#tabs1" ).tabs(),
tabs = element.find( ".ui-tabs-nav li" ); tabs = element.find( ".ui-tabs-nav li" );
tabs.each( function() { tabs.each( function() {
var tab = $( this ), var tab = $( this ),
anchor = tab.find( ".ui-tabs-anchor" ); anchor = tab.find( ".ui-tabs-anchor" );
equal( anchor.prop( "hash" ).substring( 1 ), tab.attr( "aria-controls" ) ); assert.equal( anchor.prop( "hash" ).substring( 1 ), tab.attr( "aria-controls" ) );
} ); } );
element = $( "#tabs2" ).tabs(); element = $( "#tabs2" ).tabs();
tabs = element.find( ".ui-tabs-nav li" ); tabs = element.find( ".ui-tabs-nav li" );
equal( tabs.eq( 0 ).attr( "aria-controls" ), "colon:test" ); assert.equal( tabs.eq( 0 ).attr( "aria-controls" ), "colon:test" );
equal( tabs.eq( 1 ).attr( "aria-controls" ), "inline-style" ); assert.equal( tabs.eq( 1 ).attr( "aria-controls" ), "inline-style" );
ok( /^ui-id-\d+$/.test( tabs.eq( 2 ).attr( "aria-controls" ) ), "generated id" ); assert.ok( /^ui-id-\d+$/.test( tabs.eq( 2 ).attr( "aria-controls" ) ), "generated id" );
equal( tabs.eq( 3 ).attr( "aria-controls" ), "custom-id" ); assert.equal( tabs.eq( 3 ).attr( "aria-controls" ), "custom-id" );
} ); } );
test( "accessibility", function() { QUnit.test( "accessibility", function( assert ) {
expect( 49 ); assert.expect( 49 );
var element = $( "#tabs1" ).tabs( { var element = $( "#tabs1" ).tabs( {
active: 1, active: 1,
disabled: [ 2 ] disabled: [ 2 ]
@ -109,76 +110,78 @@ test( "accessibility", function() {
anchors = tabs.find( ".ui-tabs-anchor" ), anchors = tabs.find( ".ui-tabs-anchor" ),
panels = element.find( ".ui-tabs-panel" ); panels = element.find( ".ui-tabs-panel" );
equal( element.find( ".ui-tabs-nav" ).attr( "role" ), "tablist", "tablist role" ); assert.equal( element.find( ".ui-tabs-nav" ).attr( "role" ), "tablist", "tablist role" );
tabs.each( function( index ) { tabs.each( function( index ) {
var tab = tabs.eq( index ), var tab = tabs.eq( index ),
anchor = anchors.eq( index ), anchor = anchors.eq( index ),
anchorId = anchor.attr( "id" ), anchorId = anchor.attr( "id" ),
panel = panels.eq( index ); panel = panels.eq( index );
equal( tab.attr( "role" ), "tab", "tab " + index + " role" ); assert.equal( tab.attr( "role" ), "tab", "tab " + index + " role" );
equal( tab.attr( "aria-labelledby" ), anchorId, "tab " + index + " aria-labelledby" ); assert.equal( tab.attr( "aria-labelledby" ), anchorId, "tab " + index + " aria-labelledby" );
equal( anchor.attr( "role" ), "presentation", "anchor " + index + " role" ); assert.equal( anchor.attr( "role" ), "presentation", "anchor " + index + " role" );
equal( anchor.attr( "tabindex" ), -1, "anchor " + index + " tabindex" ); assert.equal( anchor.attr( "tabindex" ), -1, "anchor " + index + " tabindex" );
equal( panel.attr( "role" ), "tabpanel", "panel " + index + " role" ); assert.equal( panel.attr( "role" ), "tabpanel", "panel " + index + " role" );
equal( panel.attr( "aria-labelledby" ), anchorId, "panel " + index + " aria-labelledby" ); assert.equal( panel.attr( "aria-labelledby" ), anchorId, "panel " + index + " aria-labelledby" );
} ); } );
equal( tabs.eq( 1 ).attr( "aria-selected" ), "true", "active tab has aria-selected=true" ); assert.equal( tabs.eq( 1 ).attr( "aria-selected" ), "true", "active tab has aria-selected=true" );
equal( tabs.eq( 1 ).attr( "tabindex" ), 0, "active tab has tabindex=0" ); assert.equal( tabs.eq( 1 ).attr( "tabindex" ), 0, "active tab has tabindex=0" );
equal( tabs.eq( 1 ).attr( "aria-disabled" ), null, "enabled tab does not have aria-disabled" ); assert.equal( tabs.eq( 1 ).attr( "aria-disabled" ), null, "enabled tab does not have aria-disabled" );
equal( tabs.eq( 1 ).attr( "aria-expanded" ), "true", "active tab has aria-expanded=true" ); assert.equal( tabs.eq( 1 ).attr( "aria-expanded" ), "true", "active tab has aria-expanded=true" );
equal( panels.eq( 1 ).attr( "aria-hidden" ), "false", "active panel has aria-hidden=false" ); assert.equal( panels.eq( 1 ).attr( "aria-hidden" ), "false", "active panel has aria-hidden=false" );
equal( tabs.eq( 0 ).attr( "aria-selected" ), "false", "inactive tab has aria-selected=false" ); assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "false", "inactive tab has aria-selected=false" );
equal( tabs.eq( 0 ).attr( "tabindex" ), -1, "inactive tab has tabindex=-1" ); assert.equal( tabs.eq( 0 ).attr( "tabindex" ), -1, "inactive tab has tabindex=-1" );
equal( tabs.eq( 0 ).attr( "aria-disabled" ), null, "enabled tab does not have aria-disabled" ); assert.equal( tabs.eq( 0 ).attr( "aria-disabled" ), null, "enabled tab does not have aria-disabled" );
equal( tabs.eq( 0 ).attr( "aria-expanded" ), "false", "inactive tab has aria-expanded=false" ); assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "false", "inactive tab has aria-expanded=false" );
equal( panels.eq( 0 ).attr( "aria-hidden" ), "true", "inactive panel has aria-hidden=true" ); assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "true", "inactive panel has aria-hidden=true" );
equal( tabs.eq( 2 ).attr( "aria-selected" ), "false", "inactive tab has aria-selected=false" ); assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "false", "inactive tab has aria-selected=false" );
equal( tabs.eq( 2 ).attr( "tabindex" ), -1, "inactive tab has tabindex=-1" ); assert.equal( tabs.eq( 2 ).attr( "tabindex" ), -1, "inactive tab has tabindex=-1" );
equal( tabs.eq( 2 ).attr( "aria-disabled" ), "true", "disabled tab has aria-disabled=true" ); assert.equal( tabs.eq( 2 ).attr( "aria-disabled" ), "true", "disabled tab has aria-disabled=true" );
equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "inactive tab has aria-expanded=false" ); assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "inactive tab has aria-expanded=false" );
equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "inactive panel has aria-hidden=true" ); assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "inactive panel has aria-hidden=true" );
element.tabs( "option", "active", 0 ); element.tabs( "option", "active", 0 );
equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "active tab has aria-selected=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "active tab has aria-selected=true" );
equal( tabs.eq( 0 ).attr( "tabindex" ), 0, "active tab has tabindex=0" ); assert.equal( tabs.eq( 0 ).attr( "tabindex" ), 0, "active tab has tabindex=0" );
equal( tabs.eq( 0 ).attr( "aria-disabled" ), null, "enabled tab does not have aria-disabled" ); assert.equal( tabs.eq( 0 ).attr( "aria-disabled" ), null, "enabled tab does not have aria-disabled" );
equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "active tab has aria-expanded=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "active tab has aria-expanded=true" );
equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "active panel has aria-hidden=false" ); assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "active panel has aria-hidden=false" );
equal( tabs.eq( 1 ).attr( "aria-selected" ), "false", "inactive tab has aria-selected=false" ); assert.equal( tabs.eq( 1 ).attr( "aria-selected" ), "false", "inactive tab has aria-selected=false" );
equal( tabs.eq( 1 ).attr( "tabindex" ), -1, "inactive tab has tabindex=-1" ); assert.equal( tabs.eq( 1 ).attr( "tabindex" ), -1, "inactive tab has tabindex=-1" );
equal( tabs.eq( 1 ).attr( "aria-disabled" ), null, "enabled tab does not have aria-disabled" ); assert.equal( tabs.eq( 1 ).attr( "aria-disabled" ), null, "enabled tab does not have aria-disabled" );
equal( tabs.eq( 1 ).attr( "aria-expanded" ), "false", "inactive tab has aria-expanded=false" ); assert.equal( tabs.eq( 1 ).attr( "aria-expanded" ), "false", "inactive tab has aria-expanded=false" );
equal( panels.eq( 1 ).attr( "aria-hidden" ), "true", "inactive panel has aria-hidden=true" ); assert.equal( panels.eq( 1 ).attr( "aria-hidden" ), "true", "inactive panel has aria-hidden=true" );
equal( tabs.eq( 2 ).attr( "aria-selected" ), "false", "inactive tab has aria-selected=false" ); assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "false", "inactive tab has aria-selected=false" );
equal( tabs.eq( 2 ).attr( "tabindex" ), -1, "inactive tab has tabindex=-1" ); assert.equal( tabs.eq( 2 ).attr( "tabindex" ), -1, "inactive tab has tabindex=-1" );
equal( tabs.eq( 2 ).attr( "aria-disabled" ), "true", "disabled tab has aria-disabled=true" ); assert.equal( tabs.eq( 2 ).attr( "aria-disabled" ), "true", "disabled tab has aria-disabled=true" );
equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "inactive tab has aria-expanded=false" ); assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "inactive tab has aria-expanded=false" );
equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "inactive panel has aria-hidden=true" ); assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "inactive panel has aria-hidden=true" );
} ); } );
asyncTest( "accessibility - ajax", function( assert ) { QUnit.test( "accessibility - ajax", function( assert ) {
expect( 6 ); var ready = assert.async();
assert.expect( 6 );
var element = $( "#tabs2" ).tabs(), var element = $( "#tabs2" ).tabs(),
tab = element.find( ".ui-tabs-nav li" ).eq( 3 ), tab = element.find( ".ui-tabs-nav li" ).eq( 3 ),
panel = $( "#custom-id" ); panel = $( "#custom-id" );
equal( panel.attr( "aria-live" ), "polite", "remote panel has aria-live" ); assert.equal( panel.attr( "aria-live" ), "polite", "remote panel has aria-live" );
equal( panel.attr( "aria-busy" ), null, "does not have aria-busy on init" ); assert.equal( panel.attr( "aria-busy" ), null, "does not have aria-busy on init" );
element.tabs( "option", "active", 3 ); element.tabs( "option", "active", 3 );
assert.hasClasses( tab, "ui-tabs-loading" ); assert.hasClasses( tab, "ui-tabs-loading" );
equal( panel.attr( "aria-busy" ), "true", "panel has aria-busy during load" ); assert.equal( panel.attr( "aria-busy" ), "true", "panel has aria-busy during load" );
element.one( "tabsload", function() { element.one( "tabsload", function() {
setTimeout( function() { setTimeout( function() {
equal( panel.attr( "aria-busy" ), null, "panel does not have aria-busy after load" ); assert.equal( panel.attr( "aria-busy" ), null, "panel does not have aria-busy after load" );
assert.lacksClasses( tab, "ui-tabs-loading" ); assert.lacksClasses( tab, "ui-tabs-loading" );
start(); ready();
}, 1 ); }, 1 );
} ); } );
} ); } );
asyncTest( "keyboard support - LEFT, RIGHT, UP, DOWN, HOME, END, SPACE, ENTER", function( assert ) { QUnit.test( "keyboard support - LEFT, RIGHT, UP, DOWN, HOME, END, SPACE, ENTER", function( assert ) {
expect( 92 ); var ready = assert.async();
assert.expect( 92 );
var element = $( "#tabs1" ).tabs( { var element = $( "#tabs1" ).tabs( {
collapsible: true collapsible: true
} ), } ),
@ -188,92 +191,92 @@ asyncTest( "keyboard support - LEFT, RIGHT, UP, DOWN, HOME, END, SPACE, ENTER",
element.tabs( "instance" ).delay = 1; element.tabs( "instance" ).delay = 1;
equal( tabs.filter( ".ui-state-focus" ).length, 0, "no tabs focused on init" ); assert.equal( tabs.filter( ".ui-state-focus" ).length, 0, "no tabs focused on init" );
tabs.eq( 0 ).simulate( "focus" ); tabs.eq( 0 ).simulate( "focus" );
// Down, right, down (wrap), up (wrap) // Down, right, down (wrap), up (wrap)
function step1() { function step1() {
assert.hasClasses( tabs.eq( 0 ), "ui-state-focus", "first tab has focus" ); assert.hasClasses( tabs.eq( 0 ), "ui-state-focus", "first tab has focus" );
equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
ok( panels.eq( 0 ).is( ":visible" ), "first panel is visible" ); assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is visible" );
tabs.eq( 0 ).simulate( "keydown", { keyCode: keyCode.DOWN } ); tabs.eq( 0 ).simulate( "keydown", { keyCode: keyCode.DOWN } );
assert.hasClasses( tabs.eq( 1 ), "ui-state-focus", "DOWN moves focus to next tab" ); assert.hasClasses( tabs.eq( 1 ), "ui-state-focus", "DOWN moves focus to next tab" );
assert.lacksClasses( tabs.eq( 0 ), "ui-state-focus", "first tab is no longer focused" ); assert.lacksClasses( tabs.eq( 0 ), "ui-state-focus", "first tab is no longer focused" );
equal( tabs.eq( 1 ).attr( "aria-selected" ), "true", "second tab has aria-selected=true" ); assert.equal( tabs.eq( 1 ).attr( "aria-selected" ), "true", "second tab has aria-selected=true" );
equal( tabs.eq( 0 ).attr( "aria-selected" ), "false", "first tab has aria-selected=false" ); assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "false", "first tab has aria-selected=false" );
ok( panels.eq( 1 ).is( ":hidden" ), "second panel is still hidden" ); assert.ok( panels.eq( 1 ).is( ":hidden" ), "second panel is still hidden" );
equal( tabs.eq( 1 ).attr( "aria-expanded" ), "false", "second tab has aria-expanded=false" ); assert.equal( tabs.eq( 1 ).attr( "aria-expanded" ), "false", "second tab has aria-expanded=false" );
equal( panels.eq( 1 ).attr( "aria-hidden" ), "true", "second panel has aria-hidden=true" ); assert.equal( panels.eq( 1 ).attr( "aria-hidden" ), "true", "second panel has aria-hidden=true" );
ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" ); assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" );
equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" ); assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
tabs.eq( 1 ).simulate( "keydown", { keyCode: keyCode.RIGHT } ); tabs.eq( 1 ).simulate( "keydown", { keyCode: keyCode.RIGHT } );
assert.hasClasses( tabs.eq( 2 ), "ui-state-focus", "RIGHT moves focus to next tab" ); assert.hasClasses( tabs.eq( 2 ), "ui-state-focus", "RIGHT moves focus to next tab" );
equal( tabs.eq( 2 ).attr( "aria-selected" ), "true", "third tab has aria-selected=true" ); assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "true", "third tab has aria-selected=true" );
equal( tabs.eq( 1 ).attr( "aria-selected" ), "false", "second tab has aria-selected=false" ); assert.equal( tabs.eq( 1 ).attr( "aria-selected" ), "false", "second tab has aria-selected=false" );
ok( panels.eq( 2 ).is( ":hidden" ), "third panel is still hidden" ); assert.ok( panels.eq( 2 ).is( ":hidden" ), "third panel is still hidden" );
equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" ); assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" );
equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" ); assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" );
ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" ); assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" );
equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" ); assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
tabs.eq( 2 ).simulate( "keydown", { keyCode: keyCode.DOWN } ); tabs.eq( 2 ).simulate( "keydown", { keyCode: keyCode.DOWN } );
assert.hasClasses( tabs.eq( 0 ), "ui-state-focus", "DOWN wraps focus to first tab" ); assert.hasClasses( tabs.eq( 0 ), "ui-state-focus", "DOWN wraps focus to first tab" );
equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
equal( tabs.eq( 2 ).attr( "aria-selected" ), "false", "third tab has aria-selected=false" ); assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "false", "third tab has aria-selected=false" );
ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" ); assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" );
equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" ); assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
tabs.eq( 0 ).simulate( "keydown", { keyCode: keyCode.UP } ); tabs.eq( 0 ).simulate( "keydown", { keyCode: keyCode.UP } );
assert.hasClasses( tabs.eq( 2 ), "ui-state-focus", "UP wraps focus to last tab" ); assert.hasClasses( tabs.eq( 2 ), "ui-state-focus", "UP wraps focus to last tab" );
equal( tabs.eq( 2 ).attr( "aria-selected" ), "true", "third tab has aria-selected=true" ); assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "true", "third tab has aria-selected=true" );
equal( tabs.eq( 0 ).attr( "aria-selected" ), "false", "first tab has aria-selected=false" ); assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "false", "first tab has aria-selected=false" );
ok( panels.eq( 2 ).is( ":hidden" ), "third panel is still hidden" ); assert.ok( panels.eq( 2 ).is( ":hidden" ), "third panel is still hidden" );
equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" ); assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" );
equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" ); assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" );
ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" ); assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" );
equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" ); assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
setTimeout( step2, 25 ); setTimeout( step2, 25 );
} }
// Left, home, space // Left, home, space
function step2() { function step2() {
equal( tabs.eq( 2 ).attr( "aria-selected" ), "true", "third tab has aria-selected=true" ); assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "true", "third tab has aria-selected=true" );
equal( tabs.eq( 0 ).attr( "aria-selected" ), "false", "first tab has aria-selected=false" ); assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "false", "first tab has aria-selected=false" );
ok( panels.eq( 2 ).is( ":visible" ), "third panel is visible" ); assert.ok( panels.eq( 2 ).is( ":visible" ), "third panel is visible" );
equal( tabs.eq( 2 ).attr( "aria-expanded" ), "true", "third tab has aria-expanded=true" ); assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "true", "third tab has aria-expanded=true" );
equal( panels.eq( 2 ).attr( "aria-hidden" ), "false", "third panel has aria-hidden=false" ); assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "false", "third panel has aria-hidden=false" );
ok( panels.eq( 0 ).is( ":hidden" ), "first panel is hidden" ); assert.ok( panels.eq( 0 ).is( ":hidden" ), "first panel is hidden" );
equal( tabs.eq( 0 ).attr( "aria-expanded" ), "false", "first tab has aria-expanded=false" ); assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "false", "first tab has aria-expanded=false" );
equal( panels.eq( 0 ).attr( "aria-hidden" ), "true", "first panel has aria-hidden=true" ); assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "true", "first panel has aria-hidden=true" );
tabs.eq( 2 ).simulate( "keydown", { keyCode: keyCode.LEFT } ); tabs.eq( 2 ).simulate( "keydown", { keyCode: keyCode.LEFT } );
assert.hasClasses( tabs.eq( 1 ), "ui-state-focus", "LEFT moves focus to previous tab" ); assert.hasClasses( tabs.eq( 1 ), "ui-state-focus", "LEFT moves focus to previous tab" );
equal( tabs.eq( 1 ).attr( "aria-selected" ), "true", "second tab has aria-selected=true" ); assert.equal( tabs.eq( 1 ).attr( "aria-selected" ), "true", "second tab has aria-selected=true" );
equal( tabs.eq( 2 ).attr( "aria-selected" ), "false", "third tab has aria-selected=false" ); assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "false", "third tab has aria-selected=false" );
ok( panels.eq( 1 ).is( ":hidden" ), "second panel is still hidden" ); assert.ok( panels.eq( 1 ).is( ":hidden" ), "second panel is still hidden" );
equal( tabs.eq( 1 ).attr( "aria-expanded" ), "false", "second tab has aria-expanded=false" ); assert.equal( tabs.eq( 1 ).attr( "aria-expanded" ), "false", "second tab has aria-expanded=false" );
equal( panels.eq( 1 ).attr( "aria-hidden" ), "true", "second panel has aria-hidden=true" ); assert.equal( panels.eq( 1 ).attr( "aria-hidden" ), "true", "second panel has aria-hidden=true" );
ok( panels.eq( 2 ).is( ":visible" ), "third panel is still visible" ); assert.ok( panels.eq( 2 ).is( ":visible" ), "third panel is still visible" );
equal( tabs.eq( 2 ).attr( "aria-expanded" ), "true", "third tab has aria-expanded=true" ); assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "true", "third tab has aria-expanded=true" );
equal( panels.eq( 2 ).attr( "aria-hidden" ), "false", "third panel has aria-hidden=false" ); assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "false", "third panel has aria-hidden=false" );
tabs.eq( 1 ).simulate( "keydown", { keyCode: keyCode.HOME } ); tabs.eq( 1 ).simulate( "keydown", { keyCode: keyCode.HOME } );
assert.hasClasses( tabs.eq( 0 ), "ui-state-focus", "HOME moves focus to first tab" ); assert.hasClasses( tabs.eq( 0 ), "ui-state-focus", "HOME moves focus to first tab" );
equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
equal( tabs.eq( 1 ).attr( "aria-selected" ), "false", "second tab has aria-selected=false" ); assert.equal( tabs.eq( 1 ).attr( "aria-selected" ), "false", "second tab has aria-selected=false" );
ok( panels.eq( 0 ).is( ":hidden" ), "first panel is still hidden" ); assert.ok( panels.eq( 0 ).is( ":hidden" ), "first panel is still hidden" );
equal( tabs.eq( 0 ).attr( "aria-expanded" ), "false", "first tab has aria-expanded=false" ); assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "false", "first tab has aria-expanded=false" );
equal( panels.eq( 0 ).attr( "aria-hidden" ), "true", "first panel has aria-hidden=true" ); assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "true", "first panel has aria-hidden=true" );
ok( panels.eq( 2 ).is( ":visible" ), "third panel is still visible" ); assert.ok( panels.eq( 2 ).is( ":visible" ), "third panel is still visible" );
equal( tabs.eq( 2 ).attr( "aria-expanded" ), "true", "third tab has aria-expanded=true" ); assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "true", "third tab has aria-expanded=true" );
equal( panels.eq( 2 ).attr( "aria-hidden" ), "false", "third panel has aria-hidden=false" ); assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "false", "third panel has aria-hidden=false" );
// SPACE activates, cancels delay // SPACE activates, cancels delay
tabs.eq( 0 ).simulate( "keydown", { keyCode: keyCode.SPACE } ); tabs.eq( 0 ).simulate( "keydown", { keyCode: keyCode.SPACE } );
@ -282,25 +285,25 @@ asyncTest( "keyboard support - LEFT, RIGHT, UP, DOWN, HOME, END, SPACE, ENTER",
// End, enter // End, enter
function step3() { function step3() {
equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
equal( tabs.eq( 2 ).attr( "aria-selected" ), "false", "third tab has aria-selected=false" ); assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "false", "third tab has aria-selected=false" );
ok( panels.eq( 0 ).is( ":visible" ), "first panel is visible" ); assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is visible" );
equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tabs has aria-expanded=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tabs has aria-expanded=true" );
equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" ); assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
ok( panels.eq( 2 ).is( ":hidden" ), "third panel is hidden" ); assert.ok( panels.eq( 2 ).is( ":hidden" ), "third panel is hidden" );
equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" ); assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" );
equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" ); assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" );
tabs.eq( 0 ).simulate( "keydown", { keyCode: keyCode.END } ); tabs.eq( 0 ).simulate( "keydown", { keyCode: keyCode.END } );
assert.hasClasses( tabs.eq( 2 ), "ui-state-focus", "END moves focus to last tab" ); assert.hasClasses( tabs.eq( 2 ), "ui-state-focus", "END moves focus to last tab" );
equal( tabs.eq( 2 ).attr( "aria-selected" ), "true", "third tab has aria-selected=true" ); assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "true", "third tab has aria-selected=true" );
equal( tabs.eq( 0 ).attr( "aria-selected" ), "false", "first tab has aria-selected=false" ); assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "false", "first tab has aria-selected=false" );
ok( panels.eq( 2 ).is( ":hidden" ), "third panel is still hidden" ); assert.ok( panels.eq( 2 ).is( ":hidden" ), "third panel is still hidden" );
equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" ); assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" );
equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" ); assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" );
ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" ); assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" );
equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tabs has aria-expanded=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tabs has aria-expanded=true" );
equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" ); assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
// ENTER activates, cancels delay // ENTER activates, cancels delay
tabs.eq( 0 ).simulate( "keydown", { keyCode: keyCode.ENTER } ); tabs.eq( 0 ).simulate( "keydown", { keyCode: keyCode.ENTER } );
@ -309,22 +312,22 @@ asyncTest( "keyboard support - LEFT, RIGHT, UP, DOWN, HOME, END, SPACE, ENTER",
// Enter (collapse) // Enter (collapse)
function step4() { function step4() {
equal( tabs.eq( 2 ).attr( "aria-selected" ), "true", "third tab has aria-selected=true" ); assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "true", "third tab has aria-selected=true" );
ok( panels.eq( 2 ).is( ":visible" ), "third panel is visible" ); assert.ok( panels.eq( 2 ).is( ":visible" ), "third panel is visible" );
equal( tabs.eq( 2 ).attr( "aria-expanded" ), "true", "third tab has aria-expanded=true" ); assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "true", "third tab has aria-expanded=true" );
equal( panels.eq( 2 ).attr( "aria-hidden" ), "false", "third panel has aria-hidden=false" ); assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "false", "third panel has aria-hidden=false" );
ok( panels.eq( 0 ).is( ":hidden" ), "first panel is hidden" ); assert.ok( panels.eq( 0 ).is( ":hidden" ), "first panel is hidden" );
equal( tabs.eq( 0 ).attr( "aria-expanded" ), "false", "first tab has aria-expanded=false" ); assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "false", "first tab has aria-expanded=false" );
equal( panels.eq( 0 ).attr( "aria-hidden" ), "true", "first panel has aria-hidden=true" ); assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "true", "first panel has aria-hidden=true" );
// ENTER collapses if active // ENTER collapses if active
tabs.eq( 2 ).simulate( "keydown", { keyCode: keyCode.ENTER } ); tabs.eq( 2 ).simulate( "keydown", { keyCode: keyCode.ENTER } );
equal( tabs.eq( 2 ).attr( "aria-selected" ), "false", "third tab has aria-selected=false" ); assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "false", "third tab has aria-selected=false" );
ok( panels.eq( 2 ).is( ":hidden" ), "third panel is hidden" ); assert.ok( panels.eq( 2 ).is( ":hidden" ), "third panel is hidden" );
equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" ); assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" );
equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" ); assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" );
setTimeout( start ); setTimeout( ready );
} }
setTimeout( step1 ); setTimeout( step1 );
@ -335,8 +338,9 @@ $.each( {
ctrl: "CTRL", ctrl: "CTRL",
meta: "COMMAND" meta: "COMMAND"
}, function( modifier, label ) { }, function( modifier, label ) {
asyncTest( "keyboard support - " + label + " navigation", function( assert ) { QUnit.test( "keyboard support - " + label + " navigation", function( assert ) {
expect( 115 ); var ready = assert.async();
assert.expect( 115 );
var element = $( "#tabs1" ).tabs(), var element = $( "#tabs1" ).tabs(),
tabs = element.find( ".ui-tabs-nav li" ), tabs = element.find( ".ui-tabs-nav li" ),
panels = element.find( ".ui-tabs-panel" ), panels = element.find( ".ui-tabs-panel" ),
@ -344,7 +348,7 @@ $.each( {
element.tabs( "instance" ).delay = 1; element.tabs( "instance" ).delay = 1;
equal( tabs.filter( ".ui-state-focus" ).length, 0, "no tabs focused on init" ); assert.equal( tabs.filter( ".ui-state-focus" ).length, 0, "no tabs focused on init" );
tabs.eq( 0 ).simulate( "focus" ); tabs.eq( 0 ).simulate( "focus" );
// Down // Down
@ -353,20 +357,20 @@ $.each( {
eventProperties[ modifier + "Key" ] = true; eventProperties[ modifier + "Key" ] = true;
assert.hasClasses( tabs.eq( 0 ), "ui-state-focus", "first tab has focus" ); assert.hasClasses( tabs.eq( 0 ), "ui-state-focus", "first tab has focus" );
equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
ok( panels.eq( 0 ).is( ":visible" ), "first panel is visible" ); assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is visible" );
tabs.eq( 0 ).simulate( "keydown", eventProperties ); tabs.eq( 0 ).simulate( "keydown", eventProperties );
assert.hasClasses( tabs.eq( 1 ), "ui-state-focus", "DOWN moves focus to next tab" ); assert.hasClasses( tabs.eq( 1 ), "ui-state-focus", "DOWN moves focus to next tab" );
assert.lacksClasses( tabs.eq( 0 ), ".ui-state-focus", "first tab is no longer focused" ); assert.lacksClasses( tabs.eq( 0 ), ".ui-state-focus", "first tab is no longer focused" );
equal( tabs.eq( 1 ).attr( "aria-selected" ), "false", "second tab has aria-selected=false" ); assert.equal( tabs.eq( 1 ).attr( "aria-selected" ), "false", "second tab has aria-selected=false" );
equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
ok( panels.eq( 1 ).is( ":hidden" ), "second panel is still hidden" ); assert.ok( panels.eq( 1 ).is( ":hidden" ), "second panel is still hidden" );
equal( tabs.eq( 1 ).attr( "aria-expanded" ), "false", "second tab has aria-expanded=false" ); assert.equal( tabs.eq( 1 ).attr( "aria-expanded" ), "false", "second tab has aria-expanded=false" );
equal( panels.eq( 1 ).attr( "aria-hidden" ), "true", "second panel has aria-hidden=true" ); assert.equal( panels.eq( 1 ).attr( "aria-hidden" ), "true", "second panel has aria-hidden=true" );
ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" ); assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" );
equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" ); assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
setTimeout( step2, 25 ); setTimeout( step2, 25 );
} }
@ -376,24 +380,24 @@ $.each( {
var eventProperties = { keyCode: keyCode.RIGHT }; var eventProperties = { keyCode: keyCode.RIGHT };
eventProperties[ modifier + "Key" ] = true; eventProperties[ modifier + "Key" ] = true;
equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
ok( panels.eq( 0 ).is( ":visible" ), "first panel is visible" ); assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is visible" );
equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" ); assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
ok( panels.eq( 1 ).is( ":hidden" ), "second panel is hidden" ); assert.ok( panels.eq( 1 ).is( ":hidden" ), "second panel is hidden" );
equal( tabs.eq( 1 ).attr( "aria-expanded" ), "false", "second tab has aria-expanded=false" ); assert.equal( tabs.eq( 1 ).attr( "aria-expanded" ), "false", "second tab has aria-expanded=false" );
equal( panels.eq( 1 ).attr( "aria-hidden" ), "true", "second panel has aria-hidden=true" ); assert.equal( panels.eq( 1 ).attr( "aria-hidden" ), "true", "second panel has aria-hidden=true" );
tabs.eq( 1 ).simulate( "keydown", eventProperties ); tabs.eq( 1 ).simulate( "keydown", eventProperties );
assert.hasClasses( tabs.eq( 2 ), "ui-state-focus", "RIGHT moves focus to next tab" ); assert.hasClasses( tabs.eq( 2 ), "ui-state-focus", "RIGHT moves focus to next tab" );
equal( tabs.eq( 2 ).attr( "aria-selected" ), "false", "third tab has aria-selected=false" ); assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "false", "third tab has aria-selected=false" );
equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
ok( panels.eq( 2 ).is( ":hidden" ), "third panel is still hidden" ); assert.ok( panels.eq( 2 ).is( ":hidden" ), "third panel is still hidden" );
equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" ); assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" );
equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" ); assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" );
ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" ); assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" );
equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" ); assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
setTimeout( step3, 25 ); setTimeout( step3, 25 );
} }
@ -403,20 +407,20 @@ $.each( {
var eventProperties = { keyCode: keyCode.DOWN }; var eventProperties = { keyCode: keyCode.DOWN };
eventProperties[ modifier + "Key" ] = true; eventProperties[ modifier + "Key" ] = true;
equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
ok( panels.eq( 0 ).is( ":visible" ), "first panel is visible" ); assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is visible" );
equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" ); assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
ok( panels.eq( 2 ).is( ":hidden" ), "third panel is hidden" ); assert.ok( panels.eq( 2 ).is( ":hidden" ), "third panel is hidden" );
equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" ); assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" );
equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" ); assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" );
tabs.eq( 2 ).simulate( "keydown", eventProperties ); tabs.eq( 2 ).simulate( "keydown", eventProperties );
assert.hasClasses( tabs.eq( 0 ), "ui-state-focus", "DOWN wraps focus to first tab" ); assert.hasClasses( tabs.eq( 0 ), "ui-state-focus", "DOWN wraps focus to first tab" );
equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" ); assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" );
equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" ); assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
setTimeout( step4, 25 ); setTimeout( step4, 25 );
} }
@ -426,21 +430,21 @@ $.each( {
var eventProperties = { keyCode: keyCode.UP }; var eventProperties = { keyCode: keyCode.UP };
eventProperties[ modifier + "Key" ] = true; eventProperties[ modifier + "Key" ] = true;
equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
ok( panels.eq( 0 ).is( ":visible" ), "first panel is visible" ); assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is visible" );
equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" ); assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
tabs.eq( 0 ).simulate( "keydown", eventProperties ); tabs.eq( 0 ).simulate( "keydown", eventProperties );
assert.hasClasses( tabs.eq( 2 ), "ui-state-focus", "UP wraps focus to last tab" ); assert.hasClasses( tabs.eq( 2 ), "ui-state-focus", "UP wraps focus to last tab" );
equal( tabs.eq( 2 ).attr( "aria-selected" ), "false", "third tab has aria-selected=false" ); assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "false", "third tab has aria-selected=false" );
equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
ok( panels.eq( 2 ).is( ":hidden" ), "third panel is still hidden" ); assert.ok( panels.eq( 2 ).is( ":hidden" ), "third panel is still hidden" );
equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" ); assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" );
equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" ); assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" );
ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" ); assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" );
equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" ); assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
setTimeout( step5, 25 ); setTimeout( step5, 25 );
} }
@ -450,24 +454,24 @@ $.each( {
var eventProperties = { keyCode: keyCode.LEFT }; var eventProperties = { keyCode: keyCode.LEFT };
eventProperties[ modifier + "Key" ] = true; eventProperties[ modifier + "Key" ] = true;
equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
ok( panels.eq( 0 ).is( ":visible" ), "first panel is visible" ); assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is visible" );
equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" ); assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
ok( panels.eq( 2 ).is( ":hidden" ), "third panel is hidden" ); assert.ok( panels.eq( 2 ).is( ":hidden" ), "third panel is hidden" );
equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" ); assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" );
equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" ); assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" );
tabs.eq( 2 ).simulate( "keydown", eventProperties ); tabs.eq( 2 ).simulate( "keydown", eventProperties );
assert.hasClasses( tabs.eq( 1 ), "ui-state-focus", "LEFT moves focus to previous tab" ); assert.hasClasses( tabs.eq( 1 ), "ui-state-focus", "LEFT moves focus to previous tab" );
equal( tabs.eq( 1 ).attr( "aria-selected" ), "false", "second tab has aria-selected=false" ); assert.equal( tabs.eq( 1 ).attr( "aria-selected" ), "false", "second tab has aria-selected=false" );
equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
ok( panels.eq( 1 ).is( ":hidden" ), "second panel is still hidden" ); assert.ok( panels.eq( 1 ).is( ":hidden" ), "second panel is still hidden" );
equal( tabs.eq( 1 ).attr( "aria-expanded" ), "false", "second tab has aria-expanded=false" ); assert.equal( tabs.eq( 1 ).attr( "aria-expanded" ), "false", "second tab has aria-expanded=false" );
equal( panels.eq( 1 ).attr( "aria-hidden" ), "true", "second panel has aria-hidden=true" ); assert.equal( panels.eq( 1 ).attr( "aria-hidden" ), "true", "second panel has aria-hidden=true" );
ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" ); assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" );
equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" ); assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
setTimeout( step6, 25 ); setTimeout( step6, 25 );
} }
@ -477,24 +481,24 @@ $.each( {
var eventProperties = { keyCode: keyCode.HOME }; var eventProperties = { keyCode: keyCode.HOME };
eventProperties[ modifier + "Key" ] = true; eventProperties[ modifier + "Key" ] = true;
equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
ok( panels.eq( 0 ).is( ":visible" ), "first panel is visible" ); assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is visible" );
equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" ); assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
ok( panels.eq( 1 ).is( ":hidden" ), "second panel is hidden" ); assert.ok( panels.eq( 1 ).is( ":hidden" ), "second panel is hidden" );
equal( tabs.eq( 1 ).attr( "aria-expanded" ), "false", "second tab has aria-expanded=false" ); assert.equal( tabs.eq( 1 ).attr( "aria-expanded" ), "false", "second tab has aria-expanded=false" );
equal( panels.eq( 1 ).attr( "aria-hidden" ), "true", "second panel has aria-hidden=true" ); assert.equal( panels.eq( 1 ).attr( "aria-hidden" ), "true", "second panel has aria-hidden=true" );
tabs.eq( 1 ).simulate( "keydown", eventProperties ); tabs.eq( 1 ).simulate( "keydown", eventProperties );
assert.hasClasses( tabs.eq( 0 ), "ui-state-focus", "HOME moves focus to first tab" ); assert.hasClasses( tabs.eq( 0 ), "ui-state-focus", "HOME moves focus to first tab" );
equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
equal( tabs.eq( 1 ).attr( "aria-selected" ), "false", "second tab has aria-selected=false" ); assert.equal( tabs.eq( 1 ).attr( "aria-selected" ), "false", "second tab has aria-selected=false" );
ok( panels.eq( 1 ).is( ":hidden" ), "second panel is still hidden" ); assert.ok( panels.eq( 1 ).is( ":hidden" ), "second panel is still hidden" );
equal( tabs.eq( 1 ).attr( "aria-expanded" ), "false", "second tab has aria-expanded=false" ); assert.equal( tabs.eq( 1 ).attr( "aria-expanded" ), "false", "second tab has aria-expanded=false" );
equal( panels.eq( 1 ).attr( "aria-hidden" ), "true", "second panel has aria-hidden=true" ); assert.equal( panels.eq( 1 ).attr( "aria-hidden" ), "true", "second panel has aria-hidden=true" );
ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" ); assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" );
equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" ); assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
setTimeout( step7, 25 ); setTimeout( step7, 25 );
} }
@ -504,170 +508,171 @@ $.each( {
var eventProperties = { keyCode: keyCode.END }; var eventProperties = { keyCode: keyCode.END };
eventProperties[ modifier + "Key" ] = true; eventProperties[ modifier + "Key" ] = true;
equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
ok( panels.eq( 0 ).is( ":visible" ), "first panel is visible" ); assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is visible" );
equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" ); assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
tabs.eq( 0 ).simulate( "keydown", eventProperties ); tabs.eq( 0 ).simulate( "keydown", eventProperties );
assert.hasClasses( tabs.eq( 2 ), "ui-state-focus", "END moves focus to last tab" ); assert.hasClasses( tabs.eq( 2 ), "ui-state-focus", "END moves focus to last tab" );
equal( tabs.eq( 2 ).attr( "aria-selected" ), "false", "third tab has aria-selected=false" ); assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "false", "third tab has aria-selected=false" );
equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
ok( panels.eq( 2 ).is( ":hidden" ), "third panel is still hidden" ); assert.ok( panels.eq( 2 ).is( ":hidden" ), "third panel is still hidden" );
equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" ); assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" );
equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" ); assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" );
ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" ); assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" );
equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" ); assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
setTimeout( step8, 25 ); setTimeout( step8, 25 );
} }
// Space // Space
function step8() { function step8() {
equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
ok( panels.eq( 0 ).is( ":visible" ), "first panel is visible" ); assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is visible" );
equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" ); assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
ok( panels.eq( 2 ).is( ":hidden" ), "third panel is hidden" ); assert.ok( panels.eq( 2 ).is( ":hidden" ), "third panel is hidden" );
equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" ); assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" );
equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" ); assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" );
tabs.eq( 2 ).simulate( "keydown", { keyCode: keyCode.SPACE } ); tabs.eq( 2 ).simulate( "keydown", { keyCode: keyCode.SPACE } );
equal( tabs.eq( 2 ).attr( "aria-selected" ), "true", "third tab has aria-selected=true" ); assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "true", "third tab has aria-selected=true" );
equal( tabs.eq( 0 ).attr( "aria-selected" ), "false", "first tab has aria-selected=false" ); assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "false", "first tab has aria-selected=false" );
ok( panels.eq( 2 ).is( ":visible" ), "third panel is visible" ); assert.ok( panels.eq( 2 ).is( ":visible" ), "third panel is visible" );
equal( tabs.eq( 2 ).attr( "aria-expanded" ), "true", "third tab has aria-expanded=true" ); assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "true", "third tab has aria-expanded=true" );
equal( panels.eq( 2 ).attr( "aria-hidden" ), "false", "third panel has aria-hidden=false" ); assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "false", "third panel has aria-hidden=false" );
ok( panels.eq( 0 ).is( ":hidden" ), "first panel is hidden" ); assert.ok( panels.eq( 0 ).is( ":hidden" ), "first panel is hidden" );
equal( tabs.eq( 0 ).attr( "aria-expanded" ), "false", "first tab has aria-expanded=false" ); assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "false", "first tab has aria-expanded=false" );
equal( panels.eq( 0 ).attr( "aria-hidden" ), "true", "first panel has aria-hidden=true" ); assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "true", "first panel has aria-hidden=true" );
setTimeout( start ); setTimeout( ready );
} }
setTimeout( step1 ); setTimeout( step1 );
} ); } );
} ); } );
asyncTest( "keyboard support - CTRL+UP, ALT+PAGE_DOWN, ALT+PAGE_UP", function( assert ) { QUnit.test( "keyboard support - CTRL+UP, ALT+PAGE_DOWN, ALT+PAGE_UP", function( assert ) {
expect( 50 ); var ready = assert.async();
assert.expect( 50 );
var element = $( "#tabs1" ).tabs(), var element = $( "#tabs1" ).tabs(),
tabs = element.find( ".ui-tabs-nav li" ), tabs = element.find( ".ui-tabs-nav li" ),
panels = element.find( ".ui-tabs-panel" ), panels = element.find( ".ui-tabs-panel" ),
keyCode = $.ui.keyCode; keyCode = $.ui.keyCode;
equal( tabs.filter( ".ui-state-focus" ).length, 0, "no tabs focused on init" ); assert.equal( tabs.filter( ".ui-state-focus" ).length, 0, "no tabs focused on init" );
panels.attr( "tabindex", -1 ); panels.attr( "tabindex", -1 );
panels.eq( 0 ).simulate( "focus" ); panels.eq( 0 ).simulate( "focus" );
function step1() { function step1() {
strictEqual( document.activeElement, panels[ 0 ], "first panel is activeElement" ); assert.strictEqual( document.activeElement, panels[ 0 ], "first panel is activeElement" );
panels.eq( 0 ).simulate( "keydown", { keyCode: keyCode.PAGE_DOWN, altKey: true } ); panels.eq( 0 ).simulate( "keydown", { keyCode: keyCode.PAGE_DOWN, altKey: true } );
strictEqual( document.activeElement, tabs[ 1 ], "second tab is activeElement" ); assert.strictEqual( document.activeElement, tabs[ 1 ], "second tab is activeElement" );
assert.hasClasses( tabs.eq( 1 ), "ui-state-focus", "ALT+PAGE_DOWN moves focus to next tab" ); assert.hasClasses( tabs.eq( 1 ), "ui-state-focus", "ALT+PAGE_DOWN moves focus to next tab" );
equal( tabs.eq( 1 ).attr( "aria-selected" ), "true", "second tab has aria-selected=true" ); assert.equal( tabs.eq( 1 ).attr( "aria-selected" ), "true", "second tab has aria-selected=true" );
ok( panels.eq( 1 ).is( ":visible" ), "second panel is visible" ); assert.ok( panels.eq( 1 ).is( ":visible" ), "second panel is visible" );
equal( tabs.eq( 1 ).attr( "aria-expanded" ), "true", "second tab has aria-expanded=true" ); assert.equal( tabs.eq( 1 ).attr( "aria-expanded" ), "true", "second tab has aria-expanded=true" );
equal( panels.eq( 1 ).attr( "aria-hidden" ), "false", "second panel has aria-hidden=false" ); assert.equal( panels.eq( 1 ).attr( "aria-hidden" ), "false", "second panel has aria-hidden=false" );
ok( panels.eq( 0 ).is( ":hidden" ), "first panel is hidden" ); assert.ok( panels.eq( 0 ).is( ":hidden" ), "first panel is hidden" );
equal( tabs.eq( 0 ).attr( "aria-expanded" ), "false", "first tab has aria-expanded=false" ); assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "false", "first tab has aria-expanded=false" );
equal( panels.eq( 0 ).attr( "aria-hidden" ), "true", "first panel has aria-hidden=true" ); assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "true", "first panel has aria-hidden=true" );
tabs.eq( 1 ).simulate( "keydown", { keyCode: keyCode.PAGE_DOWN, altKey: true } ); tabs.eq( 1 ).simulate( "keydown", { keyCode: keyCode.PAGE_DOWN, altKey: true } );
strictEqual( document.activeElement, tabs[ 2 ], "third tab is activeElement" ); assert.strictEqual( document.activeElement, tabs[ 2 ], "third tab is activeElement" );
assert.hasClasses( tabs.eq( 2 ), "ui-state-focus", "ALT+PAGE_DOWN moves focus to next tab" ); assert.hasClasses( tabs.eq( 2 ), "ui-state-focus", "ALT+PAGE_DOWN moves focus to next tab" );
equal( tabs.eq( 2 ).attr( "aria-selected" ), "true", "third tab has aria-selected=true" ); assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "true", "third tab has aria-selected=true" );
ok( panels.eq( 2 ).is( ":visible" ), "third panel is visible" ); assert.ok( panels.eq( 2 ).is( ":visible" ), "third panel is visible" );
equal( tabs.eq( 2 ).attr( "aria-expanded" ), "true", "third tab has aria-expanded=true" ); assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "true", "third tab has aria-expanded=true" );
equal( panels.eq( 2 ).attr( "aria-hidden" ), "false", "third panel has aria-hidden=false" ); assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "false", "third panel has aria-hidden=false" );
ok( panels.eq( 1 ).is( ":hidden" ), "second panel is hidden" ); assert.ok( panels.eq( 1 ).is( ":hidden" ), "second panel is hidden" );
equal( tabs.eq( 1 ).attr( "aria-expanded" ), "false", "second tab has aria-expanded=false" ); assert.equal( tabs.eq( 1 ).attr( "aria-expanded" ), "false", "second tab has aria-expanded=false" );
equal( panels.eq( 1 ).attr( "aria-hidden" ), "true", "second panel has aria-hidden=true" ); assert.equal( panels.eq( 1 ).attr( "aria-hidden" ), "true", "second panel has aria-hidden=true" );
tabs.eq( 2 ).simulate( "keydown", { keyCode: keyCode.PAGE_DOWN, altKey: true } ); tabs.eq( 2 ).simulate( "keydown", { keyCode: keyCode.PAGE_DOWN, altKey: true } );
strictEqual( document.activeElement, tabs[ 0 ], "first tab is activeElement" ); assert.strictEqual( document.activeElement, tabs[ 0 ], "first tab is activeElement" );
assert.hasClasses( tabs.eq( 0 ), "ui-state-focus", "ALT+PAGE_DOWN wraps focus to first tab" ); assert.hasClasses( tabs.eq( 0 ), "ui-state-focus", "ALT+PAGE_DOWN wraps focus to first tab" );
equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
ok( panels.eq( 0 ).is( ":visible" ), "first panel is visible" ); assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is visible" );
equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" ); assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" ); assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
ok( panels.eq( 2 ).is( ":hidden" ), "third panel is hidden" ); assert.ok( panels.eq( 2 ).is( ":hidden" ), "third panel is hidden" );
equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" ); assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" );
equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" ); assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" );
panels.eq( 0 ).simulate( "focus" ); panels.eq( 0 ).simulate( "focus" );
setTimeout( step2 ); setTimeout( step2 );
} }
function step2() { function step2() {
strictEqual( document.activeElement, panels[ 0 ], "first panel is activeElement" ); assert.strictEqual( document.activeElement, panels[ 0 ], "first panel is activeElement" );
panels.eq( 0 ).simulate( "keydown", { keyCode: keyCode.PAGE_UP, altKey: true } ); panels.eq( 0 ).simulate( "keydown", { keyCode: keyCode.PAGE_UP, altKey: true } );
strictEqual( document.activeElement, tabs[ 2 ], "third tab is activeElement" ); assert.strictEqual( document.activeElement, tabs[ 2 ], "third tab is activeElement" );
assert.hasClasses( tabs.eq( 2 ), "ui-state-focus", "ALT+PAGE_UP wraps focus to last tab" ); assert.hasClasses( tabs.eq( 2 ), "ui-state-focus", "ALT+PAGE_UP wraps focus to last tab" );
equal( tabs.eq( 2 ).attr( "aria-selected" ), "true", "third tab has aria-selected=true" ); assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "true", "third tab has aria-selected=true" );
ok( panels.eq( 2 ).is( ":visible" ), "third panel is visible" ); assert.ok( panels.eq( 2 ).is( ":visible" ), "third panel is visible" );
equal( tabs.eq( 2 ).attr( "aria-expanded" ), "true", "third tab has aria-expanded=true" ); assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "true", "third tab has aria-expanded=true" );
equal( panels.eq( 2 ).attr( "aria-hidden" ), "false", "third panel has aria-hidden=false" ); assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "false", "third panel has aria-hidden=false" );
ok( panels.eq( 0 ).is( ":hidden" ), "first panel is hidden" ); assert.ok( panels.eq( 0 ).is( ":hidden" ), "first panel is hidden" );
equal( tabs.eq( 0 ).attr( "aria-expanded" ), "false", "first tab has aria-expanded=false" ); assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "false", "first tab has aria-expanded=false" );
equal( panels.eq( 0 ).attr( "aria-hidden" ), "true", "first panel has aria-hidden=true" ); assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "true", "first panel has aria-hidden=true" );
tabs.eq( 2 ).simulate( "keydown", { keyCode: keyCode.PAGE_UP, altKey: true } ); tabs.eq( 2 ).simulate( "keydown", { keyCode: keyCode.PAGE_UP, altKey: true } );
strictEqual( document.activeElement, tabs[ 1 ], "second tab is activeElement" ); assert.strictEqual( document.activeElement, tabs[ 1 ], "second tab is activeElement" );
assert.hasClasses( tabs.eq( 1 ), "ui-state-focus", "ALT+PAGE_UP moves focus to previous tab" ); assert.hasClasses( tabs.eq( 1 ), "ui-state-focus", "ALT+PAGE_UP moves focus to previous tab" );
equal( tabs.eq( 1 ).attr( "aria-selected" ), "true", "second tab has aria-selected=true" ); assert.equal( tabs.eq( 1 ).attr( "aria-selected" ), "true", "second tab has aria-selected=true" );
ok( panels.eq( 1 ).is( ":visible" ), "second panel is visible" ); assert.ok( panels.eq( 1 ).is( ":visible" ), "second panel is visible" );
equal( tabs.eq( 1 ).attr( "aria-expanded" ), "true", "second tab has aria-expanded=true" ); assert.equal( tabs.eq( 1 ).attr( "aria-expanded" ), "true", "second tab has aria-expanded=true" );
equal( panels.eq( 1 ).attr( "aria-hidden" ), "false", "second panel has aria-hidden=false" ); assert.equal( panels.eq( 1 ).attr( "aria-hidden" ), "false", "second panel has aria-hidden=false" );
ok( panels.eq( 2 ).is( ":hidden" ), "third panel is hidden" ); assert.ok( panels.eq( 2 ).is( ":hidden" ), "third panel is hidden" );
equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" ); assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" );
equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" ); assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" );
panels.eq( 1 ).simulate( "focus" ); panels.eq( 1 ).simulate( "focus" );
setTimeout( step3 ); setTimeout( step3 );
} }
function step3() { function step3() {
strictEqual( document.activeElement, panels[ 1 ], "second panel is activeElement" ); assert.strictEqual( document.activeElement, panels[ 1 ], "second panel is activeElement" );
panels.eq( 1 ).simulate( "keydown", { keyCode: keyCode.UP, ctrlKey: true } ); panels.eq( 1 ).simulate( "keydown", { keyCode: keyCode.UP, ctrlKey: true } );
strictEqual( document.activeElement, tabs[ 1 ], "second tab is activeElement" ); assert.strictEqual( document.activeElement, tabs[ 1 ], "second tab is activeElement" );
setTimeout( start ); setTimeout( ready );
} }
setTimeout( step1 ); setTimeout( step1 );
} ); } );
test( "#3627 - Ajax tab with url containing a fragment identifier fails to load", function() { QUnit.test( "#3627 - Ajax tab with url containing a fragment identifier fails to load", function( assert ) {
expect( 1 ); assert.expect( 1 );
$( "#tabs2" ).tabs( { $( "#tabs2" ).tabs( {
active: 2, active: 2,
beforeLoad: function( event, ui ) { beforeLoad: function( event, ui ) {
event.preventDefault(); event.preventDefault();
ok( /test.html$/.test( ui.ajaxSettings.url ), "should ignore fragment identifier" ); assert.ok( /test.html$/.test( ui.ajaxSettings.url ), "should ignore fragment identifier" );
} }
} ); } );
} ); } );
test( "#4033 - IE expands hash to full url and misinterprets tab as ajax", function() { QUnit.test( "#4033 - IE expands hash to full url and misinterprets tab as ajax", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( "<div><ul><li><a href='#tab'>Tab</a></li></ul><div id='tab'></div></div>" ); var element = $( "<div><ul><li><a href='#tab'>Tab</a></li></ul><div id='tab'></div></div>" );
element.appendTo( "#qunit-fixture" ); element.appendTo( "#qunit-fixture" );
element.tabs( { element.tabs( {
beforeLoad: function() { beforeLoad: function() {
event.preventDefault(); event.preventDefault();
ok( false, "should not be an ajax tab" ); assert.ok( false, "should not be an ajax tab" );
} }
} ); } );
equal( element.find( ".ui-tabs-nav li" ).attr( "aria-controls" ), "tab", "aria-contorls attribute is correct" ); assert.equal( element.find( ".ui-tabs-nav li" ).attr( "aria-controls" ), "tab", "aria-contorls attribute is correct" );
state( element, 1 ); state( assert, element, 1 );
} ); } );
} ); } );

View File

@ -1,15 +1,16 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"./helper", "./helper",
"ui/widgets/tabs" "ui/widgets/tabs"
], function( $, testHelper ) { ], function( QUnit, $, testHelper ) {
var state = testHelper.state; var state = testHelper.state;
module( "tabs: events" ); QUnit.module( "tabs: events" );
test( "create", function() { QUnit.test( "create", function( assert ) {
expect( 10 ); assert.expect( 10 );
var element = $( "#tabs1" ), var element = $( "#tabs1" ),
tabs = element.find( "ul li" ), tabs = element.find( "ul li" ),
@ -17,10 +18,10 @@ test( "create", function() {
element.tabs( { element.tabs( {
create: function( event, ui ) { create: function( event, ui ) {
equal( ui.tab.length, 1, "tab length" ); assert.equal( ui.tab.length, 1, "tab length" );
strictEqual( ui.tab[ 0 ], tabs[ 0 ], "tab" ); assert.strictEqual( ui.tab[ 0 ], tabs[ 0 ], "tab" );
equal( ui.panel.length, 1, "panel length" ); assert.equal( ui.panel.length, 1, "panel length" );
strictEqual( ui.panel[ 0 ], panels[ 0 ], "panel" ); assert.strictEqual( ui.panel[ 0 ], panels[ 0 ], "panel" );
} }
} ); } );
element.tabs( "destroy" ); element.tabs( "destroy" );
@ -28,10 +29,10 @@ test( "create", function() {
element.tabs( { element.tabs( {
active: 2, active: 2,
create: function( event, ui ) { create: function( event, ui ) {
equal( ui.tab.length, 1, "tab length" ); assert.equal( ui.tab.length, 1, "tab length" );
strictEqual( ui.tab[ 0 ], tabs[ 2 ], "tab" ); assert.strictEqual( ui.tab[ 0 ], tabs[ 2 ], "tab" );
equal( ui.panel.length, 1, "panel length" ); assert.equal( ui.panel.length, 1, "panel length" );
strictEqual( ui.panel[ 0 ], panels[ 2 ], "panel" ); assert.strictEqual( ui.panel[ 0 ], panels[ 2 ], "panel" );
} }
} ); } );
element.tabs( "destroy" ); element.tabs( "destroy" );
@ -40,15 +41,15 @@ test( "create", function() {
active: false, active: false,
collapsible: true, collapsible: true,
create: function( event, ui ) { create: function( event, ui ) {
equal( ui.tab.length, 0, "tab length" ); assert.equal( ui.tab.length, 0, "tab length" );
equal( ui.panel.length, 0, "panel length" ); assert.equal( ui.panel.length, 0, "panel length" );
} }
} ); } );
element.tabs( "destroy" ); element.tabs( "destroy" );
} ); } );
test( "beforeActivate", function() { QUnit.test( "beforeActivate", function( assert ) {
expect( 38 ); assert.expect( 38 );
var element = $( "#tabs1" ).tabs( { var element = $( "#tabs1" ).tabs( {
active: false, active: false,
@ -60,66 +61,66 @@ test( "beforeActivate", function() {
// From collapsed // From collapsed
element.one( "tabsbeforeactivate", function( event, ui ) { element.one( "tabsbeforeactivate", function( event, ui ) {
ok( !( "originalEvent" in event ), "originalEvent" ); assert.ok( !( "originalEvent" in event ), "originalEvent" );
equal( ui.oldTab.length, 0, "oldTab length" ); assert.equal( ui.oldTab.length, 0, "oldTab length" );
equal( ui.oldPanel.length, 0, "oldPanel length" ); assert.equal( ui.oldPanel.length, 0, "oldPanel length" );
equal( ui.newTab.length, 1, "newTab length" ); assert.equal( ui.newTab.length, 1, "newTab length" );
strictEqual( ui.newTab[ 0 ], tabs[ 0 ], "newTab" ); assert.strictEqual( ui.newTab[ 0 ], tabs[ 0 ], "newTab" );
equal( ui.newPanel.length, 1, "newPanel length" ); assert.equal( ui.newPanel.length, 1, "newPanel length" );
strictEqual( ui.newPanel[ 0 ], panels[ 0 ], "newPanel" ); assert.strictEqual( ui.newPanel[ 0 ], panels[ 0 ], "newPanel" );
state( element, 0, 0, 0 ); state( assert, element, 0, 0, 0 );
} ); } );
element.tabs( "option", "active", 0 ); element.tabs( "option", "active", 0 );
state( element, 1, 0, 0 ); state( assert, element, 1, 0, 0 );
// Switching tabs // Switching tabs
element.one( "tabsbeforeactivate", function( event, ui ) { element.one( "tabsbeforeactivate", function( event, ui ) {
equal( event.originalEvent.type, "click", "originalEvent" ); assert.equal( event.originalEvent.type, "click", "originalEvent" );
equal( ui.oldTab.length, 1, "oldTab length" ); assert.equal( ui.oldTab.length, 1, "oldTab length" );
strictEqual( ui.oldTab[ 0 ], tabs[ 0 ], "oldTab" ); assert.strictEqual( ui.oldTab[ 0 ], tabs[ 0 ], "oldTab" );
equal( ui.oldPanel.length, 1, "oldPanel length" ); assert.equal( ui.oldPanel.length, 1, "oldPanel length" );
strictEqual( ui.oldPanel[ 0 ], panels[ 0 ], "oldPanel" ); assert.strictEqual( ui.oldPanel[ 0 ], panels[ 0 ], "oldPanel" );
equal( ui.newTab.length, 1, "newTab length" ); assert.equal( ui.newTab.length, 1, "newTab length" );
strictEqual( ui.newTab[ 0 ], tabs[ 1 ], "newTab" ); assert.strictEqual( ui.newTab[ 0 ], tabs[ 1 ], "newTab" );
equal( ui.newPanel.length, 1, "newPanel length" ); assert.equal( ui.newPanel.length, 1, "newPanel length" );
strictEqual( ui.newPanel[ 0 ], panels[ 1 ], "newPanel" ); assert.strictEqual( ui.newPanel[ 0 ], panels[ 1 ], "newPanel" );
state( element, 1, 0, 0 ); state( assert, element, 1, 0, 0 );
} ); } );
anchors.eq( 1 ).trigger( "click" ); anchors.eq( 1 ).trigger( "click" );
state( element, 0, 1, 0 ); state( assert, element, 0, 1, 0 );
// Collapsing // Collapsing
element.one( "tabsbeforeactivate", function( event, ui ) { element.one( "tabsbeforeactivate", function( event, ui ) {
ok( !( "originalEvent" in event ), "originalEvent" ); assert.ok( !( "originalEvent" in event ), "originalEvent" );
equal( ui.oldTab.length, 1, "oldTab length" ); assert.equal( ui.oldTab.length, 1, "oldTab length" );
strictEqual( ui.oldTab[ 0 ], tabs[ 1 ], "oldTab" ); assert.strictEqual( ui.oldTab[ 0 ], tabs[ 1 ], "oldTab" );
equal( ui.oldPanel.length, 1, "oldPanel length" ); assert.equal( ui.oldPanel.length, 1, "oldPanel length" );
strictEqual( ui.oldPanel[ 0 ], panels[ 1 ], "oldPanel" ); assert.strictEqual( ui.oldPanel[ 0 ], panels[ 1 ], "oldPanel" );
equal( ui.newTab.length, 0, "newTab length" ); assert.equal( ui.newTab.length, 0, "newTab length" );
equal( ui.newPanel.length, 0, "newPanel length" ); assert.equal( ui.newPanel.length, 0, "newPanel length" );
state( element, 0, 1, 0 ); state( assert, element, 0, 1, 0 );
} ); } );
element.tabs( "option", "active", false ); element.tabs( "option", "active", false );
state( element, 0, 0, 0 ); state( assert, element, 0, 0, 0 );
// Prevent activation // Prevent activation
element.one( "tabsbeforeactivate", function( event, ui ) { element.one( "tabsbeforeactivate", function( event, ui ) {
ok( !( "originalEvent" in event ), "originalEvent" ); assert.ok( !( "originalEvent" in event ), "originalEvent" );
equal( ui.oldTab.length, 0, "oldTab length" ); assert.equal( ui.oldTab.length, 0, "oldTab length" );
equal( ui.oldPanel.length, 0, "oldTab" ); assert.equal( ui.oldPanel.length, 0, "oldTab" );
equal( ui.newTab.length, 1, "newTab length" ); assert.equal( ui.newTab.length, 1, "newTab length" );
strictEqual( ui.newTab[ 0 ], tabs[ 1 ], "newTab" ); assert.strictEqual( ui.newTab[ 0 ], tabs[ 1 ], "newTab" );
equal( ui.newPanel.length, 1, "newPanel length" ); assert.equal( ui.newPanel.length, 1, "newPanel length" );
strictEqual( ui.newPanel[ 0 ], panels[ 1 ], "newPanel" ); assert.strictEqual( ui.newPanel[ 0 ], panels[ 1 ], "newPanel" );
event.preventDefault(); event.preventDefault();
state( element, 0, 0, 0 ); state( assert, element, 0, 0, 0 );
} ); } );
element.tabs( "option", "active", 1 ); element.tabs( "option", "active", 1 );
state( element, 0, 0, 0 ); state( assert, element, 0, 0, 0 );
} ); } );
test( "activate", function() { QUnit.test( "activate", function( assert ) {
expect( 30 ); assert.expect( 30 );
var element = $( "#tabs1" ).tabs( { var element = $( "#tabs1" ).tabs( {
active: false, active: false,
@ -131,61 +132,61 @@ test( "activate", function() {
// From collapsed // From collapsed
element.one( "tabsactivate", function( event, ui ) { element.one( "tabsactivate", function( event, ui ) {
ok( !( "originalEvent" in event ), "originalEvent" ); assert.ok( !( "originalEvent" in event ), "originalEvent" );
equal( ui.oldTab.length, 0, "oldTab length" ); assert.equal( ui.oldTab.length, 0, "oldTab length" );
equal( ui.oldPanel.length, 0, "oldPanel length" ); assert.equal( ui.oldPanel.length, 0, "oldPanel length" );
equal( ui.newTab.length, 1, "newTab length" ); assert.equal( ui.newTab.length, 1, "newTab length" );
strictEqual( ui.newTab[ 0 ], tabs[ 0 ], "newTab" ); assert.strictEqual( ui.newTab[ 0 ], tabs[ 0 ], "newTab" );
equal( ui.newPanel.length, 1, "newPanel length" ); assert.equal( ui.newPanel.length, 1, "newPanel length" );
strictEqual( ui.newPanel[ 0 ], panels[ 0 ], "newPanel" ); assert.strictEqual( ui.newPanel[ 0 ], panels[ 0 ], "newPanel" );
state( element, 1, 0, 0 ); state( assert, element, 1, 0, 0 );
} ); } );
element.tabs( "option", "active", 0 ); element.tabs( "option", "active", 0 );
state( element, 1, 0, 0 ); state( assert, element, 1, 0, 0 );
// Switching tabs // Switching tabs
element.one( "tabsactivate", function( event, ui ) { element.one( "tabsactivate", function( event, ui ) {
equal( event.originalEvent.type, "click", "originalEvent" ); assert.equal( event.originalEvent.type, "click", "originalEvent" );
equal( ui.oldTab.length, 1, "oldTab length" ); assert.equal( ui.oldTab.length, 1, "oldTab length" );
strictEqual( ui.oldTab[ 0 ], tabs[ 0 ], "oldTab" ); assert.strictEqual( ui.oldTab[ 0 ], tabs[ 0 ], "oldTab" );
equal( ui.oldPanel.length, 1, "oldPanel length" ); assert.equal( ui.oldPanel.length, 1, "oldPanel length" );
strictEqual( ui.oldPanel[ 0 ], panels[ 0 ], "oldPanel" ); assert.strictEqual( ui.oldPanel[ 0 ], panels[ 0 ], "oldPanel" );
equal( ui.newTab.length, 1, "newTab length" ); assert.equal( ui.newTab.length, 1, "newTab length" );
strictEqual( ui.newTab[ 0 ], tabs[ 1 ], "newTab" ); assert.strictEqual( ui.newTab[ 0 ], tabs[ 1 ], "newTab" );
equal( ui.newPanel.length, 1, "newPanel length" ); assert.equal( ui.newPanel.length, 1, "newPanel length" );
strictEqual( ui.newPanel[ 0 ], panels[ 1 ], "newPanel" ); assert.strictEqual( ui.newPanel[ 0 ], panels[ 1 ], "newPanel" );
state( element, 0, 1, 0 ); state( assert, element, 0, 1, 0 );
} ); } );
anchors.eq( 1 ).trigger( "click" ); anchors.eq( 1 ).trigger( "click" );
state( element, 0, 1, 0 ); state( assert, element, 0, 1, 0 );
// Collapsing // Collapsing
element.one( "tabsactivate", function( event, ui ) { element.one( "tabsactivate", function( event, ui ) {
ok( !( "originalEvent" in event ), "originalEvent" ); assert.ok( !( "originalEvent" in event ), "originalEvent" );
equal( ui.oldTab.length, 1, "oldTab length" ); assert.equal( ui.oldTab.length, 1, "oldTab length" );
strictEqual( ui.oldTab[ 0 ], tabs[ 1 ], "oldTab" ); assert.strictEqual( ui.oldTab[ 0 ], tabs[ 1 ], "oldTab" );
equal( ui.oldPanel.length, 1, "oldPanel length" ); assert.equal( ui.oldPanel.length, 1, "oldPanel length" );
strictEqual( ui.oldPanel[ 0 ], panels[ 1 ], "oldPanel" ); assert.strictEqual( ui.oldPanel[ 0 ], panels[ 1 ], "oldPanel" );
equal( ui.newTab.length, 0, "newTab length" ); assert.equal( ui.newTab.length, 0, "newTab length" );
equal( ui.newPanel.length, 0, "newPanel length" ); assert.equal( ui.newPanel.length, 0, "newPanel length" );
state( element, 0, 0, 0 ); state( assert, element, 0, 0, 0 );
} ); } );
element.tabs( "option", "active", false ); element.tabs( "option", "active", false );
state( element, 0, 0, 0 ); state( assert, element, 0, 0, 0 );
// Prevent activation // Prevent activation
element.one( "tabsbeforeactivate", function( event ) { element.one( "tabsbeforeactivate", function( event ) {
ok( true, "tabsbeforeactivate" ); assert.ok( true, "tabsbeforeactivate" );
event.preventDefault(); event.preventDefault();
} ); } );
element.one( "tabsactivate", function() { element.one( "tabsactivate", function() {
ok( false, "tabsactivate" ); assert.ok( false, "tabsactivate" );
} ); } );
element.tabs( "option", "active", 1 ); element.tabs( "option", "active", 1 );
} ); } );
test( "beforeLoad", function() { QUnit.test( "beforeLoad", function( assert ) {
expect( 32 ); assert.expect( 32 );
var tab, panelId, panel, var tab, panelId, panel,
element = $( "#tabs2" ); element = $( "#tabs2" );
@ -196,20 +197,20 @@ test( "beforeLoad", function() {
panelId = tab.attr( "aria-controls" ); panelId = tab.attr( "aria-controls" );
panel = $( "#" + panelId ); panel = $( "#" + panelId );
ok( !( "originalEvent" in event ), "originalEvent" ); assert.ok( !( "originalEvent" in event ), "originalEvent" );
ok( "abort" in ui.jqXHR, "jqXHR" ); assert.ok( "abort" in ui.jqXHR, "jqXHR" );
ok( ui.ajaxSettings.url, "data/test.html", "ajaxSettings.url" ); assert.ok( ui.ajaxSettings.url, "data/test.html", "ajaxSettings.url" );
equal( ui.tab.length, 1, "tab length" ); assert.equal( ui.tab.length, 1, "tab length" );
strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" ); assert.strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
equal( ui.panel.length, 1, "panel length" ); assert.equal( ui.panel.length, 1, "panel length" );
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" ); assert.strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
equal( ui.panel.html(), "", "panel html" ); assert.equal( ui.panel.html(), "", "panel html" );
event.preventDefault(); event.preventDefault();
state( element, 0, 0, 1, 0, 0 ); state( assert, element, 0, 0, 1, 0, 0 );
} ); } );
element.tabs( { active: 2 } ); element.tabs( { active: 2 } );
state( element, 0, 0, 1, 0, 0 ); state( assert, element, 0, 0, 1, 0, 0 );
equal( panel.html(), "", "panel html after" ); assert.equal( panel.html(), "", "panel html after" );
element.tabs( "destroy" ); element.tabs( "destroy" );
// .option() // .option()
@ -218,21 +219,21 @@ test( "beforeLoad", function() {
panelId = tab.attr( "aria-controls" ); panelId = tab.attr( "aria-controls" );
panel = $( "#" + panelId ); panel = $( "#" + panelId );
ok( !( "originalEvent" in event ), "originalEvent" ); assert.ok( !( "originalEvent" in event ), "originalEvent" );
ok( "abort" in ui.jqXHR, "jqXHR" ); assert.ok( "abort" in ui.jqXHR, "jqXHR" );
ok( ui.ajaxSettings.url, "data/test.html", "ajaxSettings.url" ); assert.ok( ui.ajaxSettings.url, "data/test.html", "ajaxSettings.url" );
equal( ui.tab.length, 1, "tab length" ); assert.equal( ui.tab.length, 1, "tab length" );
strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" ); assert.strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
equal( ui.panel.length, 1, "panel length" ); assert.equal( ui.panel.length, 1, "panel length" );
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" ); assert.strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
equal( ui.panel.html(), "", "panel html" ); assert.equal( ui.panel.html(), "", "panel html" );
event.preventDefault(); event.preventDefault();
state( element, 1, 0, 0, 0, 0 ); state( assert, element, 1, 0, 0, 0, 0 );
} ); } );
element.tabs(); element.tabs();
element.tabs( "option", "active", 2 ); element.tabs( "option", "active", 2 );
state( element, 0, 0, 1, 0, 0 ); state( assert, element, 0, 0, 1, 0, 0 );
equal( panel.html(), "", "panel html after" ); assert.equal( panel.html(), "", "panel html after" );
// Click, change panel content // Click, change panel content
element.one( "tabsbeforeload", function( event, ui ) { element.one( "tabsbeforeload", function( event, ui ) {
@ -240,26 +241,27 @@ test( "beforeLoad", function() {
panelId = tab.attr( "aria-controls" ); panelId = tab.attr( "aria-controls" );
panel = $( "#" + panelId ); panel = $( "#" + panelId );
equal( event.originalEvent.type, "click", "originalEvent" ); assert.equal( event.originalEvent.type, "click", "originalEvent" );
ok( "abort" in ui.jqXHR, "jqXHR" ); assert.ok( "abort" in ui.jqXHR, "jqXHR" );
ok( ui.ajaxSettings.url, "data/test.html", "ajaxSettings.url" ); assert.ok( ui.ajaxSettings.url, "data/test.html", "ajaxSettings.url" );
equal( ui.tab.length, 1, "tab length" ); assert.equal( ui.tab.length, 1, "tab length" );
strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" ); assert.strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
equal( ui.panel.length, 1, "panel length" ); assert.equal( ui.panel.length, 1, "panel length" );
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" ); assert.strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
ui.panel.html( "<p>testing</p>" ); ui.panel.html( "<p>testing</p>" );
event.preventDefault(); event.preventDefault();
state( element, 0, 0, 1, 0, 0 ); state( assert, element, 0, 0, 1, 0, 0 );
} ); } );
element.find( ".ui-tabs-nav .ui-tabs-anchor" ).eq( 3 ).trigger( "click" ); element.find( ".ui-tabs-nav .ui-tabs-anchor" ).eq( 3 ).trigger( "click" );
state( element, 0, 0, 0, 1, 0 ); state( assert, element, 0, 0, 0, 1, 0 );
// .toLowerCase() is needed to convert <P> to <p> in old IEs // .toLowerCase() is needed to convert <P> to <p> in old IEs
equal( panel.html().toLowerCase(), "<p>testing</p>", "panel html after" ); assert.equal( panel.html().toLowerCase(), "<p>testing</p>", "panel html after" );
} ); } );
asyncTest( "load", function() { QUnit.test( "load", function( assert ) {
expect( 21 ); var ready = assert.async();
assert.expect( 21 );
var tab, panelId, panel, var tab, panelId, panel,
element = $( "#tabs2" ); element = $( "#tabs2" );
@ -270,13 +272,13 @@ asyncTest( "load", function() {
panelId = tab.attr( "aria-controls" ); panelId = tab.attr( "aria-controls" );
panel = $( "#" + panelId ); panel = $( "#" + panelId );
ok( !( "originalEvent" in event ), "originalEvent" ); assert.ok( !( "originalEvent" in event ), "originalEvent" );
equal( ui.tab.length, 1, "tab length" ); assert.equal( ui.tab.length, 1, "tab length" );
strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" ); assert.strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
equal( ui.panel.length, 1, "panel length" ); assert.equal( ui.panel.length, 1, "panel length" );
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" ); assert.strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
equal( ui.panel.find( "p" ).length, 1, "panel html" ); assert.equal( ui.panel.find( "p" ).length, 1, "panel html" );
state( element, 0, 0, 1, 0, 0 ); state( assert, element, 0, 0, 1, 0, 0 );
tabsload1(); tabsload1();
} ); } );
element.tabs( { active: 2 } ); element.tabs( { active: 2 } );
@ -289,13 +291,13 @@ asyncTest( "load", function() {
panelId = tab.attr( "aria-controls" ); panelId = tab.attr( "aria-controls" );
panel = $( "#" + panelId ); panel = $( "#" + panelId );
ok( !( "originalEvent" in event ), "originalEvent" ); assert.ok( !( "originalEvent" in event ), "originalEvent" );
equal( ui.tab.length, 1, "tab length" ); assert.equal( ui.tab.length, 1, "tab length" );
strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" ); assert.strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
equal( ui.panel.length, 1, "panel length" ); assert.equal( ui.panel.length, 1, "panel length" );
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" ); assert.strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
equal( ui.panel.find( "p" ).length, 1, "panel html" ); assert.equal( ui.panel.find( "p" ).length, 1, "panel html" );
state( element, 0, 0, 0, 1, 0 ); state( assert, element, 0, 0, 0, 1, 0 );
tabsload2(); tabsload2();
} ); } );
element.tabs( "option", "active", 3 ); element.tabs( "option", "active", 3 );
@ -303,20 +305,20 @@ asyncTest( "load", function() {
function tabsload2() { function tabsload2() {
// click, change panel content // Click, change panel content
element.one( "tabsload", function( event, ui ) { element.one( "tabsload", function( event, ui ) {
tab = element.find( ".ui-tabs-nav li" ).eq( 4 ); tab = element.find( ".ui-tabs-nav li" ).eq( 4 );
panelId = tab.attr( "aria-controls" ); panelId = tab.attr( "aria-controls" );
panel = $( "#" + panelId ); panel = $( "#" + panelId );
equal( event.originalEvent.type, "click", "originalEvent" ); assert.equal( event.originalEvent.type, "click", "originalEvent" );
equal( ui.tab.length, 1, "tab length" ); assert.equal( ui.tab.length, 1, "tab length" );
strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" ); assert.strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
equal( ui.panel.length, 1, "panel length" ); assert.equal( ui.panel.length, 1, "panel length" );
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" ); assert.strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
equal( ui.panel.find( "p" ).length, 1, "panel html" ); assert.equal( ui.panel.find( "p" ).length, 1, "panel html" );
state( element, 0, 0, 0, 0, 1 ); state( assert, element, 0, 0, 0, 0, 1 );
start(); ready();
} ); } );
element.find( ".ui-tabs-nav .ui-tabs-anchor" ).eq( 4 ).trigger( "click" ); element.find( ".ui-tabs-nav .ui-tabs-anchor" ).eq( 4 ).trigger( "click" );
} }

View File

@ -5,7 +5,7 @@ define( [
], function( $, helper ) { ], function( $, helper ) {
return $.extend( helper, { return $.extend( helper, {
disabled: function( tabs, state ) { disabled: function( assert, tabs, state ) {
var expected, actual, var expected, actual,
internalState = tabs.tabs( "option", "disabled" ); internalState = tabs.tabs( "option", "disabled" );
@ -18,7 +18,7 @@ return $.extend( helper, {
} ); } );
} }
expected = $.map( new Array( tabs.find ( ".ui-tabs-nav li" ).length ), function( _, index ) { expected = $.map( new Array( tabs.find( ".ui-tabs-nav li" ).length ), function( _, index ) {
if ( typeof state === "boolean" ) { if ( typeof state === "boolean" ) {
return state ? 1 : 0; return state ? 1 : 0;
} else { } else {
@ -37,25 +37,25 @@ return $.extend( helper, {
return 0; return 0;
} }
// mixed state - invalid // Mixed state - invalid
return -1; return -1;
} ).get(); } ).get();
deepEqual( tabs.tabs( "option", "disabled" ), state ); assert.deepEqual( tabs.tabs( "option", "disabled" ), state );
deepEqual( actual, expected ); assert.deepEqual( actual, expected );
}, },
equalHeight: function( tabs, height ) { equalHeight: function( assert, tabs, height ) {
tabs.find( ".ui-tabs-panel" ).each( function() { tabs.find( ".ui-tabs-panel" ).each( function() {
// Handle overly-precise values // Handle overly-precise values
var actualHeight = parseFloat( $( this ).outerHeight().toFixed( 1 ) ); var actualHeight = parseFloat( $( this ).outerHeight().toFixed( 1 ) );
equal( actualHeight, height ); assert.equal( actualHeight, height );
} ); } );
}, },
state: function( tabs ) { state: function( assert, tabs ) {
var expected = $.makeArray( arguments ).slice( 1 ), var expected = $.makeArray( arguments ).slice( 2 ),
actual = tabs.find( ".ui-tabs-nav li" ).map( function() { actual = tabs.find( ".ui-tabs-nav li" ).map( function() {
var tab = $( this ), var tab = $( this ),
panel = $( $.ui.tabs.prototype._sanitizeSelector( panel = $( $.ui.tabs.prototype._sanitizeSelector(
@ -69,9 +69,9 @@ return $.extend( helper, {
if ( !tabIsActive && !panelIsActive ) { if ( !tabIsActive && !panelIsActive ) {
return 0; return 0;
} }
return -1; // mixed state - invalid return -1; // Mixed state - invalid
} ).get(); } ).get();
deepEqual( actual, expected ); assert.deepEqual( actual, expected );
} }
} ); } );

View File

@ -1,16 +1,17 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"./helper", "./helper",
"ui/widgets/tabs" "ui/widgets/tabs"
], function( $, testHelper ) { ], function( QUnit, $, testHelper ) {
var disabled = testHelper.disabled, var disabled = testHelper.disabled,
state = testHelper.state; state = testHelper.state;
module( "tabs: methods" ); QUnit.module( "tabs: methods" );
test( "destroy", function( assert ) { QUnit.test( "destroy", function( assert ) {
expect( 2 ); assert.expect( 2 );
assert.domEqual( "#tabs1", function() { assert.domEqual( "#tabs1", function() {
$( "#tabs1" ).tabs().tabs( "destroy" ); $( "#tabs1" ).tabs().tabs( "destroy" );
} ); } );
@ -19,15 +20,16 @@ test( "destroy", function( assert ) {
} ); } );
} ); } );
asyncTest( "destroy - ajax", function( assert ) { QUnit.test( "destroy - ajax", function( assert ) {
expect( 1 ); var ready = assert.async();
assert.expect( 1 );
assert.domEqual( "#tabs2", function( done ) { assert.domEqual( "#tabs2", function( done ) {
var element = $( "#tabs2" ).tabs( { var element = $( "#tabs2" ).tabs( {
load: function() { load: function() {
setTimeout( function() { setTimeout( function() {
element.tabs( "destroy" ); element.tabs( "destroy" );
done(); done();
start(); ready();
} ); } );
} }
} ); } );
@ -35,108 +37,108 @@ asyncTest( "destroy - ajax", function( assert ) {
} ); } );
} ); } );
test( "enable", function() { QUnit.test( "enable", function( assert ) {
expect( 8 ); assert.expect( 8 );
var element = $( "#tabs1" ).tabs( { disabled: true } ); var element = $( "#tabs1" ).tabs( { disabled: true } );
disabled( element, true ); disabled( assert, element, true );
element.tabs( "enable" ); element.tabs( "enable" );
disabled( element, false ); disabled( assert, element, false );
element.tabs( "destroy" ); element.tabs( "destroy" );
element.tabs( { disabled: [ 0, 1 ] } ); element.tabs( { disabled: [ 0, 1 ] } );
disabled( element, [ 0, 1 ] ); disabled( assert, element, [ 0, 1 ] );
element.tabs( "enable" ); element.tabs( "enable" );
disabled( element, false ); disabled( assert, element, false );
} ); } );
test( "enable( index )", function() { QUnit.test( "enable( index )", function( assert ) {
expect( 10 ); assert.expect( 10 );
var element = $( "#tabs1" ).tabs( { disabled: true } ); var element = $( "#tabs1" ).tabs( { disabled: true } );
disabled( element, true ); disabled( assert, element, true );
// fully disabled -> partially disabled // fully disabled -> partially disabled
element.tabs( "enable", 1 ); element.tabs( "enable", 1 );
disabled( element, [ 0, 2 ] ); disabled( assert, element, [ 0, 2 ] );
// partially disabled -> partially disabled // partially disabled -> partially disabled
element.tabs( "enable", 2 ); element.tabs( "enable", 2 );
disabled( element, [ 0 ] ); disabled( assert, element, [ 0 ] );
// already enabled tab, no change // already enabled tab, no change
element.tabs( "enable", 2 ); element.tabs( "enable", 2 );
disabled( element, [ 0 ] ); disabled( assert, element, [ 0 ] );
// partially disabled -> fully enabled // partially disabled -> fully enabled
element.tabs( "enable", 0 ); element.tabs( "enable", 0 );
disabled( element, false ); disabled( assert, element, false );
} ); } );
test( "disable", function() { QUnit.test( "disable", function( assert ) {
expect( 8 ); assert.expect( 8 );
var element = $( "#tabs1" ).tabs( { disabled: false } ); var element = $( "#tabs1" ).tabs( { disabled: false } );
disabled( element, false ); disabled( assert, element, false );
element.tabs( "disable" ); element.tabs( "disable" );
disabled( element, true ); disabled( assert, element, true );
element.tabs( "destroy" ); element.tabs( "destroy" );
element.tabs( { disabled: [ 0, 1 ] } ); element.tabs( { disabled: [ 0, 1 ] } );
disabled( element, [ 0, 1 ] ); disabled( assert, element, [ 0, 1 ] );
element.tabs( "disable" ); element.tabs( "disable" );
disabled( element, true ); disabled( assert, element, true );
} ); } );
test( "disable( index )", function() { QUnit.test( "disable( index )", function( assert ) {
expect( 10 ); assert.expect( 10 );
var element = $( "#tabs1" ).tabs( { disabled: false } ); var element = $( "#tabs1" ).tabs( { disabled: false } );
disabled( element, false ); disabled( assert, element, false );
// fully enabled -> partially disabled // fully enabled -> partially disabled
element.tabs( "disable", 1 ); element.tabs( "disable", 1 );
disabled( element, [ 1 ] ); disabled( assert, element, [ 1 ] );
// partially disabled -> partially disabled // partially disabled -> partially disabled
element.tabs( "disable", 2 ); element.tabs( "disable", 2 );
disabled( element, [ 1, 2 ] ); disabled( assert, element, [ 1, 2 ] );
// already disabled tab, no change // already disabled tab, no change
element.tabs( "disable", 2 ); element.tabs( "disable", 2 );
disabled( element, [ 1, 2 ] ); disabled( assert, element, [ 1, 2 ] );
// partially disabled -> fully disabled // partially disabled -> fully disabled
element.tabs( "disable", 0 ); element.tabs( "disable", 0 );
disabled( element, true ); disabled( assert, element, true );
} ); } );
test( "refresh", function() { QUnit.test( "refresh", function( assert ) {
expect( 27 ); assert.expect( 27 );
var element = $( "#tabs1" ).tabs(); var element = $( "#tabs1" ).tabs();
state( element, 1, 0, 0 ); state( assert, element, 1, 0, 0 );
disabled( element, false ); disabled( assert, element, false );
// Disable tab via markup // Disable tab via markup
element.find( ".ui-tabs-nav li" ).eq( 1 ).addClass( "ui-state-disabled" ); element.find( ".ui-tabs-nav li" ).eq( 1 ).addClass( "ui-state-disabled" );
element.tabs( "refresh" ); element.tabs( "refresh" );
state( element, 1, 0, 0 ); state( assert, element, 1, 0, 0 );
disabled( element, [ 1 ] ); disabled( assert, element, [ 1 ] );
// Add remote tab // Add remote tab
element.find( ".ui-tabs-nav" ).append( "<li id='newTab'><a href='data/test.html'>new</a></li>" ); element.find( ".ui-tabs-nav" ).append( "<li id='newTab'><a href='data/test.html'>new</a></li>" );
element.tabs( "refresh" ); element.tabs( "refresh" );
state( element, 1, 0, 0, 0 ); state( assert, element, 1, 0, 0, 0 );
disabled( element, [ 1 ] ); disabled( assert, element, [ 1 ] );
equal( element.find( "#" + $( "#newTab" ).attr( "aria-controls" ) ).length, 1, assert.equal( element.find( "#" + $( "#newTab" ).attr( "aria-controls" ) ).length, 1,
"panel added for remote tab" ); "panel added for remote tab" );
// Remove all tabs // Remove all tabs
element.find( ".ui-tabs-nav li, .ui-tabs-panel" ).remove(); element.find( ".ui-tabs-nav li, .ui-tabs-panel" ).remove();
element.tabs( "refresh" ); element.tabs( "refresh" );
state( element ); state( assert, element );
equal( element.tabs( "option", "active" ), false, "no active tab" ); assert.equal( element.tabs( "option", "active" ), false, "no active tab" );
// Add tabs // Add tabs
element.find( ".ui-tabs-nav" ) element.find( ".ui-tabs-nav" )
@ -150,45 +152,45 @@ test( "refresh", function() {
.append( "<div id='newTab4'>new 4</div>" ) .append( "<div id='newTab4'>new 4</div>" )
.append( "<div id='newTab5'>new 5</div>" ); .append( "<div id='newTab5'>new 5</div>" );
element.tabs( "refresh" ); element.tabs( "refresh" );
state( element, 0, 0, 0, 0 ); state( assert, element, 0, 0, 0, 0 );
disabled( element, [ 0 ] ); disabled( assert, element, [ 0 ] );
// Activate third tab // Activate third tab
element.tabs( "option", "active", 2 ); element.tabs( "option", "active", 2 );
state( element, 0, 0, 1, 0 ); state( assert, element, 0, 0, 1, 0 );
disabled( element, [ 0 ] ); disabled( assert, element, [ 0 ] );
// Remove fourth tab, third tab should stay active // Remove fourth tab, third tab should stay active
element.find( ".ui-tabs-nav li" ).eq( 3 ).remove(); element.find( ".ui-tabs-nav li" ).eq( 3 ).remove();
element.find( ".ui-tabs-panel" ).eq( 3 ).remove(); element.find( ".ui-tabs-panel" ).eq( 3 ).remove();
element.tabs( "refresh" ); element.tabs( "refresh" );
state( element, 0, 0, 1 ); state( assert, element, 0, 0, 1 );
disabled( element, [ 0 ] ); disabled( assert, element, [ 0 ] );
// Remove third (active) tab, second tab should become active // Remove third (active) tab, second tab should become active
element.find( ".ui-tabs-nav li" ).eq( 2 ).remove(); element.find( ".ui-tabs-nav li" ).eq( 2 ).remove();
element.find( ".ui-tabs-panel" ).eq( 2 ).remove(); element.find( ".ui-tabs-panel" ).eq( 2 ).remove();
element.tabs( "refresh" ); element.tabs( "refresh" );
state( element, 0, 1 ); state( assert, element, 0, 1 );
disabled( element, [ 0 ] ); disabled( assert, element, [ 0 ] );
// Remove first tab, previously active tab (now first) should stay active // Remove first tab, previously active tab (now first) should stay active
element.find( ".ui-tabs-nav li" ).eq( 0 ).remove(); element.find( ".ui-tabs-nav li" ).eq( 0 ).remove();
element.find( ".ui-tabs-panel" ).eq( 0 ).remove(); element.find( ".ui-tabs-panel" ).eq( 0 ).remove();
element.tabs( "refresh" ); element.tabs( "refresh" );
state( element, 1 ); state( assert, element, 1 );
disabled( element, false ); disabled( assert, element, false );
} ); } );
test( "refresh - looping", function() { QUnit.test( "refresh - looping", function( assert ) {
expect( 6 ); assert.expect( 6 );
var element = $( "#tabs1" ).tabs( { var element = $( "#tabs1" ).tabs( {
disabled: [ 0 ], disabled: [ 0 ],
active: 1 active: 1
} ); } );
state( element, 0, 1, 0 ); state( assert, element, 0, 1, 0 );
disabled( element, [ 0 ] ); disabled( assert, element, [ 0 ] );
// Remove active, jump to previous // Remove active, jump to previous
// previous is disabled, just back one more // previous is disabled, just back one more
@ -196,12 +198,13 @@ test( "refresh - looping", function() {
// activate last tab // activate last tab
element.find( ".ui-tabs-nav li" ).eq( 2 ).remove(); element.find( ".ui-tabs-nav li" ).eq( 2 ).remove();
element.tabs( "refresh" ); element.tabs( "refresh" );
state( element, 0, 1 ); state( assert, element, 0, 1 );
disabled( element, [ 0 ] ); disabled( assert, element, [ 0 ] );
} ); } );
asyncTest( "load", function() { QUnit.test( "load", function( assert ) {
expect( 30 ); var ready = assert.async();
assert.expect( 30 );
var element = $( "#tabs2" ).tabs(); var element = $( "#tabs2" ).tabs();
@ -212,12 +215,12 @@ asyncTest( "load", function() {
panelId = tab.attr( "aria-controls" ), panelId = tab.attr( "aria-controls" ),
panel = $( "#" + panelId ); panel = $( "#" + panelId );
ok( !( "originalEvent" in event ), "originalEvent" ); assert.ok( !( "originalEvent" in event ), "originalEvent" );
equal( ui.tab.length, 1, "tab length" ); assert.equal( ui.tab.length, 1, "tab length" );
strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" ); assert.strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
equal( ui.panel.length, 1, "panel length" ); assert.equal( ui.panel.length, 1, "panel length" );
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" ); assert.strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
state( element, 1, 0, 0, 0, 0 ); state( assert, element, 1, 0, 0, 0, 0 );
} ); } );
element.one( "tabsload", function( event, ui ) { element.one( "tabsload", function( event, ui ) {
@ -228,30 +231,30 @@ asyncTest( "load", function() {
panelId = tab.attr( "aria-controls" ), panelId = tab.attr( "aria-controls" ),
panel = $( "#" + panelId ); panel = $( "#" + panelId );
ok( !( "originalEvent" in event ), "originalEvent" ); assert.ok( !( "originalEvent" in event ), "originalEvent" );
equal( uiTab.length, 1, "tab length" ); assert.equal( uiTab.length, 1, "tab length" );
strictEqual( uiTab[ 0 ], tab[ 0 ], "tab" ); assert.strictEqual( uiTab[ 0 ], tab[ 0 ], "tab" );
equal( uiPanel.length, 1, "panel length" ); assert.equal( uiPanel.length, 1, "panel length" );
strictEqual( uiPanel[ 0 ], panel[ 0 ], "panel" ); assert.strictEqual( uiPanel[ 0 ], panel[ 0 ], "panel" );
equal( uiPanel.find( "p" ).length, 1, "panel html" ); assert.equal( uiPanel.find( "p" ).length, 1, "panel html" );
state( element, 1, 0, 0, 0, 0 ); state( assert, element, 1, 0, 0, 0, 0 );
setTimeout( tabsload1 ); setTimeout( tabsload1 );
} ); } );
element.tabs( "load", 3 ); element.tabs( "load", 3 );
state( element, 1, 0, 0, 0, 0 ); state( assert, element, 1, 0, 0, 0, 0 );
function tabsload1() { function tabsload1() {
// no need to test details of event (tested in events tests) // no need to test details of event (tested in events tests)
element.one( "tabsbeforeload", function() { element.one( "tabsbeforeload", function() {
ok( true, "tabsbeforeload invoked" ); assert.ok( true, "tabsbeforeload invoked" );
} ); } );
element.one( "tabsload", function() { element.one( "tabsload", function() {
ok( true, "tabsload invoked" ); assert.ok( true, "tabsload invoked" );
setTimeout( tabsload2 ); setTimeout( tabsload2 );
} ); } );
element.tabs( "option", "active", 3 ); element.tabs( "option", "active", 3 );
state( element, 0, 0, 0, 1, 0 ); state( assert, element, 0, 0, 0, 1, 0 );
} }
function tabsload2() { function tabsload2() {
@ -262,12 +265,12 @@ asyncTest( "load", function() {
panelId = tab.attr( "aria-controls" ), panelId = tab.attr( "aria-controls" ),
panel = $( "#" + panelId ); panel = $( "#" + panelId );
ok( !( "originalEvent" in event ), "originalEvent" ); assert.ok( !( "originalEvent" in event ), "originalEvent" );
equal( ui.tab.length, 1, "tab length" ); assert.equal( ui.tab.length, 1, "tab length" );
strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" ); assert.strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
equal( ui.panel.length, 1, "panel length" ); assert.equal( ui.panel.length, 1, "panel length" );
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" ); assert.strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
state( element, 0, 0, 0, 1, 0 ); state( assert, element, 0, 0, 0, 1, 0 );
} ); } );
element.one( "tabsload", function( event, ui ) { element.one( "tabsload", function( event, ui ) {
@ -278,25 +281,25 @@ asyncTest( "load", function() {
panelId = tab.attr( "aria-controls" ), panelId = tab.attr( "aria-controls" ),
panel = $( "#" + panelId ); panel = $( "#" + panelId );
ok( !( "originalEvent" in event ), "originalEvent" ); assert.ok( !( "originalEvent" in event ), "originalEvent" );
equal( uiTab.length, 1, "tab length" ); assert.equal( uiTab.length, 1, "tab length" );
strictEqual( uiTab[ 0 ], tab[ 0 ], "tab" ); assert.strictEqual( uiTab[ 0 ], tab[ 0 ], "tab" );
equal( uiPanel.length, 1, "panel length" ); assert.equal( uiPanel.length, 1, "panel length" );
strictEqual( uiPanel[ 0 ], panel[ 0 ], "panel" ); assert.strictEqual( uiPanel[ 0 ], panel[ 0 ], "panel" );
state( element, 0, 0, 0, 1, 0 ); state( assert, element, 0, 0, 0, 1, 0 );
start(); ready();
} ); } );
element.tabs( "load", 3 ); element.tabs( "load", 3 );
state( element, 0, 0, 0, 1, 0 ); state( assert, element, 0, 0, 0, 1, 0 );
} }
} ); } );
test( "widget", function() { QUnit.test( "widget", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( "#tabs1" ).tabs(), var element = $( "#tabs1" ).tabs(),
widgetElement = element.tabs( "widget" ); widgetElement = element.tabs( "widget" );
equal( widgetElement.length, 1, "one element" ); assert.equal( widgetElement.length, 1, "one element" );
strictEqual( widgetElement[ 0 ], element[ 0 ], "same element" ); assert.strictEqual( widgetElement[ 0 ], element[ 0 ], "same element" );
} ); } );
} ); } );

View File

@ -1,118 +1,119 @@
define( [ define( [
"qunit",
"jquery", "jquery",
"./helper", "./helper",
"ui/widgets/tabs" "ui/widgets/tabs"
], function( $, testHelper ) { ], function( QUnit, $, testHelper ) {
var disabled = testHelper.disabled, var disabled = testHelper.disabled,
equalHeight = testHelper.equalHeight, equalHeight = testHelper.equalHeight,
state = testHelper.state; state = testHelper.state;
module( "tabs: options" ); QUnit.module( "tabs: options" );
test( "{ active: default }", function() { QUnit.test( "{ active: default }", function( assert ) {
expect( 6 ); assert.expect( 6 );
var element = $( "#tabs1" ).tabs(); var element = $( "#tabs1" ).tabs();
equal( element.tabs( "option", "active" ), 0, "should be 0 by default" ); assert.equal( element.tabs( "option", "active" ), 0, "should be 0 by default" );
state( element, 1, 0, 0 ); state( assert, element, 1, 0, 0 );
element.tabs( "destroy" ); element.tabs( "destroy" );
location.hash = "#fragment-3"; location.hash = "#fragment-3";
element = $( "#tabs1" ).tabs(); element = $( "#tabs1" ).tabs();
equal( element.tabs( "option", "active" ), 2, "should be 2 based on URL" ); assert.equal( element.tabs( "option", "active" ), 2, "should be 2 based on URL" );
state( element, 0, 0, 1 ); state( assert, element, 0, 0, 1 );
element.tabs( "destroy" ); element.tabs( "destroy" );
location.hash = "#custom-id"; location.hash = "#custom-id";
element = $( "#tabs2" ).tabs(); element = $( "#tabs2" ).tabs();
equal( element.tabs( "option", "active" ), 3, "should be 3 based on URL" ); assert.equal( element.tabs( "option", "active" ), 3, "should be 3 based on URL" );
state( element, 0, 0, 0, 1, 0 ); state( assert, element, 0, 0, 0, 1, 0 );
element.tabs( "destroy" ); element.tabs( "destroy" );
location.hash = "#"; location.hash = "#";
} ); } );
test( "{ active: false }", function() { QUnit.test( "{ active: false }", function( assert ) {
expect( 7 ); assert.expect( 7 );
var element = $( "#tabs1" ).tabs( { var element = $( "#tabs1" ).tabs( {
active: false, active: false,
collapsible: true collapsible: true
} ); } );
state( element, 0, 0, 0 ); state( assert, element, 0, 0, 0 );
equal( element.find( ".ui-tabs-nav .ui-state-active" ).length, 0, "no tabs selected" ); assert.equal( element.find( ".ui-tabs-nav .ui-state-active" ).length, 0, "no tabs selected" );
strictEqual( element.tabs( "option", "active" ), false ); assert.strictEqual( element.tabs( "option", "active" ), false );
element.tabs( "option", "collapsible", false ); element.tabs( "option", "collapsible", false );
state( element, 1, 0, 0 ); state( assert, element, 1, 0, 0 );
equal( element.tabs( "option", "active" ), 0 ); assert.equal( element.tabs( "option", "active" ), 0 );
element.tabs( "destroy" ); element.tabs( "destroy" );
element.tabs( { element.tabs( {
active: false active: false
} ); } );
state( element, 1, 0, 0 ); state( assert, element, 1, 0, 0 );
strictEqual( element.tabs( "option", "active" ), 0 ); assert.strictEqual( element.tabs( "option", "active" ), 0 );
} ); } );
test( "{ active: Number }", function() { QUnit.test( "{ active: Number }", function( assert ) {
expect( 8 ); assert.expect( 8 );
var element = $( "#tabs1" ).tabs( { var element = $( "#tabs1" ).tabs( {
active: 2 active: 2
} ); } );
equal( element.tabs( "option", "active" ), 2 ); assert.equal( element.tabs( "option", "active" ), 2 );
state( element, 0, 0, 1 ); state( assert, element, 0, 0, 1 );
element.tabs( "option", "active", 0 ); element.tabs( "option", "active", 0 );
equal( element.tabs( "option", "active" ), 0 ); assert.equal( element.tabs( "option", "active" ), 0 );
state( element, 1, 0, 0 ); state( assert, element, 1, 0, 0 );
element.find( ".ui-tabs-nav .ui-tabs-anchor" ).eq( 1 ).trigger( "click" ); element.find( ".ui-tabs-nav .ui-tabs-anchor" ).eq( 1 ).trigger( "click" );
equal( element.tabs( "option", "active" ), 1 ); assert.equal( element.tabs( "option", "active" ), 1 );
state( element, 0, 1, 0 ); state( assert, element, 0, 1, 0 );
element.tabs( "option", "active", 10 ); element.tabs( "option", "active", 10 );
equal( element.tabs( "option", "active" ), 1 ); assert.equal( element.tabs( "option", "active" ), 1 );
state( element, 0, 1, 0 ); state( assert, element, 0, 1, 0 );
} ); } );
test( "{ active: -Number }", function() { QUnit.test( "{ active: -Number }", function( assert ) {
expect( 8 ); assert.expect( 8 );
var element = $( "#tabs1" ).tabs( { var element = $( "#tabs1" ).tabs( {
active: -1 active: -1
} ); } );
equal( element.tabs( "option", "active" ), 2 ); assert.equal( element.tabs( "option", "active" ), 2 );
state( element, 0, 0, 1 ); state( assert, element, 0, 0, 1 );
element.tabs( "option", "active", -2 ); element.tabs( "option", "active", -2 );
equal( element.tabs( "option", "active" ), 1 ); assert.equal( element.tabs( "option", "active" ), 1 );
state( element, 0, 1, 0 ); state( assert, element, 0, 1, 0 );
element.tabs( "option", "active", -10 ); element.tabs( "option", "active", -10 );
equal( element.tabs( "option", "active" ), 1 ); assert.equal( element.tabs( "option", "active" ), 1 );
state( element, 0, 1, 0 ); state( assert, element, 0, 1, 0 );
element.tabs( "option", "active", -3 ); element.tabs( "option", "active", -3 );
equal( element.tabs( "option", "active" ), 0 ); assert.equal( element.tabs( "option", "active" ), 0 );
state( element, 1, 0, 0 ); state( assert, element, 1, 0, 0 );
} ); } );
test( "active - mismatched tab/panel order", function() { QUnit.test( "active - mismatched tab/panel order", function( assert ) {
expect( 3 ); assert.expect( 3 );
location.hash = "#tabs7-2"; location.hash = "#tabs7-2";
var element = $( "#tabs7" ).tabs(); var element = $( "#tabs7" ).tabs();
equal( element.tabs( "option", "active" ), 1, "should be 1 based on URL" ); assert.equal( element.tabs( "option", "active" ), 1, "should be 1 based on URL" );
state( element, 0, 1 ); state( assert, element, 0, 1 );
element.tabs( "option", "active", 0 ); element.tabs( "option", "active", 0 );
state( element, 1, 0 ); state( assert, element, 1, 0 );
location.hash = "#"; location.hash = "#";
} ); } );
test( "collapsible", function( assert ) { QUnit.test( "collapsible", function( assert ) {
expect( 13 ); assert.expect( 13 );
var element = $( "#tabs1" ).tabs( { var element = $( "#tabs1" ).tabs( {
active: 1, active: 1,
@ -120,16 +121,16 @@ test( "collapsible", function( assert ) {
} ); } );
assert.hasClasses( element, "ui-tabs-collapsible" ); assert.hasClasses( element, "ui-tabs-collapsible" );
element.tabs( "option", "active", false ); element.tabs( "option", "active", false );
equal( element.tabs( "option", "active" ), false ); assert.equal( element.tabs( "option", "active" ), false );
state( element, 0, 0, 0 ); state( assert, element, 0, 0, 0 );
element.tabs( "option", "active", 1 ); element.tabs( "option", "active", 1 );
equal( element.tabs( "option", "active" ), 1 ); assert.equal( element.tabs( "option", "active" ), 1 );
state( element, 0, 1, 0 ); state( assert, element, 0, 1, 0 );
element.find( ".ui-state-active .ui-tabs-anchor" ).trigger( "click" ); element.find( ".ui-state-active .ui-tabs-anchor" ).trigger( "click" );
equal( element.tabs( "option", "active" ), false ); assert.equal( element.tabs( "option", "active" ), false );
state( element, 0, 0, 0 ); state( assert, element, 0, 0, 0 );
element.tabs( "option", "collapsible", false ); element.tabs( "option", "collapsible", false );
assert.lacksClasses( element, "ui-tabs-collapsible" ); assert.lacksClasses( element, "ui-tabs-collapsible" );
@ -143,132 +144,132 @@ test( "collapsible", function( assert ) {
collapsible: false collapsible: false
} ); } );
element.tabs( "option", "active", false ); element.tabs( "option", "active", false );
equal( element.tabs( "option", "active" ), 1 ); assert.equal( element.tabs( "option", "active" ), 1 );
state( element, 0, 1, 0 ); state( assert, element, 0, 1, 0 );
element.find( ".ui-state-active .ui-tabs-anchor" ).eq( 1 ).trigger( "click" ); element.find( ".ui-state-active .ui-tabs-anchor" ).eq( 1 ).trigger( "click" );
equal( element.tabs( "option", "active" ), 1 ); assert.equal( element.tabs( "option", "active" ), 1 );
state( element, 0, 1, 0 ); state( assert, element, 0, 1, 0 );
} ); } );
test( "disabled", function( assert ) { QUnit.test( "disabled", function( assert ) {
expect( 23 ); assert.expect( 23 );
// Fully enabled by default // Fully enabled by default
var event, var event,
element = $( "#tabs1" ).tabs(); element = $( "#tabs1" ).tabs();
disabled( element, false ); disabled( assert, element, false );
assert.lacksClasses( element.tabs( "widget" ), "ui-state-disabled" ); assert.lacksClasses( element.tabs( "widget" ), "ui-state-disabled" );
assert.lacksClasses( element.tabs( "widget" ), "ui-tabs-disabled" ); assert.lacksClasses( element.tabs( "widget" ), "ui-tabs-disabled" );
ok( !element.tabs( "widget" ).attr( "aria-disabled" ), "after: wrapper doesn't have aria-disabled attr" ); assert.ok( !element.tabs( "widget" ).attr( "aria-disabled" ), "after: wrapper doesn't have aria-disabled attr" );
// Disable single tab // Disable single tab
element.tabs( "option", "disabled", [ 1 ] ); element.tabs( "option", "disabled", [ 1 ] );
disabled( element, [ 1 ] ); disabled( assert, element, [ 1 ] );
assert.lacksClasses( element.tabs( "widget" ), "ui-state-disabled" ); assert.lacksClasses( element.tabs( "widget" ), "ui-state-disabled" );
assert.lacksClasses( element.tabs( "widget" ), "ui-tabs-disabled" ); assert.lacksClasses( element.tabs( "widget" ), "ui-tabs-disabled" );
ok( !element.tabs( "widget" ).attr( "aria-disabled" ), "after: wrapper doesn't have aria-disabled attr" ); assert.ok( !element.tabs( "widget" ).attr( "aria-disabled" ), "after: wrapper doesn't have aria-disabled attr" );
// Disabled active tab // Disabled active tab
element.tabs( "option", "disabled", [ 0, 1 ] ); element.tabs( "option", "disabled", [ 0, 1 ] );
disabled( element, [ 0, 1 ] ); disabled( assert, element, [ 0, 1 ] );
assert.lacksClasses( element.tabs( "widget" ), "ui-state-disabled" ); assert.lacksClasses( element.tabs( "widget" ), "ui-state-disabled" );
assert.lacksClasses( element.tabs( "widget" ), "ui-tabs-disabled" ); assert.lacksClasses( element.tabs( "widget" ), "ui-tabs-disabled" );
ok( !element.tabs( "widget" ).attr( "aria-disabled" ), "after: wrapper doesn't have aria-disabled attr" ); assert.ok( !element.tabs( "widget" ).attr( "aria-disabled" ), "after: wrapper doesn't have aria-disabled attr" );
// Disable all tabs // Disable all tabs
element.tabs( "option", "disabled", [ 0, 1, 2 ] ); element.tabs( "option", "disabled", [ 0, 1, 2 ] );
disabled( element, true ); disabled( assert, element, true );
assert.lacksClasses( element.tabs( "widget" ), "ui-state-disabled" ); assert.lacksClasses( element.tabs( "widget" ), "ui-state-disabled" );
assert.hasClasses( element.tabs( "widget" ), "ui-tabs-disabled" ); assert.hasClasses( element.tabs( "widget" ), "ui-tabs-disabled" );
ok( !element.tabs( "widget" ).attr( "aria-disabled" ), "after: wrapper doesn't have aria-disabled attr" ); assert.ok( !element.tabs( "widget" ).attr( "aria-disabled" ), "after: wrapper doesn't have aria-disabled attr" );
event = $.Event( "click" ); event = $.Event( "click" );
element.find( ".ui-tabs-anchor" ).eq( 0 ).trigger( event ); element.find( ".ui-tabs-anchor" ).eq( 0 ).trigger( event );
ok( event.isDefaultPrevented(), "click is prevented for disabled tab" ); assert.ok( event.isDefaultPrevented(), "click is prevented for disabled tab" );
// Enable all tabs // Enable all tabs
element.tabs( "option", "disabled", [] ); element.tabs( "option", "disabled", [] );
disabled( element, false ); disabled( assert, element, false );
} ); } );
test( "{ event: null }", function() { QUnit.test( "{ event: null }", function( assert ) {
expect( 5 ); assert.expect( 5 );
var element = $( "#tabs1" ).tabs( { var element = $( "#tabs1" ).tabs( {
event: null event: null
} ); } );
state( element, 1, 0, 0 ); state( assert, element, 1, 0, 0 );
element.tabs( "option", "active", 1 ); element.tabs( "option", "active", 1 );
equal( element.tabs( "option", "active" ), 1 ); assert.equal( element.tabs( "option", "active" ), 1 );
state( element, 0, 1, 0 ); state( assert, element, 0, 1, 0 );
// Ensure default click handler isn't bound // Ensure default click handler isn't bound
element.find( ".ui-tabs-nav .ui-tabs-anchor" ).eq( 2 ).trigger( "click" ); element.find( ".ui-tabs-nav .ui-tabs-anchor" ).eq( 2 ).trigger( "click" );
equal( element.tabs( "option", "active" ), 1 ); assert.equal( element.tabs( "option", "active" ), 1 );
state( element, 0, 1, 0 ); state( assert, element, 0, 1, 0 );
} ); } );
test( "{ event: custom }", function() { QUnit.test( "{ event: custom }", function( assert ) {
expect( 11 ); assert.expect( 11 );
var element = $( "#tabs1" ).tabs( { var element = $( "#tabs1" ).tabs( {
event: "custom1 custom2" event: "custom1 custom2"
} ); } );
state( element, 1, 0, 0 ); state( assert, element, 1, 0, 0 );
element.find( ".ui-tabs-nav .ui-tabs-anchor" ).eq( 1 ).trigger( "custom1" ); element.find( ".ui-tabs-nav .ui-tabs-anchor" ).eq( 1 ).trigger( "custom1" );
equal( element.tabs( "option", "active" ), 1 ); assert.equal( element.tabs( "option", "active" ), 1 );
state( element, 0, 1, 0 ); state( assert, element, 0, 1, 0 );
// Ensure default click handler isn't bound // Ensure default click handler isn't bound
element.find( ".ui-tabs-nav .ui-tabs-anchor" ).eq( 2 ).trigger( "click" ); element.find( ".ui-tabs-nav .ui-tabs-anchor" ).eq( 2 ).trigger( "click" );
equal( element.tabs( "option", "active" ), 1 ); assert.equal( element.tabs( "option", "active" ), 1 );
state( element, 0, 1, 0 ); state( assert, element, 0, 1, 0 );
element.find( ".ui-tabs-nav .ui-tabs-anchor" ).eq( 2 ).trigger( "custom2" ); element.find( ".ui-tabs-nav .ui-tabs-anchor" ).eq( 2 ).trigger( "custom2" );
equal( element.tabs( "option", "active" ), 2 ); assert.equal( element.tabs( "option", "active" ), 2 );
state( element, 0, 0, 1 ); state( assert, element, 0, 0, 1 );
element.tabs( "option", "event", "custom3" ); element.tabs( "option", "event", "custom3" );
// Ensure old event handlers are unbound // Ensure old event handlers are unbound
element.find( ".ui-tabs-nav .ui-tabs-anchor" ).eq( 1 ).trigger( "custom1" ); element.find( ".ui-tabs-nav .ui-tabs-anchor" ).eq( 1 ).trigger( "custom1" );
equal( element.tabs( "option", "active" ), 2 ); assert.equal( element.tabs( "option", "active" ), 2 );
state( element, 0, 0, 1 ); state( assert, element, 0, 0, 1 );
element.find( ".ui-tabs-nav .ui-tabs-anchor" ).eq( 1 ).trigger( "custom3" ); element.find( ".ui-tabs-nav .ui-tabs-anchor" ).eq( 1 ).trigger( "custom3" );
equal( element.tabs( "option", "active" ), 1 ); assert.equal( element.tabs( "option", "active" ), 1 );
state( element, 0, 1, 0 ); state( assert, element, 0, 1, 0 );
} ); } );
test( "{ heightStyle: 'auto' }", function() { QUnit.test( "{ heightStyle: 'auto' }", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( "#tabs8" ).tabs( { heightStyle: "auto" } ); var element = $( "#tabs8" ).tabs( { heightStyle: "auto" } );
equalHeight( element, 45 ); equalHeight( assert, element, 45 );
} ); } );
test( "{ heightStyle: 'content' }", function() { QUnit.test( "{ heightStyle: 'content' }", function( assert ) {
expect( 2 ); assert.expect( 2 );
var element = $( "#tabs8" ).tabs( { heightStyle: "content" } ), var element = $( "#tabs8" ).tabs( { heightStyle: "content" } ),
sizes = element.find( ".ui-tabs-panel" ).map( function() { sizes = element.find( ".ui-tabs-panel" ).map( function() {
return $( this ).height(); return $( this ).height();
} ).get(); } ).get();
equal( sizes[ 0 ], 45 ); assert.equal( sizes[ 0 ], 45 );
equal( sizes[ 1 ], 15 ); assert.equal( sizes[ 1 ], 15 );
} ); } );
test( "{ heightStyle: 'fill' }", function() { QUnit.test( "{ heightStyle: 'fill' }", function( assert ) {
expect( 4 ); assert.expect( 4 );
$( "#tabs8Wrapper" ).height( 500 ); $( "#tabs8Wrapper" ).height( 500 );
var element = $( "#tabs8" ).tabs( { heightStyle: "fill" } ); var element = $( "#tabs8" ).tabs( { heightStyle: "fill" } );
equalHeight( element, 485 ); equalHeight( assert, element, 485 );
element.tabs( "destroy" ); element.tabs( "destroy" );
element = $( "#tabs8" ).css( { element = $( "#tabs8" ).css( {
@ -276,11 +277,11 @@ test( "{ heightStyle: 'fill' }", function() {
"padding": "1px 0" "padding": "1px 0"
} ); } );
element.tabs( { heightStyle: "fill" } ); element.tabs( { heightStyle: "fill" } );
equalHeight( element, 481 ); equalHeight( assert, element, 481 );
} ); } );
test( "{ heightStyle: 'fill' } with sibling", function() { QUnit.test( "{ heightStyle: 'fill' } with sibling", function( assert ) {
expect( 2 ); assert.expect( 2 );
$( "#tabs8Wrapper" ).height( 500 ); $( "#tabs8Wrapper" ).height( 500 );
$( "<p>Lorem Ipsum</p>" ) $( "<p>Lorem Ipsum</p>" )
.css( { .css( {
@ -290,11 +291,11 @@ test( "{ heightStyle: 'fill' } with sibling", function() {
} ) } )
.prependTo( "#tabs8Wrapper" ); .prependTo( "#tabs8Wrapper" );
var element = $( "#tabs8" ).tabs( { heightStyle: "fill" } ); var element = $( "#tabs8" ).tabs( { heightStyle: "fill" } );
equalHeight( element, 385 ); equalHeight( assert, element, 385 );
} ); } );
test( "{ heightStyle: 'fill' } with multiple siblings", function() { QUnit.test( "{ heightStyle: 'fill' } with multiple siblings", function( assert ) {
expect( 2 ); assert.expect( 2 );
$( "#tabs8Wrapper" ).height( 500 ); $( "#tabs8Wrapper" ).height( 500 );
$( "<p>Lorem Ipsum</p>" ) $( "<p>Lorem Ipsum</p>" )
.css( { .css( {
@ -319,11 +320,11 @@ test( "{ heightStyle: 'fill' } with multiple siblings", function() {
} ) } )
.prependTo( "#tabs8Wrapper" ); .prependTo( "#tabs8Wrapper" );
var element = $( "#tabs8" ).tabs( { heightStyle: "fill" } ); var element = $( "#tabs8" ).tabs( { heightStyle: "fill" } );
equalHeight( element, 335 ); equalHeight( assert, element, 335 );
} ); } );
test( "hide and show: false", function() { QUnit.test( "hide and show: false", function( assert ) {
expect( 3 ); assert.expect( 3 );
var element = $( "#tabs1" ).tabs( { var element = $( "#tabs1" ).tabs( {
show: false, show: false,
hide: false hide: false
@ -331,20 +332,21 @@ test( "hide and show: false", function() {
widget = element.tabs( "instance" ), widget = element.tabs( "instance" ),
panels = element.find( ".ui-tabs-panel" ); panels = element.find( ".ui-tabs-panel" );
widget._show = function() { widget._show = function() {
ok( false, "_show() called" ); assert.ok( false, "_show() called" );
}; };
widget._hide = function() { widget._hide = function() {
ok( false, "_hide() called" ); assert.ok( false, "_hide() called" );
}; };
ok( panels.eq( 0 ).is( ":visible" ), "first panel visible" ); assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel visible" );
element.tabs( "option", "active", 1 ); element.tabs( "option", "active", 1 );
ok( panels.eq( 0 ).is( ":hidden" ), "first panel hidden" ); assert.ok( panels.eq( 0 ).is( ":hidden" ), "first panel hidden" );
ok( panels.eq( 1 ).is( ":visible" ), "second panel visible" ); assert.ok( panels.eq( 1 ).is( ":visible" ), "second panel visible" );
} ); } );
asyncTest( "hide and show - animation", function() { QUnit.test( "hide and show - animation", function( assert ) {
expect( 5 ); var ready = assert.async();
assert.expect( 5 );
var element = $( "#tabs1" ).tabs( { var element = $( "#tabs1" ).tabs( {
show: "drop", show: "drop",
hide: 2000 hide: 2000
@ -352,22 +354,22 @@ asyncTest( "hide and show - animation", function() {
widget = element.tabs( "instance" ), widget = element.tabs( "instance" ),
panels = element.find( ".ui-tabs-panel" ); panels = element.find( ".ui-tabs-panel" );
widget._show = function( element, options, callback ) { widget._show = function( element, options, callback ) {
strictEqual( element[ 0 ], panels[ 1 ], "correct element in _show()" ); assert.strictEqual( element[ 0 ], panels[ 1 ], "correct element in _show()" );
equal( options, "drop", "correct options in _show()" ); assert.equal( options, "drop", "correct options in _show()" );
setTimeout( function() { setTimeout( function() {
callback(); callback();
} ); } );
}; };
widget._hide = function( element, options, callback ) { widget._hide = function( element, options, callback ) {
strictEqual( element[ 0 ], panels[ 0 ], "correct element in _hide()" ); assert.strictEqual( element[ 0 ], panels[ 0 ], "correct element in _hide()" );
equal( options, 2000, "correct options in _hide()" ); assert.equal( options, 2000, "correct options in _hide()" );
setTimeout( function() { setTimeout( function() {
callback(); callback();
start(); ready();
} ); } );
}; };
ok( panels.eq( 0 ).is( ":visible" ), "first panel visible" ); assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel visible" );
element.tabs( "option", "active", 1 ); element.tabs( "option", "active", 1 );
} ); } );