2015-04-03 19:24:09 +00:00
|
|
|
define( [
|
2016-04-03 14:37:27 +00:00
|
|
|
"qunit",
|
2015-04-03 19:24:09 +00:00
|
|
|
"jquery",
|
2015-04-07 14:55:52 +00:00
|
|
|
"./helper",
|
2015-07-15 01:54:33 +00:00
|
|
|
"ui/widgets/accordion"
|
2016-04-03 14:37:27 +00:00
|
|
|
], function( QUnit, $, testHelper ) {
|
2021-06-06 22:58:12 +00:00
|
|
|
"use strict";
|
2009-02-03 08:23:48 +00:00
|
|
|
|
2020-05-16 07:16:24 +00:00
|
|
|
var beforeAfterEach = testHelper.beforeAfterEach,
|
2015-04-07 14:30:07 +00:00
|
|
|
state = testHelper.state;
|
2012-04-19 15:37:33 +00:00
|
|
|
|
2020-05-16 07:16:24 +00:00
|
|
|
QUnit.module( "accordion: core", beforeAfterEach() );
|
2009-09-15 08:33:28 +00:00
|
|
|
|
2011-03-23 14:07:09 +00:00
|
|
|
$.each( { div: "#list1", ul: "#navigation", dl: "#accordion-dl" }, function( type, selector ) {
|
2016-04-03 14:37:27 +00:00
|
|
|
QUnit.test( "markup structure: " + type, function( assert ) {
|
|
|
|
assert.expect( 10 );
|
2014-12-03 16:23:19 +00:00
|
|
|
var element = $( selector ).accordion(),
|
|
|
|
headers = element.find( ".ui-accordion-header" ),
|
|
|
|
content = headers.next();
|
|
|
|
|
|
|
|
assert.hasClasses( element, "ui-accordion ui-widget" );
|
2016-04-03 14:37:27 +00:00
|
|
|
assert.equal( headers.length, 3, ".ui-accordion-header elements exist, correct number" );
|
2014-12-03 16:23:19 +00:00
|
|
|
assert.hasClasses( headers[ 0 ],
|
|
|
|
"ui-accordion-header ui-accordion-header-active ui-accordion-icons" );
|
|
|
|
assert.hasClasses( headers[ 1 ],
|
|
|
|
"ui-accordion-header ui-accordion-header-collapsed ui-accordion-icons" );
|
|
|
|
assert.hasClasses( headers[ 2 ],
|
|
|
|
"ui-accordion-header ui-accordion-header-collapsed ui-accordion-icons" );
|
2016-04-03 14:37:27 +00:00
|
|
|
assert.equal( content.length, 3, ".ui-accordion-content elements exist, correct number" );
|
2014-12-03 16:23:19 +00:00
|
|
|
assert.hasClasses( content[ 0 ],
|
|
|
|
"ui-accordion-content ui-widget-content ui-accordion-content-active" );
|
|
|
|
assert.hasClasses( content[ 1 ], "ui-accordion-content ui-widget-content" );
|
|
|
|
assert.hasClasses( content[ 2 ], "ui-accordion-content ui-widget-content" );
|
2016-04-03 14:37:27 +00:00
|
|
|
assert.deepEqual( element.find( ".ui-accordion-header" ).next().get(),
|
2011-04-15 15:29:26 +00:00
|
|
|
element.find( ".ui-accordion-content" ).get(),
|
2011-03-23 14:07:09 +00:00
|
|
|
"content panels come immediately after headers" );
|
2015-08-21 04:12:07 +00:00
|
|
|
} );
|
|
|
|
} );
|
2011-01-25 03:40:03 +00:00
|
|
|
|
2016-04-03 14:37:27 +00:00
|
|
|
QUnit.test( "handle click on header-descendant", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2011-04-15 15:29:26 +00:00
|
|
|
var element = $( "#navigation" ).accordion();
|
2020-01-22 15:44:34 +00:00
|
|
|
$( "#navigation h2" ).eq( 1 ).find( "a" ).trigger( "click" );
|
2016-04-03 14:37:27 +00:00
|
|
|
state( assert, element, 0, 1, 0 );
|
2015-08-21 04:12:07 +00:00
|
|
|
} );
|
2009-02-03 08:23:48 +00:00
|
|
|
|
2016-04-03 14:37:27 +00:00
|
|
|
QUnit.test( "accessibility", function( assert ) {
|
|
|
|
assert.expect( 61 );
|
2015-08-21 04:12:07 +00:00
|
|
|
var element = $( "#list1" ).accordion( {
|
2015-01-05 20:44:49 +00:00
|
|
|
active: 1,
|
|
|
|
collapsible: true
|
2015-08-21 04:12:07 +00:00
|
|
|
} ),
|
2012-04-19 14:50:09 +00:00
|
|
|
headers = element.find( ".ui-accordion-header" );
|
2011-01-24 20:45:29 +00:00
|
|
|
|
2016-04-03 14:37:27 +00:00
|
|
|
assert.equal( element.attr( "role" ), "tablist", "element role" );
|
2015-08-21 04:12:07 +00:00
|
|
|
headers.each( function( i ) {
|
2012-03-27 14:19:35 +00:00
|
|
|
var header = headers.eq( i ),
|
|
|
|
panel = header.next();
|
2016-04-03 14:37:27 +00:00
|
|
|
assert.equal( header.attr( "role" ), "tab", "header " + i + " role" );
|
|
|
|
assert.equal( header.attr( "aria-controls" ), panel.attr( "id" ), "header " + i + " aria-controls" );
|
|
|
|
assert.equal( panel.attr( "role" ), "tabpanel", "panel " + i + " role" );
|
|
|
|
assert.equal( panel.attr( "aria-labelledby" ), header.attr( "id" ), "panel " + i + " aria-labelledby" );
|
2015-08-21 04:12:07 +00:00
|
|
|
} );
|
2012-03-27 14:19:35 +00:00
|
|
|
|
2016-04-03 14:37:27 +00:00
|
|
|
assert.equal( headers.eq( 1 ).attr( "tabindex" ), 0, "active header has tabindex=0" );
|
|
|
|
assert.equal( headers.eq( 1 ).attr( "aria-selected" ), "true", "active tab (1) has aria-selected=true" );
|
|
|
|
assert.equal( headers.eq( 1 ).attr( "aria-expanded" ), "true", "active tab (1) has aria-expanded=true" );
|
|
|
|
assert.equal( headers.eq( 1 ).next().attr( "aria-hidden" ), "false", "active tabpanel (1) has aria-hidden=false" );
|
|
|
|
assert.equal( headers.eq( 0 ).attr( "tabindex" ), -1, "inactive header (0) has tabindex=-1" );
|
|
|
|
assert.equal( headers.eq( 0 ).attr( "aria-selected" ), "false", "inactive tab (0) has aria-selected=false" );
|
|
|
|
assert.equal( headers.eq( 0 ).attr( "aria-expanded" ), "false", "inactive tab (0) has aria-expanded=false" );
|
|
|
|
assert.equal( headers.eq( 0 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel (0) has aria-hidden=true" );
|
|
|
|
assert.equal( headers.eq( 2 ).attr( "tabindex" ), -1, "inactive header (2) has tabindex=-1" );
|
|
|
|
assert.equal( headers.eq( 2 ).attr( "aria-selected" ), "false", "inactive tab (2) has aria-selected=false" );
|
|
|
|
assert.equal( headers.eq( 2 ).attr( "aria-expanded" ), "false", "inactive tab (2) has aria-expanded=false" );
|
|
|
|
assert.equal( headers.eq( 2 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel (2) has aria-hidden=true" );
|
2012-03-27 14:19:35 +00:00
|
|
|
|
2011-04-15 15:29:26 +00:00
|
|
|
element.accordion( "option", "active", 0 );
|
2016-04-03 14:37:27 +00:00
|
|
|
assert.equal( headers.eq( 0 ).attr( "tabindex" ), 0, "active header (0) has tabindex=0" );
|
|
|
|
assert.equal( headers.eq( 0 ).attr( "aria-selected" ), "true", "active tab (0) has aria-selected=true" );
|
|
|
|
assert.equal( headers.eq( 0 ).attr( "aria-expanded" ), "true", "active tab (0) has aria-expanded=true" );
|
|
|
|
assert.equal( headers.eq( 0 ).next().attr( "aria-hidden" ), "false", "active tabpanel (0) has aria-hidden=false" );
|
|
|
|
assert.equal( headers.eq( 1 ).attr( "tabindex" ), -1, "inactive header (1) has tabindex=-1" );
|
|
|
|
assert.equal( headers.eq( 1 ).attr( "aria-selected" ), "false", "inactive tab (1) has aria-selected=false" );
|
|
|
|
assert.equal( headers.eq( 1 ).attr( "aria-expanded" ), "false", "inactive tab (1) has aria-expanded=false" );
|
|
|
|
assert.equal( headers.eq( 1 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel (1) has aria-hidden=true" );
|
|
|
|
assert.equal( headers.eq( 2 ).attr( "tabindex" ), -1, "inactive header (2) has tabindex=-1" );
|
|
|
|
assert.equal( headers.eq( 2 ).attr( "aria-selected" ), "false", "inactive tab (2) has aria-selected=false" );
|
|
|
|
assert.equal( headers.eq( 2 ).attr( "aria-expanded" ), "false", "inactive tab (2) has aria-expanded=false" );
|
|
|
|
assert.equal( headers.eq( 2 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel (2) has aria-hidden=true" );
|
2015-01-05 20:44:49 +00:00
|
|
|
|
|
|
|
element.accordion( "option", "active", false );
|
2016-04-03 14:37:27 +00:00
|
|
|
assert.equal( headers.eq( 0 ).attr( "tabindex" ), 0, "previously active header (0) has tabindex=0" );
|
|
|
|
assert.equal( headers.eq( 0 ).attr( "aria-selected" ), "false", "inactive tab (0) has aria-selected=false" );
|
|
|
|
assert.equal( headers.eq( 0 ).attr( "aria-expanded" ), "false", "inactive tab (0) has aria-expanded=false" );
|
|
|
|
assert.equal( headers.eq( 0 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel (0) has aria-hidden=true" );
|
|
|
|
assert.equal( headers.eq( 1 ).attr( "tabindex" ), -1, "inactive header (1) has tabindex=-1" );
|
|
|
|
assert.equal( headers.eq( 1 ).attr( "aria-selected" ), "false", "inactive tab (1) has aria-selected=false" );
|
|
|
|
assert.equal( headers.eq( 1 ).attr( "aria-expanded" ), "false", "inactive tab (1) has aria-expanded=false" );
|
|
|
|
assert.equal( headers.eq( 1 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel (1) has aria-hidden=true" );
|
|
|
|
assert.equal( headers.eq( 2 ).attr( "tabindex" ), -1, "inactive header (2) has tabindex=-1" );
|
|
|
|
assert.equal( headers.eq( 2 ).attr( "aria-selected" ), "false", "inactive tab (2) has aria-selected=false" );
|
|
|
|
assert.equal( headers.eq( 2 ).attr( "aria-expanded" ), "false", "inactive tab (2) has aria-expanded=false" );
|
|
|
|
assert.equal( headers.eq( 2 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel (2) has aria-hidden=true" );
|
2015-01-05 20:44:49 +00:00
|
|
|
|
|
|
|
element.accordion( "option", "active", 1 );
|
2016-04-03 14:37:27 +00:00
|
|
|
assert.equal( headers.eq( 1 ).attr( "tabindex" ), 0, "active header has tabindex=0" );
|
|
|
|
assert.equal( headers.eq( 1 ).attr( "aria-selected" ), "true", "active tab (1) has aria-selected=true" );
|
|
|
|
assert.equal( headers.eq( 1 ).attr( "aria-expanded" ), "true", "active tab (1) has aria-expanded=true" );
|
|
|
|
assert.equal( headers.eq( 1 ).next().attr( "aria-hidden" ), "false", "active tabpanel (1) has aria-hidden=false" );
|
|
|
|
assert.equal( headers.eq( 0 ).attr( "tabindex" ), -1, "inactive header (0) has tabindex=-1" );
|
|
|
|
assert.equal( headers.eq( 0 ).attr( "aria-selected" ), "false", "inactive tab (0) has aria-selected=false" );
|
|
|
|
assert.equal( headers.eq( 0 ).attr( "aria-expanded" ), "false", "inactive tab (0) has aria-expanded=false" );
|
|
|
|
assert.equal( headers.eq( 0 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel (0) has aria-hidden=true" );
|
|
|
|
assert.equal( headers.eq( 2 ).attr( "tabindex" ), -1, "inactive header (2) has tabindex=-1" );
|
|
|
|
assert.equal( headers.eq( 2 ).attr( "aria-selected" ), "false", "inactive tab (2) has aria-selected=false" );
|
|
|
|
assert.equal( headers.eq( 2 ).attr( "aria-expanded" ), "false", "inactive tab (2) has aria-expanded=false" );
|
|
|
|
assert.equal( headers.eq( 2 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel (2) has aria-hidden=true" );
|
2015-01-05 20:44:49 +00:00
|
|
|
|
2015-08-21 04:12:07 +00:00
|
|
|
} );
|
2009-02-02 14:36:08 +00:00
|
|
|
|
2016-04-03 14:37:27 +00:00
|
|
|
QUnit.test( "keyboard support", function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 13 );
|
2012-03-27 20:49:05 +00:00
|
|
|
var element = $( "#list1" ).accordion(),
|
|
|
|
headers = element.find( ".ui-accordion-header" ),
|
|
|
|
anchor = headers.eq( 1 ).next().find( "a" ).eq( 0 ),
|
|
|
|
keyCode = $.ui.keyCode;
|
2016-04-03 14:37:27 +00:00
|
|
|
assert.equal( headers.filter( ".ui-state-focus" ).length, 0, "no headers focused on init" );
|
2012-03-27 20:49:05 +00:00
|
|
|
headers.eq( 0 ).simulate( "focus" );
|
2015-03-10 20:10:43 +00:00
|
|
|
setTimeout( step1 );
|
|
|
|
|
|
|
|
function step1() {
|
2015-01-30 14:53:26 +00:00
|
|
|
assert.hasClasses( headers.eq( 0 ), "ui-state-focus", "first header has focus" );
|
2012-03-27 20:49:05 +00:00
|
|
|
headers.eq( 0 ).simulate( "keydown", { keyCode: keyCode.DOWN } );
|
2015-01-30 14:53:26 +00:00
|
|
|
assert.hasClasses( headers.eq( 1 ), "ui-state-focus", "DOWN moves focus to next header" );
|
2012-03-27 20:49:05 +00:00
|
|
|
headers.eq( 1 ).simulate( "keydown", { keyCode: keyCode.RIGHT } );
|
2015-01-30 14:53:26 +00:00
|
|
|
assert.hasClasses( headers.eq( 2 ), "ui-state-focus", "RIGHT moves focus to next header" );
|
2012-03-27 20:49:05 +00:00
|
|
|
headers.eq( 2 ).simulate( "keydown", { keyCode: keyCode.DOWN } );
|
2015-01-30 14:53:26 +00:00
|
|
|
assert.hasClasses( headers.eq( 0 ), "ui-state-focus", "DOWN wraps focus to first header" );
|
2015-03-10 20:10:43 +00:00
|
|
|
|
2021-04-09 21:36:00 +00:00
|
|
|
headers.eq( 0 ).simulate( "keydown", { keyCode: keyCode.UP } );
|
2015-01-30 14:53:26 +00:00
|
|
|
assert.hasClasses( headers.eq( 2 ), "ui-state-focus", "UP wraps focus to last header" );
|
2012-03-27 20:49:05 +00:00
|
|
|
headers.eq( 2 ).simulate( "keydown", { keyCode: keyCode.LEFT } );
|
2015-01-30 14:53:26 +00:00
|
|
|
assert.hasClasses( headers.eq( 1 ),
|
|
|
|
"ui-state-focus", "LEFT moves focus to previous header" );
|
2015-03-10 20:10:43 +00:00
|
|
|
|
2021-04-09 21:36:00 +00:00
|
|
|
headers.eq( 1 ).simulate( "keydown", { keyCode: keyCode.HOME } );
|
2015-01-30 14:53:26 +00:00
|
|
|
assert.hasClasses( headers.eq( 0 ), "ui-state-focus", "HOME moves focus to first header" );
|
2012-03-27 20:49:05 +00:00
|
|
|
headers.eq( 0 ).simulate( "keydown", { keyCode: keyCode.END } );
|
2015-01-30 14:53:26 +00:00
|
|
|
assert.hasClasses( headers.eq( 2 ), "ui-state-focus", "END moves focus to last header" );
|
2015-03-10 20:10:43 +00:00
|
|
|
|
2021-04-09 21:36:00 +00:00
|
|
|
headers.eq( 2 ).simulate( "keydown", { keyCode: keyCode.ENTER } );
|
2016-04-03 14:37:27 +00:00
|
|
|
assert.equal( element.accordion( "option", "active" ), 2, "ENTER activates panel" );
|
2012-03-27 20:49:05 +00:00
|
|
|
headers.eq( 1 ).simulate( "keydown", { keyCode: keyCode.SPACE } );
|
2016-04-03 14:37:27 +00:00
|
|
|
assert.equal( element.accordion( "option", "active" ), 1, "SPACE activates panel" );
|
2021-04-09 21:36:00 +00:00
|
|
|
|
2012-03-27 20:49:05 +00:00
|
|
|
anchor.simulate( "focus" );
|
2021-04-09 21:36:00 +00:00
|
|
|
setTimeout( step2 );
|
2015-03-10 20:10:43 +00:00
|
|
|
}
|
|
|
|
|
2021-04-09 21:36:00 +00:00
|
|
|
function step2() {
|
2015-01-30 14:53:26 +00:00
|
|
|
assert.lacksClasses( headers.eq( 1 ), "ui-state-focus",
|
|
|
|
"header loses focus when focusing inside the panel" );
|
2015-03-10 20:10:43 +00:00
|
|
|
anchor.simulate( "keydown", { keyCode: keyCode.UP, ctrlKey: true } );
|
2015-01-30 14:53:26 +00:00
|
|
|
assert.hasClasses( headers.eq( 1 ), "ui-state-focus", "CTRL+UP moves focus to header" );
|
2016-04-03 14:37:27 +00:00
|
|
|
ready();
|
2015-03-10 20:10:43 +00:00
|
|
|
}
|
2015-08-21 04:12:07 +00:00
|
|
|
} );
|
2012-03-27 14:19:35 +00:00
|
|
|
|
2015-04-03 19:24:09 +00:00
|
|
|
} );
|