2015-04-06 19:01:13 +00:00
|
|
|
define( [
|
2016-04-06 13:48:50 +00:00
|
|
|
"qunit",
|
2015-04-06 19:01:13 +00:00
|
|
|
"jquery",
|
2015-04-07 14:55:52 +00:00
|
|
|
"./helper",
|
2015-07-15 02:11:35 +00:00
|
|
|
"ui/widgets/tabs"
|
2016-04-06 13:48:50 +00:00
|
|
|
], function( QUnit, $, testHelper ) {
|
2009-02-04 09:35:52 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
var state = testHelper.state;
|
2012-04-19 16:53:06 +00:00
|
|
|
|
2016-04-06 13:48:50 +00:00
|
|
|
QUnit.module( "tabs: core" );
|
2009-02-02 14:36:08 +00:00
|
|
|
|
2016-04-06 13:48:50 +00:00
|
|
|
QUnit.test( "markup structure", function( assert ) {
|
|
|
|
assert.expect( 20 );
|
2014-12-03 16:28:56 +00:00
|
|
|
var element = $( "#tabs1" ).tabs(),
|
|
|
|
tabList = element.find( "ul, ol" ),
|
|
|
|
tabs = tabList.find( "li" ),
|
|
|
|
active = tabs.eq( 0 ),
|
|
|
|
anchors = tabs.find( "a" ),
|
|
|
|
panels = element.find( ".ui-tabs-panel" );
|
|
|
|
|
|
|
|
assert.hasClasses( element, "ui-tabs ui-widget ui-widget-content" );
|
|
|
|
assert.lacksClasses( element, "ui-tabs-collapsible" );
|
|
|
|
assert.hasClasses( tabList, "ui-tabs-nav ui-widget-header" );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabList.length, 1, "The widget contains exactly one tab list" );
|
2015-04-15 15:41:03 +00:00
|
|
|
assert.hasClasses( tabs[ 0 ], "ui-tabs-tab" );
|
|
|
|
assert.hasClasses( tabs[ 1 ], "ui-tabs-tab" );
|
|
|
|
assert.hasClasses( tabs[ 2 ], "ui-tabs-tab" );
|
|
|
|
|
|
|
|
// DEPRECATED
|
2014-12-03 16:28:56 +00:00
|
|
|
assert.hasClasses( tabs[ 0 ], "ui-tab" );
|
|
|
|
assert.hasClasses( tabs[ 1 ], "ui-tab" );
|
|
|
|
assert.hasClasses( tabs[ 2 ], "ui-tab" );
|
2015-04-15 15:41:03 +00:00
|
|
|
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.length, 3, "There are exactly three tabs" );
|
2014-12-03 16:28:56 +00:00
|
|
|
assert.hasClasses( anchors[ 0 ], "ui-tabs-anchor" );
|
|
|
|
assert.hasClasses( anchors[ 1 ], "ui-tabs-anchor" );
|
|
|
|
assert.hasClasses( anchors[ 2 ], "ui-tabs-anchor" );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( anchors.length, 3, "There are exactly 3 anchors" );
|
2014-12-03 16:28:56 +00:00
|
|
|
assert.hasClasses( active, "ui-tabs-active" );
|
|
|
|
assert.hasClasses( panels[ 0 ], "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" );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( panels.length, 3, "There are exactly 3 tab panels" );
|
2015-08-24 12:57:25 +00:00
|
|
|
} );
|
2009-12-25 18:25:46 +00:00
|
|
|
|
2015-08-24 12:57:25 +00:00
|
|
|
$.each( {
|
2011-04-04 14:11:19 +00:00
|
|
|
"deep ul": "#tabs3",
|
|
|
|
"multiple lists, ul first": "#tabs4",
|
|
|
|
"multiple lists, ol first": "#tabs5",
|
|
|
|
"empty list": "#tabs6"
|
|
|
|
}, function( type, selector ) {
|
2016-04-06 13:48:50 +00:00
|
|
|
QUnit.test( "markup structure: " + type, function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2011-04-07 17:53:20 +00:00
|
|
|
var element = $( selector ).tabs();
|
2015-01-30 16:00:44 +00:00
|
|
|
assert.hasClasses( element, "ui-tabs" );
|
|
|
|
assert.hasClasses( $( selector + "-list" ), "ui-tabs-nav" );
|
2015-08-24 12:57:25 +00:00
|
|
|
} );
|
|
|
|
} );
|
2009-12-25 18:25:46 +00:00
|
|
|
|
2011-04-15 15:04:49 +00:00
|
|
|
// #5893 - Sublist in the tab list are considered as tab
|
2016-04-06 13:48:50 +00:00
|
|
|
QUnit.test( "nested list", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2011-04-15 15:04:49 +00:00
|
|
|
|
|
|
|
var element = $( "#tabs6" ).tabs();
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( element.tabs( "instance" ).anchors.length, 2, "should contain 2 tab" );
|
2015-08-24 12:57:25 +00:00
|
|
|
} );
|
2011-04-15 15:04:49 +00:00
|
|
|
|
2016-04-06 13:48:50 +00:00
|
|
|
QUnit.test( "disconnected from DOM", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2011-04-15 15:04:49 +00:00
|
|
|
|
|
|
|
var element = $( "#tabs1" ).remove().tabs();
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( element.find( ".ui-tabs-nav" ).length, 1, "should initialize nav" );
|
|
|
|
assert.equal( element.find( ".ui-tabs-panel" ).length, 3, "should initialize panels" );
|
2015-08-24 12:57:25 +00:00
|
|
|
} );
|
2011-04-15 15:04:49 +00:00
|
|
|
|
2016-04-06 13:48:50 +00:00
|
|
|
QUnit.test( "non-tab list items", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2012-09-12 13:28:51 +00:00
|
|
|
|
|
|
|
var element = $( "#tabs9" ).tabs();
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( element.tabs( "option", "active" ), 0, "defaults to first tab" );
|
|
|
|
assert.equal( element.find( ".ui-tabs-nav li.ui-state-active" ).index(), 1,
|
2012-09-12 13:28:51 +00:00
|
|
|
"first actual tab is active" );
|
2015-08-24 12:57:25 +00:00
|
|
|
} );
|
2012-09-12 13:28:51 +00:00
|
|
|
|
2016-04-06 13:48:50 +00:00
|
|
|
QUnit.test( "aria-controls", function( assert ) {
|
|
|
|
assert.expect( 7 );
|
2011-04-07 17:53:20 +00:00
|
|
|
var element = $( "#tabs1" ).tabs(),
|
2012-05-18 20:11:14 +00:00
|
|
|
tabs = element.find( ".ui-tabs-nav li" );
|
2015-08-24 12:57:25 +00:00
|
|
|
tabs.each( function() {
|
2012-05-18 20:11:14 +00:00
|
|
|
var tab = $( this ),
|
|
|
|
anchor = tab.find( ".ui-tabs-anchor" );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( anchor.prop( "hash" ).substring( 1 ), tab.attr( "aria-controls" ) );
|
2015-08-24 12:57:25 +00:00
|
|
|
} );
|
2011-04-07 17:53:20 +00:00
|
|
|
|
|
|
|
element = $( "#tabs2" ).tabs();
|
2012-05-18 20:11:14 +00:00
|
|
|
tabs = element.find( ".ui-tabs-nav li" );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-controls" ), "colon:test" );
|
|
|
|
assert.equal( tabs.eq( 1 ).attr( "aria-controls" ), "inline-style" );
|
|
|
|
assert.ok( /^ui-id-\d+$/.test( tabs.eq( 2 ).attr( "aria-controls" ) ), "generated id" );
|
|
|
|
assert.equal( tabs.eq( 3 ).attr( "aria-controls" ), "custom-id" );
|
2015-08-24 12:57:25 +00:00
|
|
|
} );
|
2011-04-07 17:53:20 +00:00
|
|
|
|
2016-04-06 13:48:50 +00:00
|
|
|
QUnit.test( "accessibility", function( assert ) {
|
2016-09-18 10:11:41 +00:00
|
|
|
assert.expect( 46 );
|
2015-08-24 12:57:25 +00:00
|
|
|
var element = $( "#tabs1" ).tabs( {
|
2012-06-08 14:45:10 +00:00
|
|
|
active: 1,
|
|
|
|
disabled: [ 2 ]
|
2015-08-24 12:57:25 +00:00
|
|
|
} ),
|
2012-06-08 14:45:10 +00:00
|
|
|
tabs = element.find( ".ui-tabs-nav li" ),
|
|
|
|
anchors = tabs.find( ".ui-tabs-anchor" ),
|
|
|
|
panels = element.find( ".ui-tabs-panel" );
|
|
|
|
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( element.find( ".ui-tabs-nav" ).attr( "role" ), "tablist", "tablist role" );
|
2015-08-24 12:57:25 +00:00
|
|
|
tabs.each( function( index ) {
|
2012-06-08 14:45:10 +00:00
|
|
|
var tab = tabs.eq( index ),
|
|
|
|
anchor = anchors.eq( index ),
|
|
|
|
anchorId = anchor.attr( "id" ),
|
|
|
|
panel = panels.eq( index );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tab.attr( "role" ), "tab", "tab " + index + " role" );
|
|
|
|
assert.equal( tab.attr( "aria-labelledby" ), anchorId, "tab " + index + " aria-labelledby" );
|
|
|
|
assert.equal( anchor.attr( "tabindex" ), -1, "anchor " + index + " tabindex" );
|
|
|
|
assert.equal( panel.attr( "role" ), "tabpanel", "panel " + index + " role" );
|
|
|
|
assert.equal( panel.attr( "aria-labelledby" ), anchorId, "panel " + index + " aria-labelledby" );
|
2015-08-24 12:57:25 +00:00
|
|
|
} );
|
2012-06-08 14:45:10 +00:00
|
|
|
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 1 ).attr( "aria-selected" ), "true", "active tab has aria-selected=true" );
|
|
|
|
assert.equal( tabs.eq( 1 ).attr( "tabindex" ), 0, "active tab has tabindex=0" );
|
|
|
|
assert.equal( tabs.eq( 1 ).attr( "aria-disabled" ), null, "enabled tab does not have aria-disabled" );
|
|
|
|
assert.equal( tabs.eq( 1 ).attr( "aria-expanded" ), "true", "active tab has aria-expanded=true" );
|
|
|
|
assert.equal( panels.eq( 1 ).attr( "aria-hidden" ), "false", "active panel has aria-hidden=false" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "false", "inactive tab has aria-selected=false" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "tabindex" ), -1, "inactive tab has tabindex=-1" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-disabled" ), null, "enabled tab does not have aria-disabled" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "false", "inactive tab has aria-expanded=false" );
|
|
|
|
assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "true", "inactive panel has aria-hidden=true" );
|
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "false", "inactive tab has aria-selected=false" );
|
|
|
|
assert.equal( tabs.eq( 2 ).attr( "tabindex" ), -1, "inactive tab has tabindex=-1" );
|
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-disabled" ), "true", "disabled tab has aria-disabled=true" );
|
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "inactive tab has aria-expanded=false" );
|
|
|
|
assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "inactive panel has aria-hidden=true" );
|
2012-06-08 14:45:10 +00:00
|
|
|
|
|
|
|
element.tabs( "option", "active", 0 );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "active tab has aria-selected=true" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "tabindex" ), 0, "active tab has tabindex=0" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-disabled" ), null, "enabled tab does not have aria-disabled" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "active tab has aria-expanded=true" );
|
|
|
|
assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "active panel has aria-hidden=false" );
|
|
|
|
assert.equal( tabs.eq( 1 ).attr( "aria-selected" ), "false", "inactive tab has aria-selected=false" );
|
|
|
|
assert.equal( tabs.eq( 1 ).attr( "tabindex" ), -1, "inactive tab has tabindex=-1" );
|
|
|
|
assert.equal( tabs.eq( 1 ).attr( "aria-disabled" ), null, "enabled tab does not have aria-disabled" );
|
|
|
|
assert.equal( tabs.eq( 1 ).attr( "aria-expanded" ), "false", "inactive tab has aria-expanded=false" );
|
|
|
|
assert.equal( panels.eq( 1 ).attr( "aria-hidden" ), "true", "inactive panel has aria-hidden=true" );
|
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "false", "inactive tab has aria-selected=false" );
|
|
|
|
assert.equal( tabs.eq( 2 ).attr( "tabindex" ), -1, "inactive tab has tabindex=-1" );
|
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-disabled" ), "true", "disabled tab has aria-disabled=true" );
|
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "inactive tab has aria-expanded=false" );
|
|
|
|
assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "inactive panel has aria-hidden=true" );
|
2015-08-24 12:57:25 +00:00
|
|
|
} );
|
2012-06-08 14:45:10 +00:00
|
|
|
|
2016-04-06 13:48:50 +00:00
|
|
|
QUnit.test( "accessibility - ajax", function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 6 );
|
2012-07-06 00:49:00 +00:00
|
|
|
var element = $( "#tabs2" ).tabs(),
|
2014-12-03 16:28:56 +00:00
|
|
|
tab = element.find( ".ui-tabs-nav li" ).eq( 3 ),
|
2012-07-06 00:49:00 +00:00
|
|
|
panel = $( "#custom-id" );
|
|
|
|
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( panel.attr( "aria-live" ), "polite", "remote panel has aria-live" );
|
|
|
|
assert.equal( panel.attr( "aria-busy" ), null, "does not have aria-busy on init" );
|
2012-07-06 00:49:00 +00:00
|
|
|
element.tabs( "option", "active", 3 );
|
2014-12-03 16:28:56 +00:00
|
|
|
assert.hasClasses( tab, "ui-tabs-loading" );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( panel.attr( "aria-busy" ), "true", "panel has aria-busy during load" );
|
2012-07-06 00:49:00 +00:00
|
|
|
element.one( "tabsload", function() {
|
2015-08-24 12:57:25 +00:00
|
|
|
setTimeout( function() {
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( panel.attr( "aria-busy" ), null, "panel does not have aria-busy after load" );
|
2014-12-03 16:28:56 +00:00
|
|
|
assert.lacksClasses( tab, "ui-tabs-loading" );
|
2016-04-06 13:48:50 +00:00
|
|
|
ready();
|
2012-07-06 00:49:00 +00:00
|
|
|
}, 1 );
|
2015-08-24 12:57:25 +00:00
|
|
|
} );
|
|
|
|
} );
|
2009-12-25 18:25:46 +00:00
|
|
|
|
2016-04-06 13:48:50 +00:00
|
|
|
QUnit.test( "keyboard support - LEFT, RIGHT, UP, DOWN, HOME, END, SPACE, ENTER", function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 92 );
|
2015-08-24 12:57:25 +00:00
|
|
|
var element = $( "#tabs1" ).tabs( {
|
2012-06-09 00:58:19 +00:00
|
|
|
collapsible: true
|
2015-08-24 12:57:25 +00:00
|
|
|
} ),
|
2012-06-09 00:58:19 +00:00
|
|
|
tabs = element.find( ".ui-tabs-nav li" ),
|
|
|
|
panels = element.find( ".ui-tabs-panel" ),
|
|
|
|
keyCode = $.ui.keyCode;
|
|
|
|
|
2015-02-17 15:11:58 +00:00
|
|
|
element.tabs( "instance" ).delay = 1;
|
2012-06-09 00:58:19 +00:00
|
|
|
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.filter( ".ui-state-focus" ).length, 0, "no tabs focused on init" );
|
2012-06-09 00:58:19 +00:00
|
|
|
tabs.eq( 0 ).simulate( "focus" );
|
|
|
|
|
2015-08-21 04:04:44 +00:00
|
|
|
// Down, right, down (wrap), up (wrap)
|
2012-06-09 00:58:19 +00:00
|
|
|
function step1() {
|
2015-01-30 16:00:44 +00:00
|
|
|
assert.hasClasses( tabs.eq( 0 ), "ui-state-focus", "first tab has focus" );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
|
|
|
|
assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is visible" );
|
2012-06-09 00:58:19 +00:00
|
|
|
|
|
|
|
tabs.eq( 0 ).simulate( "keydown", { keyCode: keyCode.DOWN } );
|
2015-01-30 16:00:44 +00:00
|
|
|
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" );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 1 ).attr( "aria-selected" ), "true", "second tab has aria-selected=true" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "false", "first tab has aria-selected=false" );
|
|
|
|
assert.ok( panels.eq( 1 ).is( ":hidden" ), "second panel is still hidden" );
|
|
|
|
assert.equal( tabs.eq( 1 ).attr( "aria-expanded" ), "false", "second tab has aria-expanded=false" );
|
|
|
|
assert.equal( panels.eq( 1 ).attr( "aria-hidden" ), "true", "second panel has aria-hidden=true" );
|
|
|
|
assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
|
|
|
|
assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
|
2012-06-09 00:58:19 +00:00
|
|
|
|
|
|
|
tabs.eq( 1 ).simulate( "keydown", { keyCode: keyCode.RIGHT } );
|
2015-01-30 16:00:44 +00:00
|
|
|
assert.hasClasses( tabs.eq( 2 ), "ui-state-focus", "RIGHT moves focus to next tab" );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "true", "third tab has aria-selected=true" );
|
|
|
|
assert.equal( tabs.eq( 1 ).attr( "aria-selected" ), "false", "second tab has aria-selected=false" );
|
|
|
|
assert.ok( panels.eq( 2 ).is( ":hidden" ), "third panel is still hidden" );
|
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" );
|
|
|
|
assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" );
|
|
|
|
assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
|
|
|
|
assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
|
2012-06-09 00:58:19 +00:00
|
|
|
|
|
|
|
tabs.eq( 2 ).simulate( "keydown", { keyCode: keyCode.DOWN } );
|
2015-01-30 16:00:44 +00:00
|
|
|
assert.hasClasses( tabs.eq( 0 ), "ui-state-focus", "DOWN wraps focus to first tab" );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
|
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "false", "third tab has aria-selected=false" );
|
|
|
|
assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
|
|
|
|
assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
|
2012-06-09 00:58:19 +00:00
|
|
|
|
|
|
|
tabs.eq( 0 ).simulate( "keydown", { keyCode: keyCode.UP } );
|
2015-01-30 16:00:44 +00:00
|
|
|
assert.hasClasses( tabs.eq( 2 ), "ui-state-focus", "UP wraps focus to last tab" );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "true", "third tab has aria-selected=true" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "false", "first tab has aria-selected=false" );
|
|
|
|
assert.ok( panels.eq( 2 ).is( ":hidden" ), "third panel is still hidden" );
|
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" );
|
|
|
|
assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" );
|
|
|
|
assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
|
|
|
|
assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
|
2012-06-09 00:58:19 +00:00
|
|
|
|
2015-02-17 15:11:58 +00:00
|
|
|
setTimeout( step2, 25 );
|
2012-06-09 00:58:19 +00:00
|
|
|
}
|
|
|
|
|
2015-08-21 04:04:44 +00:00
|
|
|
// Left, home, space
|
2012-06-09 00:58:19 +00:00
|
|
|
function step2() {
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "true", "third tab has aria-selected=true" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "false", "first tab has aria-selected=false" );
|
|
|
|
assert.ok( panels.eq( 2 ).is( ":visible" ), "third panel is visible" );
|
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "true", "third tab has aria-expanded=true" );
|
|
|
|
assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "false", "third panel has aria-hidden=false" );
|
|
|
|
assert.ok( panels.eq( 0 ).is( ":hidden" ), "first panel is hidden" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "false", "first tab has aria-expanded=false" );
|
|
|
|
assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "true", "first panel has aria-hidden=true" );
|
2012-06-09 00:58:19 +00:00
|
|
|
|
|
|
|
tabs.eq( 2 ).simulate( "keydown", { keyCode: keyCode.LEFT } );
|
2015-01-30 16:00:44 +00:00
|
|
|
assert.hasClasses( tabs.eq( 1 ), "ui-state-focus", "LEFT moves focus to previous tab" );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 1 ).attr( "aria-selected" ), "true", "second tab has aria-selected=true" );
|
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "false", "third tab has aria-selected=false" );
|
|
|
|
assert.ok( panels.eq( 1 ).is( ":hidden" ), "second panel is still hidden" );
|
|
|
|
assert.equal( tabs.eq( 1 ).attr( "aria-expanded" ), "false", "second tab has aria-expanded=false" );
|
|
|
|
assert.equal( panels.eq( 1 ).attr( "aria-hidden" ), "true", "second panel has aria-hidden=true" );
|
|
|
|
assert.ok( panels.eq( 2 ).is( ":visible" ), "third panel is still visible" );
|
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "true", "third tab has aria-expanded=true" );
|
|
|
|
assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "false", "third panel has aria-hidden=false" );
|
2012-06-09 00:58:19 +00:00
|
|
|
|
|
|
|
tabs.eq( 1 ).simulate( "keydown", { keyCode: keyCode.HOME } );
|
2015-01-30 16:00:44 +00:00
|
|
|
assert.hasClasses( tabs.eq( 0 ), "ui-state-focus", "HOME moves focus to first tab" );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
|
|
|
|
assert.equal( tabs.eq( 1 ).attr( "aria-selected" ), "false", "second tab has aria-selected=false" );
|
|
|
|
assert.ok( panels.eq( 0 ).is( ":hidden" ), "first panel is still hidden" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "false", "first tab has aria-expanded=false" );
|
|
|
|
assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "true", "first panel has aria-hidden=true" );
|
|
|
|
assert.ok( panels.eq( 2 ).is( ":visible" ), "third panel is still visible" );
|
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "true", "third tab has aria-expanded=true" );
|
|
|
|
assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "false", "third panel has aria-hidden=false" );
|
2012-06-09 00:58:19 +00:00
|
|
|
|
|
|
|
// SPACE activates, cancels delay
|
|
|
|
tabs.eq( 0 ).simulate( "keydown", { keyCode: keyCode.SPACE } );
|
2015-02-17 15:11:58 +00:00
|
|
|
setTimeout( step3 );
|
2012-06-09 00:58:19 +00:00
|
|
|
}
|
|
|
|
|
2015-08-21 04:04:44 +00:00
|
|
|
// End, enter
|
2012-06-09 00:58:19 +00:00
|
|
|
function step3() {
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
|
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "false", "third tab has aria-selected=false" );
|
|
|
|
assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is visible" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tabs has aria-expanded=true" );
|
|
|
|
assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
|
|
|
|
assert.ok( panels.eq( 2 ).is( ":hidden" ), "third panel is hidden" );
|
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" );
|
|
|
|
assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" );
|
2012-06-09 00:58:19 +00:00
|
|
|
|
|
|
|
tabs.eq( 0 ).simulate( "keydown", { keyCode: keyCode.END } );
|
2015-01-30 16:00:44 +00:00
|
|
|
assert.hasClasses( tabs.eq( 2 ), "ui-state-focus", "END moves focus to last tab" );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "true", "third tab has aria-selected=true" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "false", "first tab has aria-selected=false" );
|
|
|
|
assert.ok( panels.eq( 2 ).is( ":hidden" ), "third panel is still hidden" );
|
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" );
|
|
|
|
assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" );
|
|
|
|
assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tabs has aria-expanded=true" );
|
|
|
|
assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
|
2012-06-09 00:58:19 +00:00
|
|
|
|
|
|
|
// ENTER activates, cancels delay
|
|
|
|
tabs.eq( 0 ).simulate( "keydown", { keyCode: keyCode.ENTER } );
|
2015-02-17 15:11:58 +00:00
|
|
|
setTimeout( step4 );
|
2012-06-09 00:58:19 +00:00
|
|
|
}
|
|
|
|
|
2015-08-21 04:04:44 +00:00
|
|
|
// Enter (collapse)
|
2012-06-09 00:58:19 +00:00
|
|
|
function step4() {
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "true", "third tab has aria-selected=true" );
|
|
|
|
assert.ok( panels.eq( 2 ).is( ":visible" ), "third panel is visible" );
|
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "true", "third tab has aria-expanded=true" );
|
|
|
|
assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "false", "third panel has aria-hidden=false" );
|
|
|
|
assert.ok( panels.eq( 0 ).is( ":hidden" ), "first panel is hidden" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "false", "first tab has aria-expanded=false" );
|
|
|
|
assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "true", "first panel has aria-hidden=true" );
|
2012-06-09 00:58:19 +00:00
|
|
|
|
|
|
|
// ENTER collapses if active
|
|
|
|
tabs.eq( 2 ).simulate( "keydown", { keyCode: keyCode.ENTER } );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "false", "third tab has aria-selected=false" );
|
|
|
|
assert.ok( panels.eq( 2 ).is( ":hidden" ), "third panel is hidden" );
|
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" );
|
|
|
|
assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" );
|
2012-06-09 00:58:19 +00:00
|
|
|
|
2016-04-06 13:48:50 +00:00
|
|
|
setTimeout( ready );
|
2012-06-09 01:36:23 +00:00
|
|
|
}
|
|
|
|
|
2015-02-17 15:11:58 +00:00
|
|
|
setTimeout( step1 );
|
2015-08-24 12:57:25 +00:00
|
|
|
} );
|
2012-06-09 01:36:23 +00:00
|
|
|
|
2014-11-03 20:06:12 +00:00
|
|
|
// Navigation with CTRL and COMMAND (both behave the same)
|
2015-08-24 12:57:25 +00:00
|
|
|
$.each( {
|
2014-11-03 20:06:12 +00:00
|
|
|
ctrl: "CTRL",
|
|
|
|
meta: "COMMAND"
|
|
|
|
}, function( modifier, label ) {
|
2016-04-06 13:48:50 +00:00
|
|
|
QUnit.test( "keyboard support - " + label + " navigation", function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 115 );
|
2014-11-03 20:06:12 +00:00
|
|
|
var element = $( "#tabs1" ).tabs(),
|
|
|
|
tabs = element.find( ".ui-tabs-nav li" ),
|
|
|
|
panels = element.find( ".ui-tabs-panel" ),
|
|
|
|
keyCode = $.ui.keyCode;
|
|
|
|
|
2015-02-17 15:11:58 +00:00
|
|
|
element.tabs( "instance" ).delay = 1;
|
2014-11-03 20:06:12 +00:00
|
|
|
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.filter( ".ui-state-focus" ).length, 0, "no tabs focused on init" );
|
2014-11-03 20:06:12 +00:00
|
|
|
tabs.eq( 0 ).simulate( "focus" );
|
|
|
|
|
2015-08-21 04:04:44 +00:00
|
|
|
// Down
|
2014-11-03 20:06:12 +00:00
|
|
|
function step1() {
|
|
|
|
var eventProperties = { keyCode: keyCode.DOWN };
|
|
|
|
eventProperties[ modifier + "Key" ] = true;
|
|
|
|
|
2015-01-30 16:00:44 +00:00
|
|
|
assert.hasClasses( tabs.eq( 0 ), "ui-state-focus", "first tab has focus" );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
|
|
|
|
assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is visible" );
|
2014-11-03 20:06:12 +00:00
|
|
|
|
|
|
|
tabs.eq( 0 ).simulate( "keydown", eventProperties );
|
2015-01-30 16:00:44 +00:00
|
|
|
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" );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 1 ).attr( "aria-selected" ), "false", "second tab has aria-selected=false" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
|
|
|
|
assert.ok( panels.eq( 1 ).is( ":hidden" ), "second panel is still hidden" );
|
|
|
|
assert.equal( tabs.eq( 1 ).attr( "aria-expanded" ), "false", "second tab has aria-expanded=false" );
|
|
|
|
assert.equal( panels.eq( 1 ).attr( "aria-hidden" ), "true", "second panel has aria-hidden=true" );
|
|
|
|
assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
|
|
|
|
assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
|
2014-11-03 20:06:12 +00:00
|
|
|
|
2015-02-17 15:11:58 +00:00
|
|
|
setTimeout( step2, 25 );
|
2014-11-03 20:06:12 +00:00
|
|
|
}
|
|
|
|
|
2015-08-21 04:04:44 +00:00
|
|
|
// Right
|
2014-11-03 20:06:12 +00:00
|
|
|
function step2() {
|
|
|
|
var eventProperties = { keyCode: keyCode.RIGHT };
|
|
|
|
eventProperties[ modifier + "Key" ] = true;
|
|
|
|
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
|
|
|
|
assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is visible" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
|
|
|
|
assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
|
|
|
|
assert.ok( panels.eq( 1 ).is( ":hidden" ), "second panel is hidden" );
|
|
|
|
assert.equal( tabs.eq( 1 ).attr( "aria-expanded" ), "false", "second tab has aria-expanded=false" );
|
|
|
|
assert.equal( panels.eq( 1 ).attr( "aria-hidden" ), "true", "second panel has aria-hidden=true" );
|
2014-11-03 20:06:12 +00:00
|
|
|
|
|
|
|
tabs.eq( 1 ).simulate( "keydown", eventProperties );
|
2015-01-30 16:00:44 +00:00
|
|
|
assert.hasClasses( tabs.eq( 2 ), "ui-state-focus", "RIGHT moves focus to next tab" );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "false", "third tab has aria-selected=false" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
|
|
|
|
assert.ok( panels.eq( 2 ).is( ":hidden" ), "third panel is still hidden" );
|
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" );
|
|
|
|
assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" );
|
|
|
|
assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
|
|
|
|
assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
|
2014-11-03 20:06:12 +00:00
|
|
|
|
2015-02-17 15:11:58 +00:00
|
|
|
setTimeout( step3, 25 );
|
2014-11-03 20:06:12 +00:00
|
|
|
}
|
|
|
|
|
2015-08-21 04:04:44 +00:00
|
|
|
// Down (wrap)
|
2014-11-03 20:06:12 +00:00
|
|
|
function step3() {
|
|
|
|
var eventProperties = { keyCode: keyCode.DOWN };
|
|
|
|
eventProperties[ modifier + "Key" ] = true;
|
|
|
|
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
|
|
|
|
assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is visible" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
|
|
|
|
assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
|
|
|
|
assert.ok( panels.eq( 2 ).is( ":hidden" ), "third panel is hidden" );
|
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" );
|
|
|
|
assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" );
|
2014-11-03 20:06:12 +00:00
|
|
|
|
|
|
|
tabs.eq( 2 ).simulate( "keydown", eventProperties );
|
2015-01-30 16:00:44 +00:00
|
|
|
assert.hasClasses( tabs.eq( 0 ), "ui-state-focus", "DOWN wraps focus to first tab" );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
|
|
|
|
assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
|
|
|
|
assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
|
2014-11-03 20:06:12 +00:00
|
|
|
|
2015-02-17 15:11:58 +00:00
|
|
|
setTimeout( step4, 25 );
|
2014-11-03 20:06:12 +00:00
|
|
|
}
|
|
|
|
|
2015-08-21 04:04:44 +00:00
|
|
|
// Up (wrap)
|
2014-11-03 20:06:12 +00:00
|
|
|
function step4() {
|
|
|
|
var eventProperties = { keyCode: keyCode.UP };
|
|
|
|
eventProperties[ modifier + "Key" ] = true;
|
|
|
|
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
|
|
|
|
assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is visible" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
|
|
|
|
assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
|
2014-11-03 20:06:12 +00:00
|
|
|
|
|
|
|
tabs.eq( 0 ).simulate( "keydown", eventProperties );
|
2015-01-30 16:00:44 +00:00
|
|
|
assert.hasClasses( tabs.eq( 2 ), "ui-state-focus", "UP wraps focus to last tab" );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "false", "third tab has aria-selected=false" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
|
|
|
|
assert.ok( panels.eq( 2 ).is( ":hidden" ), "third panel is still hidden" );
|
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" );
|
|
|
|
assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" );
|
|
|
|
assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
|
|
|
|
assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
|
2014-11-03 20:06:12 +00:00
|
|
|
|
2015-02-17 15:11:58 +00:00
|
|
|
setTimeout( step5, 25 );
|
2014-11-03 20:06:12 +00:00
|
|
|
}
|
|
|
|
|
2015-08-21 04:04:44 +00:00
|
|
|
// Left
|
2014-11-03 20:06:12 +00:00
|
|
|
function step5() {
|
|
|
|
var eventProperties = { keyCode: keyCode.LEFT };
|
|
|
|
eventProperties[ modifier + "Key" ] = true;
|
|
|
|
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
|
|
|
|
assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is visible" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
|
|
|
|
assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
|
|
|
|
assert.ok( panels.eq( 2 ).is( ":hidden" ), "third panel is hidden" );
|
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" );
|
|
|
|
assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" );
|
2014-11-03 20:06:12 +00:00
|
|
|
|
|
|
|
tabs.eq( 2 ).simulate( "keydown", eventProperties );
|
2015-01-30 16:00:44 +00:00
|
|
|
assert.hasClasses( tabs.eq( 1 ), "ui-state-focus", "LEFT moves focus to previous tab" );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 1 ).attr( "aria-selected" ), "false", "second tab has aria-selected=false" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
|
|
|
|
assert.ok( panels.eq( 1 ).is( ":hidden" ), "second panel is still hidden" );
|
|
|
|
assert.equal( tabs.eq( 1 ).attr( "aria-expanded" ), "false", "second tab has aria-expanded=false" );
|
|
|
|
assert.equal( panels.eq( 1 ).attr( "aria-hidden" ), "true", "second panel has aria-hidden=true" );
|
|
|
|
assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
|
|
|
|
assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
|
2014-11-03 20:06:12 +00:00
|
|
|
|
2015-02-17 15:11:58 +00:00
|
|
|
setTimeout( step6, 25 );
|
2014-11-03 20:06:12 +00:00
|
|
|
}
|
|
|
|
|
2015-08-21 04:04:44 +00:00
|
|
|
// Home
|
2014-11-03 20:06:12 +00:00
|
|
|
function step6() {
|
|
|
|
var eventProperties = { keyCode: keyCode.HOME };
|
|
|
|
eventProperties[ modifier + "Key" ] = true;
|
|
|
|
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
|
|
|
|
assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is visible" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
|
|
|
|
assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
|
|
|
|
assert.ok( panels.eq( 1 ).is( ":hidden" ), "second panel is hidden" );
|
|
|
|
assert.equal( tabs.eq( 1 ).attr( "aria-expanded" ), "false", "second tab has aria-expanded=false" );
|
|
|
|
assert.equal( panels.eq( 1 ).attr( "aria-hidden" ), "true", "second panel has aria-hidden=true" );
|
2014-11-03 20:06:12 +00:00
|
|
|
|
|
|
|
tabs.eq( 1 ).simulate( "keydown", eventProperties );
|
2015-01-30 16:00:44 +00:00
|
|
|
assert.hasClasses( tabs.eq( 0 ), "ui-state-focus", "HOME moves focus to first tab" );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
|
|
|
|
assert.equal( tabs.eq( 1 ).attr( "aria-selected" ), "false", "second tab has aria-selected=false" );
|
|
|
|
assert.ok( panels.eq( 1 ).is( ":hidden" ), "second panel is still hidden" );
|
|
|
|
assert.equal( tabs.eq( 1 ).attr( "aria-expanded" ), "false", "second tab has aria-expanded=false" );
|
|
|
|
assert.equal( panels.eq( 1 ).attr( "aria-hidden" ), "true", "second panel has aria-hidden=true" );
|
|
|
|
assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
|
|
|
|
assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
|
2014-11-03 20:06:12 +00:00
|
|
|
|
2015-02-17 15:11:58 +00:00
|
|
|
setTimeout( step7, 25 );
|
2014-11-03 20:06:12 +00:00
|
|
|
}
|
|
|
|
|
2015-08-21 04:04:44 +00:00
|
|
|
// End
|
2014-11-03 20:06:12 +00:00
|
|
|
function step7() {
|
|
|
|
var eventProperties = { keyCode: keyCode.END };
|
|
|
|
eventProperties[ modifier + "Key" ] = true;
|
|
|
|
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
|
|
|
|
assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is visible" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
|
|
|
|
assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
|
2014-11-03 20:06:12 +00:00
|
|
|
|
|
|
|
tabs.eq( 0 ).simulate( "keydown", eventProperties );
|
2015-01-30 16:00:44 +00:00
|
|
|
assert.hasClasses( tabs.eq( 2 ), "ui-state-focus", "END moves focus to last tab" );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "false", "third tab has aria-selected=false" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
|
|
|
|
assert.ok( panels.eq( 2 ).is( ":hidden" ), "third panel is still hidden" );
|
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" );
|
|
|
|
assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" );
|
|
|
|
assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is still visible" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
|
|
|
|
assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
|
2014-11-03 20:06:12 +00:00
|
|
|
|
2015-02-17 15:11:58 +00:00
|
|
|
setTimeout( step8, 25 );
|
2014-11-03 20:06:12 +00:00
|
|
|
}
|
|
|
|
|
2015-08-21 04:04:44 +00:00
|
|
|
// Space
|
2014-11-03 20:06:12 +00:00
|
|
|
function step8() {
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
|
|
|
|
assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is visible" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
|
|
|
|
assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
|
|
|
|
assert.ok( panels.eq( 2 ).is( ":hidden" ), "third panel is hidden" );
|
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" );
|
|
|
|
assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" );
|
2014-11-03 20:06:12 +00:00
|
|
|
|
|
|
|
tabs.eq( 2 ).simulate( "keydown", { keyCode: keyCode.SPACE } );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "true", "third tab has aria-selected=true" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "false", "first tab has aria-selected=false" );
|
|
|
|
assert.ok( panels.eq( 2 ).is( ":visible" ), "third panel is visible" );
|
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "true", "third tab has aria-expanded=true" );
|
|
|
|
assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "false", "third panel has aria-hidden=false" );
|
|
|
|
assert.ok( panels.eq( 0 ).is( ":hidden" ), "first panel is hidden" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "false", "first tab has aria-expanded=false" );
|
|
|
|
assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "true", "first panel has aria-hidden=true" );
|
|
|
|
|
|
|
|
setTimeout( ready );
|
2014-11-03 20:06:12 +00:00
|
|
|
}
|
|
|
|
|
2015-02-17 15:11:58 +00:00
|
|
|
setTimeout( step1 );
|
2015-08-24 12:57:25 +00:00
|
|
|
} );
|
|
|
|
} );
|
2012-06-09 00:58:19 +00:00
|
|
|
|
2016-04-06 13:48:50 +00:00
|
|
|
QUnit.test( "keyboard support - CTRL+UP, ALT+PAGE_DOWN, ALT+PAGE_UP", function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 50 );
|
2012-06-09 02:21:14 +00:00
|
|
|
var element = $( "#tabs1" ).tabs(),
|
|
|
|
tabs = element.find( ".ui-tabs-nav li" ),
|
|
|
|
panels = element.find( ".ui-tabs-panel" ),
|
|
|
|
keyCode = $.ui.keyCode;
|
|
|
|
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.filter( ".ui-state-focus" ).length, 0, "no tabs focused on init" );
|
2012-06-09 02:21:14 +00:00
|
|
|
panels.attr( "tabindex", -1 );
|
|
|
|
panels.eq( 0 ).simulate( "focus" );
|
|
|
|
|
|
|
|
function step1() {
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.strictEqual( document.activeElement, panels[ 0 ], "first panel is activeElement" );
|
2012-06-09 02:21:14 +00:00
|
|
|
|
|
|
|
panels.eq( 0 ).simulate( "keydown", { keyCode: keyCode.PAGE_DOWN, altKey: true } );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.strictEqual( document.activeElement, tabs[ 1 ], "second tab is activeElement" );
|
2015-01-30 16:00:44 +00:00
|
|
|
assert.hasClasses( tabs.eq( 1 ), "ui-state-focus", "ALT+PAGE_DOWN moves focus to next tab" );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 1 ).attr( "aria-selected" ), "true", "second tab has aria-selected=true" );
|
|
|
|
assert.ok( panels.eq( 1 ).is( ":visible" ), "second panel is visible" );
|
|
|
|
assert.equal( tabs.eq( 1 ).attr( "aria-expanded" ), "true", "second tab has aria-expanded=true" );
|
|
|
|
assert.equal( panels.eq( 1 ).attr( "aria-hidden" ), "false", "second panel has aria-hidden=false" );
|
|
|
|
assert.ok( panels.eq( 0 ).is( ":hidden" ), "first panel is hidden" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "false", "first tab has aria-expanded=false" );
|
|
|
|
assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "true", "first panel has aria-hidden=true" );
|
2012-06-09 02:21:14 +00:00
|
|
|
|
|
|
|
tabs.eq( 1 ).simulate( "keydown", { keyCode: keyCode.PAGE_DOWN, altKey: true } );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.strictEqual( document.activeElement, tabs[ 2 ], "third tab is activeElement" );
|
2015-01-30 16:00:44 +00:00
|
|
|
assert.hasClasses( tabs.eq( 2 ), "ui-state-focus", "ALT+PAGE_DOWN moves focus to next tab" );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "true", "third tab has aria-selected=true" );
|
|
|
|
assert.ok( panels.eq( 2 ).is( ":visible" ), "third panel is visible" );
|
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "true", "third tab has aria-expanded=true" );
|
|
|
|
assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "false", "third panel has aria-hidden=false" );
|
|
|
|
assert.ok( panels.eq( 1 ).is( ":hidden" ), "second panel is hidden" );
|
|
|
|
assert.equal( tabs.eq( 1 ).attr( "aria-expanded" ), "false", "second tab has aria-expanded=false" );
|
|
|
|
assert.equal( panels.eq( 1 ).attr( "aria-hidden" ), "true", "second panel has aria-hidden=true" );
|
2012-06-09 02:21:14 +00:00
|
|
|
|
|
|
|
tabs.eq( 2 ).simulate( "keydown", { keyCode: keyCode.PAGE_DOWN, altKey: true } );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.strictEqual( document.activeElement, tabs[ 0 ], "first tab is activeElement" );
|
2015-01-30 16:00:44 +00:00
|
|
|
assert.hasClasses( tabs.eq( 0 ), "ui-state-focus", "ALT+PAGE_DOWN wraps focus to first tab" );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-selected" ), "true", "first tab has aria-selected=true" );
|
|
|
|
assert.ok( panels.eq( 0 ).is( ":visible" ), "first panel is visible" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "true", "first tab has aria-expanded=true" );
|
|
|
|
assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "false", "first panel has aria-hidden=false" );
|
|
|
|
assert.ok( panels.eq( 2 ).is( ":hidden" ), "third panel is hidden" );
|
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" );
|
|
|
|
assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" );
|
2012-06-09 02:21:14 +00:00
|
|
|
|
|
|
|
panels.eq( 0 ).simulate( "focus" );
|
2015-02-17 15:11:58 +00:00
|
|
|
setTimeout( step2 );
|
2012-06-09 02:21:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function step2() {
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.strictEqual( document.activeElement, panels[ 0 ], "first panel is activeElement" );
|
2012-06-09 02:21:14 +00:00
|
|
|
|
|
|
|
panels.eq( 0 ).simulate( "keydown", { keyCode: keyCode.PAGE_UP, altKey: true } );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.strictEqual( document.activeElement, tabs[ 2 ], "third tab is activeElement" );
|
2015-01-30 16:00:44 +00:00
|
|
|
assert.hasClasses( tabs.eq( 2 ), "ui-state-focus", "ALT+PAGE_UP wraps focus to last tab" );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-selected" ), "true", "third tab has aria-selected=true" );
|
|
|
|
assert.ok( panels.eq( 2 ).is( ":visible" ), "third panel is visible" );
|
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "true", "third tab has aria-expanded=true" );
|
|
|
|
assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "false", "third panel has aria-hidden=false" );
|
|
|
|
assert.ok( panels.eq( 0 ).is( ":hidden" ), "first panel is hidden" );
|
|
|
|
assert.equal( tabs.eq( 0 ).attr( "aria-expanded" ), "false", "first tab has aria-expanded=false" );
|
|
|
|
assert.equal( panels.eq( 0 ).attr( "aria-hidden" ), "true", "first panel has aria-hidden=true" );
|
2012-06-09 02:21:14 +00:00
|
|
|
|
|
|
|
tabs.eq( 2 ).simulate( "keydown", { keyCode: keyCode.PAGE_UP, altKey: true } );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.strictEqual( document.activeElement, tabs[ 1 ], "second tab is activeElement" );
|
2015-01-30 16:00:44 +00:00
|
|
|
assert.hasClasses( tabs.eq( 1 ), "ui-state-focus", "ALT+PAGE_UP moves focus to previous tab" );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( tabs.eq( 1 ).attr( "aria-selected" ), "true", "second tab has aria-selected=true" );
|
|
|
|
assert.ok( panels.eq( 1 ).is( ":visible" ), "second panel is visible" );
|
|
|
|
assert.equal( tabs.eq( 1 ).attr( "aria-expanded" ), "true", "second tab has aria-expanded=true" );
|
|
|
|
assert.equal( panels.eq( 1 ).attr( "aria-hidden" ), "false", "second panel has aria-hidden=false" );
|
|
|
|
assert.ok( panels.eq( 2 ).is( ":hidden" ), "third panel is hidden" );
|
|
|
|
assert.equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "third tab has aria-expanded=false" );
|
|
|
|
assert.equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "third panel has aria-hidden=true" );
|
2012-06-09 02:21:14 +00:00
|
|
|
|
|
|
|
panels.eq( 1 ).simulate( "focus" );
|
2015-02-17 15:11:58 +00:00
|
|
|
setTimeout( step3 );
|
2012-06-09 02:21:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function step3() {
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.strictEqual( document.activeElement, panels[ 1 ], "second panel is activeElement" );
|
2012-06-09 02:21:14 +00:00
|
|
|
|
|
|
|
panels.eq( 1 ).simulate( "keydown", { keyCode: keyCode.UP, ctrlKey: true } );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.strictEqual( document.activeElement, tabs[ 1 ], "second tab is activeElement" );
|
2012-06-09 02:21:14 +00:00
|
|
|
|
2016-04-06 13:48:50 +00:00
|
|
|
setTimeout( ready );
|
2012-06-09 02:21:14 +00:00
|
|
|
}
|
|
|
|
|
2015-02-17 15:11:58 +00:00
|
|
|
setTimeout( step1 );
|
2015-08-24 12:57:25 +00:00
|
|
|
} );
|
2012-06-09 02:21:14 +00:00
|
|
|
|
2016-04-06 13:48:50 +00:00
|
|
|
QUnit.test( "#4033 - IE expands hash to full url and misinterprets tab as ajax", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2011-05-10 12:47:00 +00:00
|
|
|
|
2015-08-24 12:57:25 +00:00
|
|
|
var element = $( "<div><ul><li><a href='#tab'>Tab</a></li></ul><div id='tab'></div></div>" );
|
|
|
|
element.appendTo( "#qunit-fixture" );
|
|
|
|
element.tabs( {
|
2012-10-23 14:36:42 +00:00
|
|
|
beforeLoad: function() {
|
2011-05-10 12:47:00 +00:00
|
|
|
event.preventDefault();
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.ok( false, "should not be an ajax tab" );
|
2011-05-10 12:47:00 +00:00
|
|
|
}
|
2015-08-24 12:57:25 +00:00
|
|
|
} );
|
2011-05-10 12:47:00 +00:00
|
|
|
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( element.find( ".ui-tabs-nav li" ).attr( "aria-controls" ), "tab", "aria-contorls attribute is correct" );
|
|
|
|
state( assert, element, 1 );
|
2015-08-24 12:57:25 +00:00
|
|
|
} );
|
2011-05-10 12:47:00 +00:00
|
|
|
|
2015-04-06 19:01:13 +00:00
|
|
|
} );
|