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";
|
2011-01-25 00:20:09 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
var equalHeight = testHelper.equalHeight,
|
2020-05-16 07:16:24 +00:00
|
|
|
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: methods", beforeAfterEach() );
|
2011-01-25 00:20:09 +00:00
|
|
|
|
2016-04-03 14:37:27 +00:00
|
|
|
QUnit.test( "destroy", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2015-04-03 19:24:09 +00:00
|
|
|
assert.domEqual( "#list1", function() {
|
2011-06-13 18:51:13 +00:00
|
|
|
$( "#list1" ).accordion().accordion( "destroy" );
|
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( "enable/disable", function( assert ) {
|
|
|
|
assert.expect( 7 );
|
2011-06-13 18:51:13 +00:00
|
|
|
var element = $( "#list1" ).accordion();
|
2016-04-03 14:37:27 +00:00
|
|
|
state( assert, element, 1, 0, 0 );
|
2011-04-15 15:29:26 +00:00
|
|
|
element.accordion( "disable" );
|
2013-03-14 23:08:21 +00:00
|
|
|
|
2015-01-30 14:53:26 +00:00
|
|
|
assert.hasClasses( element, "ui-state-disabled" );
|
|
|
|
|
2016-04-03 14:37:27 +00:00
|
|
|
assert.equal( element.attr( "aria-disabled" ), "true", "element gets aria-disabled" );
|
2015-01-30 14:53:26 +00:00
|
|
|
assert.hasClasses( element, "ui-accordion-disabled" );
|
2013-03-14 23:08:21 +00:00
|
|
|
|
2015-08-21 04:12:07 +00:00
|
|
|
// Event does nothing
|
2012-03-07 18:54:06 +00:00
|
|
|
element.find( ".ui-accordion-header" ).eq( 1 ).trigger( "click" );
|
2016-04-03 14:37:27 +00:00
|
|
|
state( assert, element, 1, 0, 0 );
|
2015-08-21 04:12:07 +00:00
|
|
|
|
|
|
|
// Option still works
|
2011-04-15 15:29:26 +00:00
|
|
|
element.accordion( "option", "active", 1 );
|
2016-04-03 14:37:27 +00:00
|
|
|
state( assert, element, 0, 1, 0 );
|
2012-03-07 18:54:06 +00:00
|
|
|
element.accordion( "enable" );
|
|
|
|
element.accordion( "option", "active", 2 );
|
2016-04-03 14:37:27 +00:00
|
|
|
state( assert, element, 0, 0, 1 );
|
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( "refresh", function( assert ) {
|
|
|
|
assert.expect( 19 );
|
2011-04-15 15:29:26 +00:00
|
|
|
var element = $( "#navigation" )
|
2011-01-25 00:20:09 +00:00
|
|
|
.parent()
|
|
|
|
.height( 300 )
|
|
|
|
.end()
|
2015-08-21 04:12:07 +00:00
|
|
|
.accordion( {
|
2011-01-25 00:20:09 +00:00
|
|
|
heightStyle: "fill"
|
2015-08-21 04:12:07 +00:00
|
|
|
} );
|
2016-04-03 14:37:27 +00:00
|
|
|
equalHeight( assert, element, 255 );
|
2011-01-25 00:20:09 +00:00
|
|
|
|
2011-04-15 15:29:26 +00:00
|
|
|
element.parent().height( 500 );
|
|
|
|
element.accordion( "refresh" );
|
2016-04-03 14:37:27 +00:00
|
|
|
equalHeight( assert, element, 455 );
|
2012-11-12 02:37:56 +00:00
|
|
|
|
|
|
|
element = $( "#list1" );
|
|
|
|
element.accordion();
|
2016-04-03 14:37:27 +00:00
|
|
|
state( assert, element, 1, 0, 0 );
|
2012-11-12 02:37:56 +00:00
|
|
|
|
2015-08-21 04:12:07 +00:00
|
|
|
// Disable panel via markup
|
2012-11-12 02:37:56 +00:00
|
|
|
element.find( "h3.bar" ).eq( 1 ).addClass( "ui-state-disabled" );
|
|
|
|
element.accordion( "refresh" );
|
2016-04-03 14:37:27 +00:00
|
|
|
state( assert, element, 1, 0, 0 );
|
2012-11-12 02:37:56 +00:00
|
|
|
|
2015-08-21 04:12:07 +00:00
|
|
|
// Don't add multiple icons
|
2012-11-12 02:37:56 +00:00
|
|
|
element.accordion( "refresh" );
|
2016-04-03 14:37:27 +00:00
|
|
|
assert.equal( element.find( ".ui-accordion-header-icon" ).length, 3 );
|
2012-11-12 02:37:56 +00:00
|
|
|
|
2015-08-21 04:12:07 +00:00
|
|
|
// Add a panel
|
2012-11-12 02:37:56 +00:00
|
|
|
element
|
2015-08-21 04:12:07 +00:00
|
|
|
.append( "<h3 class='bar' id='new_1'>new 1</h3>" )
|
|
|
|
.append( "<div class='foo' id='new_1_panel'>new 1</div>" );
|
2012-11-12 02:37:56 +00:00
|
|
|
element.accordion( "refresh" );
|
2016-04-03 14:37:27 +00:00
|
|
|
state( assert, element, 1, 0, 0, 0 );
|
2012-11-12 02:37:56 +00:00
|
|
|
|
2015-08-21 04:12:07 +00:00
|
|
|
// Remove all tabs
|
2012-11-12 02:37:56 +00:00
|
|
|
element.find( "h3.bar, div.foo" ).remove();
|
|
|
|
element.accordion( "refresh" );
|
2016-04-03 14:37:27 +00:00
|
|
|
state( assert, element );
|
|
|
|
assert.equal( element.accordion( "option", "active" ), false, "no active accordion panel" );
|
2012-11-12 02:37:56 +00:00
|
|
|
|
2015-08-21 04:12:07 +00:00
|
|
|
// Add panels
|
2012-11-12 02:37:56 +00:00
|
|
|
element
|
2015-08-21 04:12:07 +00:00
|
|
|
.append( "<h3 class='bar' id='new_2'>new 2</h3>" )
|
|
|
|
.append( "<div class='foo' id='new_2_panel'>new 2</div>" )
|
|
|
|
.append( "<h3 class='bar' id='new_3'>new 3</h3>" )
|
|
|
|
.append( "<div class='foo' id='new_3_panel'>new 3</div>" )
|
|
|
|
.append( "<h3 class='bar' id='new_4'>new 4</h3>" )
|
|
|
|
.append( "<div class='foo' id='new_4_panel'>new 4</div>" )
|
|
|
|
.append( "<h3 class='bar' id='new_5'>new 5</h3>" )
|
|
|
|
.append( "<div class='foo' id='new_5_panel'>new 5</div>" );
|
2012-11-12 02:37:56 +00:00
|
|
|
element.accordion( "refresh" );
|
2016-04-03 14:37:27 +00:00
|
|
|
state( assert, element, 1, 0, 0, 0 );
|
2012-11-12 02:37:56 +00:00
|
|
|
|
2015-08-21 04:12:07 +00:00
|
|
|
// Activate third tab
|
2012-11-12 02:37:56 +00:00
|
|
|
element.accordion( "option", "active", 2 );
|
2016-04-03 14:37:27 +00:00
|
|
|
state( assert, element, 0, 0, 1, 0 );
|
2012-11-12 02:37:56 +00:00
|
|
|
|
2015-08-21 04:12:07 +00:00
|
|
|
// Remove fourth panel, third panel should stay active
|
2012-11-12 02:37:56 +00:00
|
|
|
element.find( "h3.bar" ).eq( 3 ).remove();
|
|
|
|
element.find( "div.foo" ).eq( 3 ).remove();
|
|
|
|
element.accordion( "refresh" );
|
2016-04-03 14:37:27 +00:00
|
|
|
state( assert, element, 0, 0, 1 );
|
2012-11-12 02:37:56 +00:00
|
|
|
|
2015-08-21 04:12:07 +00:00
|
|
|
// Remove third (active) panel, second panel should become active
|
2012-11-12 02:37:56 +00:00
|
|
|
element.find( "h3.bar" ).eq( 2 ).remove();
|
|
|
|
element.find( "div.foo" ).eq( 2 ).remove();
|
|
|
|
element.accordion( "refresh" );
|
2016-04-03 14:37:27 +00:00
|
|
|
state( assert, element, 0, 1 );
|
2012-11-12 02:37:56 +00:00
|
|
|
|
2015-08-21 04:12:07 +00:00
|
|
|
// Remove first panel, previously active panel (now first) should stay active
|
2012-11-12 02:37:56 +00:00
|
|
|
element.find( "h3.bar" ).eq( 0 ).remove();
|
|
|
|
element.find( "div.foo" ).eq( 0 ).remove();
|
|
|
|
element.accordion( "refresh" );
|
2016-04-03 14:37:27 +00:00
|
|
|
state( assert, element, 1 );
|
2013-03-27 19:23:59 +00:00
|
|
|
|
2015-08-21 04:12:07 +00:00
|
|
|
// Collapse all panels
|
2013-03-27 19:23:59 +00:00
|
|
|
element.accordion( "option", {
|
|
|
|
collapsible: true,
|
|
|
|
active: false
|
2015-08-21 04:12:07 +00:00
|
|
|
} );
|
2016-04-03 14:37:27 +00:00
|
|
|
state( assert, element, 0 );
|
2013-03-27 19:23:59 +00:00
|
|
|
element.accordion( "refresh" );
|
2016-04-03 14:37:27 +00:00
|
|
|
state( assert, element, 0 );
|
2015-08-21 04:12:07 +00:00
|
|
|
} );
|
2009-04-15 02:33:28 +00:00
|
|
|
|
2016-04-03 14:37:27 +00:00
|
|
|
QUnit.test( "widget", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2012-08-27 00:00:36 +00:00
|
|
|
var element = $( "#list1" ).accordion(),
|
|
|
|
widgetElement = element.accordion( "widget" );
|
2016-04-03 14:37:27 +00:00
|
|
|
assert.equal( widgetElement.length, 1, "one element" );
|
|
|
|
assert.strictEqual( widgetElement[ 0 ], element[ 0 ], "same element" );
|
2015-08-21 04:12:07 +00:00
|
|
|
} );
|
2012-08-27 00:00:36 +00:00
|
|
|
|
2015-04-03 19:24:09 +00:00
|
|
|
} );
|