aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/accordion/events.js
diff options
context:
space:
mode:
authorScott González <scott.gonzalez@gmail.com>2015-04-07 10:55:52 -0400
committerScott González <scott.gonzalez@gmail.com>2015-04-09 09:27:00 -0400
commitbde431bb449b1d957d4e0b736111ff342f2a919d (patch)
tree27fd40037c30dbff8ef3b6113e90817ab96b53bf /tests/unit/accordion/events.js
parentdc4b015a8b9acdb5bff2d5dd89737b3d8b64097f (diff)
downloadjquery-ui-bde431bb449b1d957d4e0b736111ff342f2a919d.tar.gz
jquery-ui-bde431bb449b1d957d4e0b736111ff342f2a919d.zip
Tests: Rename files
Ref gh-1528
Diffstat (limited to 'tests/unit/accordion/events.js')
-rw-r--r--tests/unit/accordion/events.js168
1 files changed, 168 insertions, 0 deletions
diff --git a/tests/unit/accordion/events.js b/tests/unit/accordion/events.js
new file mode 100644
index 000000000..7f7390c83
--- /dev/null
+++ b/tests/unit/accordion/events.js
@@ -0,0 +1,168 @@
+define( [
+ "jquery",
+ "./helper",
+ "ui/accordion"
+], function( $, testHelper ) {
+
+var setupTeardown = testHelper.setupTeardown,
+ state = testHelper.state;
+
+module( "accordion: events", setupTeardown() );
+
+test( "create", function() {
+ expect( 10 );
+
+ var element = $( "#list1" ),
+ headers = element.children( "h3" ),
+ contents = headers.next();
+
+ element.accordion({
+ create: function( event, ui ) {
+ equal( ui.header.length, 1, "header length" );
+ strictEqual( ui.header[ 0 ], headers[ 0 ], "header" );
+ equal( ui.panel.length, 1, "panel length" );
+ strictEqual( ui.panel[ 0 ], contents[ 0 ], "panel" );
+ }
+ });
+ element.accordion( "destroy" );
+
+ element.accordion({
+ active: 2,
+ create: function( event, ui ) {
+ equal( ui.header.length, 1, "header length" );
+ strictEqual( ui.header[ 0 ], headers[ 2 ], "header" );
+ equal( ui.panel.length, 1, "panel length" );
+ strictEqual( ui.panel[ 0 ], contents[ 2 ], "panel" );
+ }
+ });
+ element.accordion( "destroy" );
+
+ element.accordion({
+ active: false,
+ collapsible: true,
+ create: function( event, ui ) {
+ equal( ui.header.length, 0, "header length" );
+ equal( ui.panel.length, 0, "panel length" );
+ }
+ });
+ element.accordion( "destroy" );
+});
+
+test( "beforeActivate", function() {
+ expect( 38 );
+ var element = $( "#list1" ).accordion({
+ active: false,
+ collapsible: true
+ }),
+ headers = element.find( ".ui-accordion-header" ),
+ content = element.find( ".ui-accordion-content" );
+
+ element.one( "accordionbeforeactivate", function( event, ui ) {
+ ok( !( "originalEvent" in event ) );
+ equal( ui.oldHeader.length, 0 );
+ equal( ui.oldPanel.length, 0 );
+ equal( ui.newHeader.length, 1 );
+ strictEqual( ui.newHeader[ 0 ], headers[ 0 ] );
+ equal( ui.newPanel.length, 1 );
+ strictEqual( ui.newPanel[ 0 ], content[ 0 ] );
+ state( element, 0, 0, 0 );
+ });
+ element.accordion( "option", "active", 0 );
+ state( element, 1, 0, 0 );
+
+ element.one( "accordionbeforeactivate", function( event, ui ) {
+ equal( event.originalEvent.type, "click" );
+ equal( ui.oldHeader.length, 1 );
+ strictEqual( ui.oldHeader[ 0 ], headers[ 0 ] );
+ equal( ui.oldPanel.length, 1 );
+ strictEqual( ui.oldPanel[ 0 ], content[ 0 ] );
+ equal( ui.newHeader.length, 1 );
+ strictEqual( ui.newHeader[ 0 ], headers[ 1 ] );
+ equal( ui.newPanel.length, 1 );
+ strictEqual( ui.newPanel[ 0 ], content[ 1 ] );
+ state( element, 1, 0, 0 );
+ });
+ headers.eq( 1 ).click();
+ state( element, 0, 1, 0 );
+
+ element.one( "accordionbeforeactivate", function( event, ui ) {
+ ok( !( "originalEvent" in event ) );
+ equal( ui.oldHeader.length, 1 );
+ strictEqual( ui.oldHeader[ 0 ], headers[ 1 ] );
+ equal( ui.oldPanel.length, 1 );
+ strictEqual( ui.oldPanel[ 0 ], content[ 1 ] );
+ equal( ui.newHeader.length, 0 );
+ equal( ui.newPanel.length, 0 );
+ state( element, 0, 1, 0 );
+ });
+ element.accordion( "option", "active", false );
+ state( element, 0, 0, 0 );
+
+ element.one( "accordionbeforeactivate", function( event, ui ) {
+ ok( !( "originalEvent" in event ) );
+ equal( ui.oldHeader.length, 0 );
+ equal( ui.oldPanel.length, 0 );
+ equal( ui.newHeader.length, 1 );
+ strictEqual( ui.newHeader[ 0 ], headers[ 2 ] );
+ equal( ui.newPanel.length, 1 );
+ strictEqual( ui.newPanel[ 0 ], content[ 2 ] );
+ event.preventDefault();
+ state( element, 0, 0, 0 );
+ });
+ element.accordion( "option", "active", 2 );
+ state( element, 0, 0, 0 );
+});
+
+test( "activate", function() {
+ expect( 21 );
+ var element = $( "#list1" ).accordion({
+ active: false,
+ collapsible: true
+ }),
+ headers = element.find( ".ui-accordion-header" ),
+ content = element.find( ".ui-accordion-content" );
+
+ element.one( "accordionactivate", function( event, ui ) {
+ equal( ui.oldHeader.length, 0 );
+ equal( ui.oldPanel.length, 0 );
+ equal( ui.newHeader.length, 1 );
+ strictEqual( ui.newHeader[ 0 ], headers[ 0 ] );
+ equal( ui.newPanel.length, 1 );
+ strictEqual( ui.newPanel[ 0 ], content[ 0 ] );
+ });
+ element.accordion( "option", "active", 0 );
+
+ element.one( "accordionactivate", function( event, ui ) {
+ equal( ui.oldHeader.length, 1 );
+ strictEqual( ui.oldHeader[ 0 ], headers[ 0 ] );
+ equal( ui.oldPanel.length, 1 );
+ strictEqual( ui.oldPanel[ 0 ], content[ 0 ] );
+ equal( ui.newHeader.length, 1 );
+ strictEqual( ui.newHeader[ 0 ], headers[ 1 ] );
+ equal( ui.newPanel.length, 1 );
+ strictEqual( ui.newPanel[ 0 ], content[ 1 ] );
+ });
+ headers.eq( 1 ).click();
+
+ element.one( "accordionactivate", function( event, ui ) {
+ equal( ui.oldHeader.length, 1 );
+ strictEqual( ui.oldHeader[ 0 ], headers[ 1 ] );
+ equal( ui.oldPanel.length, 1 );
+ strictEqual( ui.oldPanel[ 0 ], content[ 1 ] );
+ equal( ui.newHeader.length, 0 );
+ equal( ui.newPanel.length, 0 );
+ });
+ element.accordion( "option", "active", false );
+
+ // prevent activation
+ element.one( "accordionbeforeactivate", function( event ) {
+ ok( true );
+ event.preventDefault();
+ });
+ element.one( "accordionactivate", function() {
+ ok( false );
+ });
+ element.accordion( "option", "active", 1 );
+});
+
+} );