Skip to content
Permalink
Browse files

Tabs: Added tests for load method.

  • Loading branch information...
scottgonzalez committed May 16, 2011
1 parent 965cb73 commit 5e588593473f0988a958a2cbba4951a895821ba8
Showing with 84 additions and 8 deletions.
  1. +79 −2 tests/unit/tabs/tabs_methods.js
  2. +5 −6 ui/jquery.ui.tabs.js
@@ -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 ) );
@@ -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

0 comments on commit 5e58859

Please sign in to comment.
You can’t perform that action at this time.