]> source.dussan.org Git - jquery-ui.git/commitdiff
Tabs: Added tests for load method.
authorScott González <scott.gonzalez@gmail.com>
Mon, 16 May 2011 18:41:27 +0000 (14:41 -0400)
committerScott González <scott.gonzalez@gmail.com>
Mon, 16 May 2011 18:41:27 +0000 (14:41 -0400)
tests/unit/tabs/tabs_methods.js
ui/jquery.ui.tabs.js

index 221b0d39de82e2f3d3146b78ae41c4c310f33df4..5cf917550e5b473c7fba56aff03edfb6bcf5a70e 100644 (file)
@@ -145,8 +145,85 @@ test( "refresh", function() {
        tabs_disabled( element, false );
 });
 
-test('load', function() {
-       ok(false, "missing test - untested code is broken code.");
+asyncTest( "load", function() {
+       expect( 30 );
+
+       var element = $( "#tabs2" ).tabs();
+
+       // load content of inactive tab
+       // useful for preloading content with custom caching
+       element.one( "tabsbeforeload", function( event, ui ) {
+               var tab = element.find( ".ui-tabs-nav a" ).eq( 3 ),
+                       panelId = tab.attr( "aria-controls" ),
+                       panel = $( "#" + panelId );
+
+               ok( !( "originalEvent" in event ), "originalEvent" );
+               equals( ui.tab.size(), 1, "tab size" );
+               strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
+               equals( ui.panel.size(), 1, "panel size" );
+               strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
+               tabs_state( element, 1, 0, 0, 0, 0 );
+       });
+       element.one( "tabsload", function( event, ui ) {
+               var tab = element.find( ".ui-tabs-nav a" ).eq( 3 ),
+                       panelId = tab.attr( "aria-controls" ),
+                       panel = $( "#" + panelId );
+               
+               ok( !( "originalEvent" in event ), "originalEvent" );
+               equals( ui.tab.size(), 1, "tab size" );
+               strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
+               equals( ui.panel.size(), 1, "panel size" );
+               strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
+               equals( ui.panel.find( "p" ).length, 1, "panel html" );
+               tabs_state( element, 1, 0, 0, 0, 0 );
+               setTimeout( tabsload1, 1 );
+       });
+       element.tabs( "load", 3 );
+       tabs_state( element, 1, 0, 0, 0, 0 );
+
+       function tabsload1() {
+               // no need to test details of event (tested in events tests)
+               element.one( "tabsbeforeload", function() {
+                       ok( true, "tabsbeforeload invoked" );
+               });
+               element.one( "tabsload", function() {
+                       ok( true, "tabsload invoked" );
+                       setTimeout( tabsload2, 1 );
+               });
+               element.tabs( "option", "active", 3 );
+               tabs_state( element, 0, 0, 0, 1, 0 );
+       }
+
+       function tabsload2() {
+               // reload content of active tab
+               element.one( "tabsbeforeload", function( event, ui ) {
+                       var tab = element.find( ".ui-tabs-nav a" ).eq( 3 ),
+                               panelId = tab.attr( "aria-controls" ),
+                               panel = $( "#" + panelId );
+
+                       ok( !( "originalEvent" in event ), "originalEvent" );
+                       equals( ui.tab.size(), 1, "tab size" );
+                       strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
+                       equals( ui.panel.size(), 1, "panel size" );
+                       strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
+                       tabs_state( element, 0, 0, 0, 1, 0 );
+               });
+               element.one( "tabsload", function( event, ui ) {
+                       var tab = element.find( ".ui-tabs-nav a" ).eq( 3 ),
+                               panelId = tab.attr( "aria-controls" ),
+                               panel = $( "#" + panelId );
+                       
+                       ok( !( "originalEvent" in event ), "originalEvent" );
+                       equals( ui.tab.size(), 1, "tab size" );
+                       strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
+                       equals( ui.panel.size(), 1, "panel size" );
+                       strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
+                       tabs_state( element, 0, 0, 0, 1, 0 );
+                       start();
+               });
+               element.tabs( "load", 3 );
+               tabs_state( element, 0, 0, 0, 1, 0 );
+       }
 });
 
 }( jQuery ) );
index 0df35be339cee3b27a4b0c707f432f25f85736fd..36c9000efaf97f8bd1de0a74f9684e1e31ff0d48 100644 (file)
@@ -529,14 +529,14 @@ $.widget( "ui.tabs", {
        load: function( index, event ) {
                index = this._getIndex( index );
                var self = this,
-                       o = this.options,
-                       a = this.anchors.eq( index )[ 0 ],
-                       panel = self._getPanelForTab( a ),
+                       options = this.options,
+                       anchor = this.anchors.eq( index ),
+                       panel = self._getPanelForTab( anchor ),
                        // TODO until #3808 is fixed strip fragment identifier from url
                        // (IE fails to load from such url)
-                       url = $( a ).attr( "href" ).replace( /#.*$/, "" ),
+                       url = anchor.attr( "href" ).replace( /#.*$/, "" ),
                        eventData = {
-                               tab: $( a ),
+                               tab: anchor,
                                panel: panel
                        };
 
@@ -558,7 +558,6 @@ $.widget( "ui.tabs", {
                });
 
                if ( this.xhr ) {
-                       // load remote from here on
                        this.lis.eq( index ).addClass( "ui-tabs-loading" );
 
                        this.xhr