aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/tabs/core.js
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/tabs/core.js')
-rw-r--r--tests/unit/tabs/core.js77
1 files changed, 77 insertions, 0 deletions
diff --git a/tests/unit/tabs/core.js b/tests/unit/tabs/core.js
index c2fd89048..1eac3c268 100644
--- a/tests/unit/tabs/core.js
+++ b/tests/unit/tabs/core.js
@@ -747,4 +747,81 @@ QUnit.test( "extra listeners created when tabs are added/removed (trac-15136)",
"No extra listeners after removing all the extra tabs" );
} );
+QUnit.test( "URL-based auth with local tabs (gh-2213)", function( assert ) {
+ assert.expect( 1 );
+
+ var origAjax = $.ajax,
+ element = $( "#tabs1" ),
+ anchor = element.find( "a[href='#fragment-3']" ),
+ url = new URL( anchor.prop( "href" ) );
+
+ try {
+ $.ajax = function() {
+ throw new Error( "Unexpected AJAX call; all tabs are local!" );
+ };
+
+ anchor.attr( "href", url.protocol + "//username:password@" + url.host +
+ url.pathname + url.search + url.hash );
+
+ element.tabs();
+ anchor.trigger( "click" );
+
+ assert.strictEqual( element.tabs( "option", "active" ), 2,
+ "should set the active option" );
+ } finally {
+ $.ajax = origAjax;
+ }
+} );
+
+( function() {
+ function getVerifyTab( assert, element ) {
+ return function verifyTab( index ) {
+ assert.strictEqual(
+ element.tabs( "option", "active" ),
+ index,
+ "should set the active option to " + index );
+ assert.strictEqual(
+ element.find( "[role='tabpanel']:visible" ).text().trim(),
+ "Tab " + ( index + 1 ),
+ "should set the panel to 'Tab " + ( index + 1 ) + "'" );
+ };
+ }
+
+ QUnit.test( "href encoding/decoding (gh-2344)", function( assert ) {
+ assert.expect( 12 );
+
+ location.hash = "#tabs-2";
+
+ var i,
+ element = $( "#tabs10" ).tabs(),
+ tabLinks = element.find( "> ul a" ),
+ verifyTab = getVerifyTab( assert, element );
+
+ for ( i = 0; i < tabLinks.length; i++ ) {
+ tabLinks.eq( i ).trigger( "click" );
+ verifyTab( i );
+ }
+
+ location.hash = "";
+ } );
+
+ QUnit.test( "href encoding/decoding on init (gh-2344)", function( assert ) {
+ assert.expect( 12 );
+
+ var i,
+ element = $( "#tabs10" ),
+ tabLinks = element.find( "> ul a" ),
+ verifyTab = getVerifyTab( assert, element );
+
+ for ( i = 0; i < tabLinks.length; i++ ) {
+ location.hash = tabLinks.eq( i ).attr( "href" );
+ element.tabs();
+ verifyTab( i );
+ element.tabs( "destroy" );
+ }
+
+ location.hash = "";
+ } );
+} )();
+
} );