Tabs: Added tests for load method.

This commit is contained in:
Scott González 2011-05-16 14:41:27 -04:00
parent 965cb7359e
commit 5e58859347
2 changed files with 84 additions and 8 deletions

View 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 ) );

11
ui/jquery.ui.tabs.js vendored
View 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