mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Tabs tests: Don't pollute the global namespace with helpers.
This commit is contained in:
parent
c16bd7c510
commit
33e93ef7f0
2
grunt.js
2
grunt.js
@ -388,8 +388,6 @@ grunt.initConfig({
|
|||||||
start: true,
|
start: true,
|
||||||
strictEqual: true,
|
strictEqual: true,
|
||||||
stop: true,
|
stop: true,
|
||||||
tabs_state: true,
|
|
||||||
tabs_disabled: true,
|
|
||||||
test: true,
|
test: true,
|
||||||
TestHelpers: true,
|
TestHelpers: true,
|
||||||
widthAfter: true
|
widthAfter: true
|
||||||
|
@ -25,68 +25,13 @@
|
|||||||
<script src="../../jquery.simulate.js"></script>
|
<script src="../../jquery.simulate.js"></script>
|
||||||
<script src="../testsuite.js"></script>
|
<script src="../testsuite.js"></script>
|
||||||
|
|
||||||
|
<script src="tabs_test_helpers.js"></script>
|
||||||
<script src="tabs_defaults.js"></script>
|
<script src="tabs_defaults.js"></script>
|
||||||
<script src="tabs_core.js"></script>
|
<script src="tabs_core.js"></script>
|
||||||
<script src="tabs_events.js"></script>
|
<script src="tabs_events.js"></script>
|
||||||
<script src="tabs_methods.js"></script>
|
<script src="tabs_methods.js"></script>
|
||||||
<script src="tabs_options.js"></script>
|
<script src="tabs_options.js"></script>
|
||||||
|
|
||||||
<script>
|
|
||||||
function tabs_state( tabs ) {
|
|
||||||
var expected = $.makeArray( arguments ).slice( 1 );
|
|
||||||
var actual = tabs.find( ".ui-tabs-nav li" ).map(function() {
|
|
||||||
var tab = $( this ),
|
|
||||||
panel = $( $.ui.tabs.prototype._sanitizeSelector(
|
|
||||||
"#" + tab.find( "a" ).attr( "aria-controls" ) ) ),
|
|
||||||
tabIsActive = tab.hasClass( "ui-state-active" ),
|
|
||||||
panelIsActive = panel.css( "display" ) !== "none";
|
|
||||||
|
|
||||||
if ( tabIsActive && panelIsActive ) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if ( !tabIsActive && !panelIsActive ) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return -1; // mixed state - invalid
|
|
||||||
}).get();
|
|
||||||
deepEqual( actual, expected );
|
|
||||||
}
|
|
||||||
|
|
||||||
function tabs_disabled( tabs, state ) {
|
|
||||||
var expected = $.map( new Array( tabs.find ( ".ui-tabs-nav li" ).length ), function( _, index ) {
|
|
||||||
if ( typeof state === "boolean" ) {
|
|
||||||
return state ? 1 : 0;
|
|
||||||
} else {
|
|
||||||
return $.inArray( index, state ) !== -1 ? 1 : 0;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var internalState = tabs.tabs( "option", "disabled" );
|
|
||||||
if ( internalState === false ) {
|
|
||||||
internalState = [];
|
|
||||||
}
|
|
||||||
if ( internalState === true ) {
|
|
||||||
internalState = $.map( new Array( tabs.find( ".ui-tabs-nav li" ).length ), function( _, index ) {
|
|
||||||
return index;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
var actual = tabs.find( ".ui-tabs-nav li" ).map(function( index ) {
|
|
||||||
var tab = $( this ),
|
|
||||||
tabIsDisabled = tab.hasClass( "ui-state-disabled" );
|
|
||||||
|
|
||||||
if ( tabIsDisabled && $.inArray( index, internalState ) !== -1 ) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if ( !tabIsDisabled && $.inArray( index, internalState ) === -1 ) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return -1; // mixed state - invalid
|
|
||||||
}).get();
|
|
||||||
deepEqual( tabs.tabs( "option", "disabled" ), state );
|
|
||||||
deepEqual( actual, expected );
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<script src="../swarminject.js"></script>
|
<script src="../swarminject.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
(function( $ ) {
|
(function( $ ) {
|
||||||
|
|
||||||
|
var state = TestHelpers.tabs.state;
|
||||||
|
|
||||||
module( "tabs: core" );
|
module( "tabs: core" );
|
||||||
|
|
||||||
test( "markup structure", function() {
|
test( "markup structure", function() {
|
||||||
@ -89,7 +91,7 @@ test( "#4033 - IE expands hash to full url and misinterprets tab as ajax", funct
|
|||||||
});
|
});
|
||||||
|
|
||||||
equal( element.find( ".ui-tabs-nav a" ).attr( "aria-controls" ), "tab", "aria-contorls attribute is correct" );
|
equal( element.find( ".ui-tabs-nav a" ).attr( "aria-controls" ), "tab", "aria-contorls attribute is correct" );
|
||||||
tabs_state( element, 1 );
|
state( element, 1 );
|
||||||
});
|
});
|
||||||
|
|
||||||
}( jQuery ) );
|
}( jQuery ) );
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
<script src="../../jquery.simulate.js"></script>
|
<script src="../../jquery.simulate.js"></script>
|
||||||
<script src="../testsuite.js"></script>
|
<script src="../testsuite.js"></script>
|
||||||
|
|
||||||
|
<script src="tabs_test_helpers.js"></script>
|
||||||
<script src="tabs_defaults_deprecated.js"></script>
|
<script src="tabs_defaults_deprecated.js"></script>
|
||||||
<script src="tabs_core.js"></script>
|
<script src="tabs_core.js"></script>
|
||||||
<script src="tabs_events.js"></script>
|
<script src="tabs_events.js"></script>
|
||||||
@ -30,62 +31,6 @@
|
|||||||
<script src="tabs_options.js"></script>
|
<script src="tabs_options.js"></script>
|
||||||
<script src="tabs_deprecated.js"></script>
|
<script src="tabs_deprecated.js"></script>
|
||||||
|
|
||||||
<script>
|
|
||||||
function tabs_state( tabs ) {
|
|
||||||
var expected = $.makeArray( arguments ).slice( 1 );
|
|
||||||
var actual = tabs.find( ".ui-tabs-nav li" ).map(function() {
|
|
||||||
var tab = $( this ),
|
|
||||||
panel = $( $.ui.tabs.prototype._sanitizeSelector(
|
|
||||||
"#" + tab.find( "a" ).attr( "aria-controls" ) ) ),
|
|
||||||
tabIsActive = tab.hasClass( "ui-state-active" ),
|
|
||||||
panelIsActive = panel.css( "display" ) !== "none";
|
|
||||||
|
|
||||||
if ( tabIsActive && panelIsActive ) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if ( !tabIsActive && !panelIsActive ) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return -1; // mixed state - invalid
|
|
||||||
}).get();
|
|
||||||
deepEqual( actual, expected );
|
|
||||||
}
|
|
||||||
|
|
||||||
function tabs_disabled( tabs, state ) {
|
|
||||||
var expected = $.map( new Array( tabs.find ( ".ui-tabs-nav li" ).length ), function( _, index ) {
|
|
||||||
if ( typeof state === "boolean" ) {
|
|
||||||
return state ? 1 : 0;
|
|
||||||
} else {
|
|
||||||
return $.inArray( index, state ) !== -1 ? 1 : 0;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var internalState = tabs.tabs( "option", "disabled" );
|
|
||||||
if ( internalState === false ) {
|
|
||||||
internalState = [];
|
|
||||||
}
|
|
||||||
if ( internalState === true ) {
|
|
||||||
internalState = $.map( new Array( tabs.find( ".ui-tabs-nav li" ).length ), function( _, index ) {
|
|
||||||
return index;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
var actual = tabs.find( ".ui-tabs-nav li" ).map(function( index ) {
|
|
||||||
var tab = $( this ),
|
|
||||||
tabIsDisabled = tab.hasClass( "ui-state-disabled" );
|
|
||||||
|
|
||||||
if ( tabIsDisabled && $.inArray( index, internalState ) !== -1 ) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if ( !tabIsDisabled && $.inArray( index, internalState ) === -1 ) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return -1; // mixed state - invalid
|
|
||||||
}).get();
|
|
||||||
deepEqual( tabs.tabs( "option", "disabled" ), state );
|
|
||||||
deepEqual( actual, expected );
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<script src="../swarminject.js"></script>
|
<script src="../swarminject.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
(function( $ ) {
|
(function( $ ) {
|
||||||
|
|
||||||
|
var state = TestHelpers.tabs.state;
|
||||||
|
|
||||||
module( "tabs (deprecated): core" );
|
module( "tabs (deprecated): core" );
|
||||||
|
|
||||||
test( "panel ids", function() {
|
test( "panel ids", function() {
|
||||||
@ -48,17 +50,17 @@ asyncTest( "cache", function() {
|
|||||||
cache: true
|
cache: true
|
||||||
});
|
});
|
||||||
element.one( "tabsshow", function( event, ui ) {
|
element.one( "tabsshow", function( event, ui ) {
|
||||||
tabs_state( element, 0, 0, 1, 0, 0 );
|
state( element, 0, 0, 1, 0, 0 );
|
||||||
});
|
});
|
||||||
element.one( "tabsload", function( event, ui ) {
|
element.one( "tabsload", function( event, ui ) {
|
||||||
ok( true, "tabsload" );
|
ok( true, "tabsload" );
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
element.tabs( "option", "active", 0 );
|
element.tabs( "option", "active", 0 );
|
||||||
tabs_state( element, 1, 0, 0, 0, 0 );
|
state( element, 1, 0, 0, 0, 0 );
|
||||||
|
|
||||||
element.one( "tabsshow", function( event, ui ) {
|
element.one( "tabsshow", function( event, ui ) {
|
||||||
tabs_state( element, 0, 0, 1, 0, 0 );
|
state( element, 0, 0, 1, 0, 0 );
|
||||||
});
|
});
|
||||||
element.one( "tabsload", function( event, ui ) {
|
element.one( "tabsload", function( event, ui ) {
|
||||||
ok( false, "should be cached" );
|
ok( false, "should be cached" );
|
||||||
@ -68,7 +70,7 @@ asyncTest( "cache", function() {
|
|||||||
}, 1 );
|
}, 1 );
|
||||||
});
|
});
|
||||||
element.tabs( "option", "active", 2 );
|
element.tabs( "option", "active", 2 );
|
||||||
tabs_state( element, 0, 0, 1, 0, 0 );
|
state( element, 0, 0, 1, 0, 0 );
|
||||||
});
|
});
|
||||||
|
|
||||||
test( "idPrefix", function() {
|
test( "idPrefix", function() {
|
||||||
@ -171,50 +173,50 @@ test( "selected", function() {
|
|||||||
|
|
||||||
var element = $( "#tabs1" ).tabs();
|
var element = $( "#tabs1" ).tabs();
|
||||||
equal( element.tabs( "option", "selected" ), 0, "should be 0 by default" );
|
equal( element.tabs( "option", "selected" ), 0, "should be 0 by default" );
|
||||||
tabs_state( element, 1, 0, 0 );
|
state( element, 1, 0, 0 );
|
||||||
element.tabs( "destroy" );
|
element.tabs( "destroy" );
|
||||||
|
|
||||||
location.hash = "#fragment-3";
|
location.hash = "#fragment-3";
|
||||||
element = $( "#tabs1" ).tabs();
|
element = $( "#tabs1" ).tabs();
|
||||||
equal( element.tabs( "option", "selected" ), 2, "should be 2 based on URL" );
|
equal( element.tabs( "option", "selected" ), 2, "should be 2 based on URL" );
|
||||||
tabs_state( element, 0, 0, 1 );
|
state( element, 0, 0, 1 );
|
||||||
element.tabs( "destroy" );
|
element.tabs( "destroy" );
|
||||||
|
|
||||||
el = $('#tabs1').tabs({
|
el = $('#tabs1').tabs({
|
||||||
selected: -1,
|
selected: -1,
|
||||||
collapsible: true
|
collapsible: true
|
||||||
});
|
});
|
||||||
tabs_state( element, 0, 0, 0 );
|
state( element, 0, 0, 0 );
|
||||||
equal( element.find( ".ui-tabs-nav .ui-state-active" ).size(), 0, "no tabs selected" );
|
equal( element.find( ".ui-tabs-nav .ui-state-active" ).size(), 0, "no tabs selected" );
|
||||||
strictEqual( element.tabs( "option", "selected" ), -1 );
|
strictEqual( element.tabs( "option", "selected" ), -1 );
|
||||||
|
|
||||||
element.tabs( "option", "collapsible", false );
|
element.tabs( "option", "collapsible", false );
|
||||||
tabs_state( element, 1, 0, 0 );
|
state( element, 1, 0, 0 );
|
||||||
equal( element.tabs( "option", "selected" ), 0 );
|
equal( element.tabs( "option", "selected" ), 0 );
|
||||||
element.tabs( "destroy" );
|
element.tabs( "destroy" );
|
||||||
|
|
||||||
element.tabs({
|
element.tabs({
|
||||||
selected: -1
|
selected: -1
|
||||||
});
|
});
|
||||||
tabs_state( element, 1, 0, 0 );
|
state( element, 1, 0, 0 );
|
||||||
strictEqual( element.tabs( "option", "selected" ), 0 );
|
strictEqual( element.tabs( "option", "selected" ), 0 );
|
||||||
element.tabs( "destroy" );
|
element.tabs( "destroy" );
|
||||||
|
|
||||||
element.tabs({ selected: 2 });
|
element.tabs({ selected: 2 });
|
||||||
equal( element.tabs( "option", "selected" ), 2 );
|
equal( element.tabs( "option", "selected" ), 2 );
|
||||||
tabs_state( element, 0, 0, 1 );
|
state( element, 0, 0, 1 );
|
||||||
|
|
||||||
element.tabs( "option", "selected", 0 );
|
element.tabs( "option", "selected", 0 );
|
||||||
equal( element.tabs( "option", "selected" ), 0 );
|
equal( element.tabs( "option", "selected" ), 0 );
|
||||||
tabs_state( element, 1, 0, 0 );
|
state( element, 1, 0, 0 );
|
||||||
|
|
||||||
element.find( ".ui-tabs-nav a" ).eq( 1 ).click();
|
element.find( ".ui-tabs-nav a" ).eq( 1 ).click();
|
||||||
equal( element.tabs( "option", "selected" ), 1 );
|
equal( element.tabs( "option", "selected" ), 1 );
|
||||||
tabs_state( element, 0, 1, 0 );
|
state( element, 0, 1, 0 );
|
||||||
|
|
||||||
element.tabs( "option", "selected", 10 );
|
element.tabs( "option", "selected", 10 );
|
||||||
equal( element.tabs( "option", "selected" ), 1 );
|
equal( element.tabs( "option", "selected" ), 1 );
|
||||||
tabs_state( element, 0, 1, 0 );
|
state( element, 0, 1, 0 );
|
||||||
|
|
||||||
location.hash = "#";
|
location.hash = "#";
|
||||||
});
|
});
|
||||||
@ -237,7 +239,7 @@ asyncTest( "load", function() {
|
|||||||
strictEqual( ui.tab, tab[ 0 ], "tab" );
|
strictEqual( ui.tab, tab[ 0 ], "tab" );
|
||||||
strictEqual( ui.panel, panel[ 0 ], "panel" );
|
strictEqual( ui.panel, panel[ 0 ], "panel" );
|
||||||
equal( $( ui.panel ).find( "p" ).length, 1, "panel html" );
|
equal( $( ui.panel ).find( "p" ).length, 1, "panel html" );
|
||||||
tabs_state( element, 0, 0, 1, 0, 0 );
|
state( element, 0, 0, 1, 0, 0 );
|
||||||
tabsload1();
|
tabsload1();
|
||||||
});
|
});
|
||||||
element.tabs({ active: 2 });
|
element.tabs({ active: 2 });
|
||||||
@ -253,7 +255,7 @@ asyncTest( "load", function() {
|
|||||||
strictEqual( ui.tab, tab[ 0 ], "tab" );
|
strictEqual( ui.tab, tab[ 0 ], "tab" );
|
||||||
strictEqual( ui.panel, panel[ 0 ], "panel" );
|
strictEqual( ui.panel, panel[ 0 ], "panel" );
|
||||||
equal( $( ui.panel ).find( "p" ).length, 1, "panel html" );
|
equal( $( ui.panel ).find( "p" ).length, 1, "panel html" );
|
||||||
tabs_state( element, 0, 0, 0, 1, 0 );
|
state( element, 0, 0, 0, 1, 0 );
|
||||||
tabsload2();
|
tabsload2();
|
||||||
});
|
});
|
||||||
element.tabs( "option", "active", 3 );
|
element.tabs( "option", "active", 3 );
|
||||||
@ -270,7 +272,7 @@ asyncTest( "load", function() {
|
|||||||
strictEqual( ui.tab, tab[ 0 ], "tab" );
|
strictEqual( ui.tab, tab[ 0 ], "tab" );
|
||||||
strictEqual( ui.panel, panel[ 0 ], "panel" );
|
strictEqual( ui.panel, panel[ 0 ], "panel" );
|
||||||
equal( $( ui.panel ).find( "p" ).length, 1, "panel html" );
|
equal( $( ui.panel ).find( "p" ).length, 1, "panel html" );
|
||||||
tabs_state( element, 0, 0, 0, 0, 1 );
|
state( element, 0, 0, 0, 0, 1 );
|
||||||
start();
|
start();
|
||||||
});
|
});
|
||||||
element.find( ".ui-tabs-nav a" ).eq( 4 ).click();
|
element.find( ".ui-tabs-nav a" ).eq( 4 ).click();
|
||||||
@ -325,10 +327,10 @@ test( "show", function() {
|
|||||||
strictEqual( ui.tab, tabs[ 0 ], "ui.tab" );
|
strictEqual( ui.tab, tabs[ 0 ], "ui.tab" );
|
||||||
strictEqual( ui.panel, panels[ 0 ], "ui.panel" );
|
strictEqual( ui.panel, panels[ 0 ], "ui.panel" );
|
||||||
equal( ui.index, 0, "ui.index" );
|
equal( ui.index, 0, "ui.index" );
|
||||||
tabs_state( element, 1, 0, 0 );
|
state( element, 1, 0, 0 );
|
||||||
});
|
});
|
||||||
element.tabs( "option", "active", 0 );
|
element.tabs( "option", "active", 0 );
|
||||||
tabs_state( element, 1, 0, 0 );
|
state( element, 1, 0, 0 );
|
||||||
|
|
||||||
// switching tabs
|
// switching tabs
|
||||||
element.one( "tabsshow", function( event, ui ) {
|
element.one( "tabsshow", function( event, ui ) {
|
||||||
@ -336,17 +338,17 @@ test( "show", function() {
|
|||||||
strictEqual( ui.tab, tabs[ 1 ], "ui.tab" );
|
strictEqual( ui.tab, tabs[ 1 ], "ui.tab" );
|
||||||
strictEqual( ui.panel, panels[ 1 ], "ui.panel" );
|
strictEqual( ui.panel, panels[ 1 ], "ui.panel" );
|
||||||
equal( ui.index, 1, "ui.index" );
|
equal( ui.index, 1, "ui.index" );
|
||||||
tabs_state( element, 0, 1, 0 );
|
state( element, 0, 1, 0 );
|
||||||
});
|
});
|
||||||
tabs.eq( 1 ).click();
|
tabs.eq( 1 ).click();
|
||||||
tabs_state( element, 0, 1, 0 );
|
state( element, 0, 1, 0 );
|
||||||
|
|
||||||
// collapsing
|
// collapsing
|
||||||
element.one( "tabsshow", function( event, ui ) {
|
element.one( "tabsshow", function( event, ui ) {
|
||||||
ok( false, "collapsing" );
|
ok( false, "collapsing" );
|
||||||
});
|
});
|
||||||
element.tabs( "option", "active", false );
|
element.tabs( "option", "active", false );
|
||||||
tabs_state( element, 0, 0, 0 );
|
state( element, 0, 0, 0 );
|
||||||
});
|
});
|
||||||
|
|
||||||
test( "select", function() {
|
test( "select", function() {
|
||||||
@ -365,10 +367,10 @@ test( "select", function() {
|
|||||||
strictEqual( ui.tab, tabs[ 0 ], "ui.tab" );
|
strictEqual( ui.tab, tabs[ 0 ], "ui.tab" );
|
||||||
strictEqual( ui.panel, panels[ 0 ], "ui.panel" );
|
strictEqual( ui.panel, panels[ 0 ], "ui.panel" );
|
||||||
equal( ui.index, 0, "ui.index" );
|
equal( ui.index, 0, "ui.index" );
|
||||||
tabs_state( element, 0, 0, 0 );
|
state( element, 0, 0, 0 );
|
||||||
});
|
});
|
||||||
element.tabs( "option", "active", 0 );
|
element.tabs( "option", "active", 0 );
|
||||||
tabs_state( element, 1, 0, 0 );
|
state( element, 1, 0, 0 );
|
||||||
|
|
||||||
// switching tabs
|
// switching tabs
|
||||||
element.one( "tabsselect", function( event, ui ) {
|
element.one( "tabsselect", function( event, ui ) {
|
||||||
@ -376,17 +378,17 @@ test( "select", function() {
|
|||||||
strictEqual( ui.tab, tabs[ 1 ], "ui.tab" );
|
strictEqual( ui.tab, tabs[ 1 ], "ui.tab" );
|
||||||
strictEqual( ui.panel, panels[ 1 ], "ui.panel" );
|
strictEqual( ui.panel, panels[ 1 ], "ui.panel" );
|
||||||
equal( ui.index, 1, "ui.index" );
|
equal( ui.index, 1, "ui.index" );
|
||||||
tabs_state( element, 1, 0, 0 );
|
state( element, 1, 0, 0 );
|
||||||
});
|
});
|
||||||
tabs.eq( 1 ).click();
|
tabs.eq( 1 ).click();
|
||||||
tabs_state( element, 0, 1, 0 );
|
state( element, 0, 1, 0 );
|
||||||
|
|
||||||
// collapsing
|
// collapsing
|
||||||
element.one( "tabsselect", function( event, ui ) {
|
element.one( "tabsselect", function( event, ui ) {
|
||||||
ok( false, "collapsing" );
|
ok( false, "collapsing" );
|
||||||
});
|
});
|
||||||
element.tabs( "option", "active", false );
|
element.tabs( "option", "active", false );
|
||||||
tabs_state( element, 0, 0, 0 );
|
state( element, 0, 0, 0 );
|
||||||
});
|
});
|
||||||
|
|
||||||
module( "tabs (deprecated): methods" );
|
module( "tabs (deprecated): methods" );
|
||||||
@ -396,7 +398,7 @@ test( "add", function() {
|
|||||||
|
|
||||||
var tab, anchor,
|
var tab, anchor,
|
||||||
element = $( "#tabs1" ).tabs();
|
element = $( "#tabs1" ).tabs();
|
||||||
tabs_state( element, 1, 0, 0 );
|
state( element, 1, 0, 0 );
|
||||||
|
|
||||||
// add without index
|
// add without index
|
||||||
element.one( "tabsadd", function( event, ui ) {
|
element.one( "tabsadd", function( event, ui ) {
|
||||||
@ -405,7 +407,7 @@ test( "add", function() {
|
|||||||
equal( ui.panel.id, "new", "ui.panel" );
|
equal( ui.panel.id, "new", "ui.panel" );
|
||||||
});
|
});
|
||||||
element.tabs( "add", "#new", "New" );
|
element.tabs( "add", "#new", "New" );
|
||||||
tabs_state( element, 1, 0, 0, 0 );
|
state( element, 1, 0, 0, 0 );
|
||||||
tab = element.find( ".ui-tabs-nav li" ).last();
|
tab = element.find( ".ui-tabs-nav li" ).last();
|
||||||
anchor = tab.find( "a" );
|
anchor = tab.find( "a" );
|
||||||
equal( tab.text(), "New", "label" );
|
equal( tab.text(), "New", "label" );
|
||||||
@ -415,7 +417,7 @@ test( "add", function() {
|
|||||||
anchor.simulate( "mouseover" );
|
anchor.simulate( "mouseover" );
|
||||||
ok( tab.hasClass( "ui-state-hover" ), "hovered" );
|
ok( tab.hasClass( "ui-state-hover" ), "hovered" );
|
||||||
anchor.simulate( "click" );
|
anchor.simulate( "click" );
|
||||||
tabs_state( element, 0, 0, 0, 1 );
|
state( element, 0, 0, 0, 1 );
|
||||||
|
|
||||||
// add remote tab with index
|
// add remote tab with index
|
||||||
element.one( "tabsadd", function( event, ui ) {
|
element.one( "tabsadd", function( event, ui ) {
|
||||||
@ -424,7 +426,7 @@ test( "add", function() {
|
|||||||
equal( ui.panel.id, $( ui.tab ).attr( "aria-controls" ), "ui.panel" );
|
equal( ui.panel.id, $( ui.tab ).attr( "aria-controls" ), "ui.panel" );
|
||||||
});
|
});
|
||||||
element.tabs( "add", "data/test.html", "New Remote", 1 );
|
element.tabs( "add", "data/test.html", "New Remote", 1 );
|
||||||
tabs_state( element, 0, 0, 0, 0, 1 );
|
state( element, 0, 0, 0, 0, 1 );
|
||||||
tab = element.find( ".ui-tabs-nav li" ).eq( 1 );
|
tab = element.find( ".ui-tabs-nav li" ).eq( 1 );
|
||||||
anchor = tab.find( "a" );
|
anchor = tab.find( "a" );
|
||||||
equal( tab.text(), "New Remote", "label" );
|
equal( tab.text(), "New Remote", "label" );
|
||||||
@ -434,7 +436,7 @@ test( "add", function() {
|
|||||||
anchor.simulate( "mouseover" );
|
anchor.simulate( "mouseover" );
|
||||||
ok( tab.hasClass( "ui-state-hover" ), "hovered" );
|
ok( tab.hasClass( "ui-state-hover" ), "hovered" );
|
||||||
anchor.simulate( "click" );
|
anchor.simulate( "click" );
|
||||||
tabs_state( element, 0, 1, 0, 0, 0 );
|
state( element, 0, 1, 0, 0, 0 );
|
||||||
|
|
||||||
// add to empty tab set
|
// add to empty tab set
|
||||||
element = $( "<div><ul></ul></div>" ).tabs();
|
element = $( "<div><ul></ul></div>" ).tabs();
|
||||||
@ -445,7 +447,7 @@ test( "add", function() {
|
|||||||
equal( ui.panel.id, "first", "ui.panel" );
|
equal( ui.panel.id, "first", "ui.panel" );
|
||||||
});
|
});
|
||||||
element.tabs( "add", "#first", "First" );
|
element.tabs( "add", "#first", "First" );
|
||||||
tabs_state( element, 1 );
|
state( element, 1 );
|
||||||
equal( element.tabs( "option", "active" ), 0, "active: 0 after add" );
|
equal( element.tabs( "option", "active" ), 0, "active: 0 after add" );
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -462,7 +464,7 @@ test( "remove", function() {
|
|||||||
expect( 17 );
|
expect( 17 );
|
||||||
|
|
||||||
var element = $( "#tabs1" ).tabs({ active: 1 });
|
var element = $( "#tabs1" ).tabs({ active: 1 });
|
||||||
tabs_state( element, 0, 1, 0 );
|
state( element, 0, 1, 0 );
|
||||||
|
|
||||||
element.one( "tabsremove", function( event, ui ) {
|
element.one( "tabsremove", function( event, ui ) {
|
||||||
equal( ui.index, -1, "ui.index" );
|
equal( ui.index, -1, "ui.index" );
|
||||||
@ -470,7 +472,7 @@ test( "remove", function() {
|
|||||||
equal( ui.panel.id, "fragment-2", "ui.panel" );
|
equal( ui.panel.id, "fragment-2", "ui.panel" );
|
||||||
});
|
});
|
||||||
element.tabs( "remove", 1 );
|
element.tabs( "remove", 1 );
|
||||||
tabs_state( element, 0, 1 );
|
state( element, 0, 1 );
|
||||||
equal( element.tabs( "option", "active" ), 1 );
|
equal( element.tabs( "option", "active" ), 1 );
|
||||||
equal( element.find( ".ui-tabs-nav li a[href$='fragment-2']" ).length, 0,
|
equal( element.find( ".ui-tabs-nav li a[href$='fragment-2']" ).length, 0,
|
||||||
"remove correct list item" );
|
"remove correct list item" );
|
||||||
@ -482,7 +484,7 @@ test( "remove", function() {
|
|||||||
equal( ui.panel.id, "fragment-3", "ui.panel" );
|
equal( ui.panel.id, "fragment-3", "ui.panel" );
|
||||||
});
|
});
|
||||||
element.tabs( "remove", 1 );
|
element.tabs( "remove", 1 );
|
||||||
tabs_state( element, 1 );
|
state( element, 1 );
|
||||||
equal( element.tabs( "option", "active"), 0 );
|
equal( element.tabs( "option", "active"), 0 );
|
||||||
|
|
||||||
element.one( "tabsremove", function( event, ui ) {
|
element.one( "tabsremove", function( event, ui ) {
|
||||||
@ -498,43 +500,43 @@ test( "select", function() {
|
|||||||
expect( 23 );
|
expect( 23 );
|
||||||
|
|
||||||
var element = $( "#tabs1" ).tabs();
|
var element = $( "#tabs1" ).tabs();
|
||||||
tabs_state( element, 1, 0, 0 );
|
state( element, 1, 0, 0 );
|
||||||
element.tabs( "select", 1 );
|
element.tabs( "select", 1 );
|
||||||
tabs_state( element, 0, 1, 0 );
|
state( element, 0, 1, 0 );
|
||||||
equal( element.tabs( "option", "active" ), 1, "active" );
|
equal( element.tabs( "option", "active" ), 1, "active" );
|
||||||
equal( element.tabs( "option", "selected" ), 1, "selected" );
|
equal( element.tabs( "option", "selected" ), 1, "selected" );
|
||||||
element.tabs( "destroy" );
|
element.tabs( "destroy" );
|
||||||
|
|
||||||
element.tabs({ collapsible: true });
|
element.tabs({ collapsible: true });
|
||||||
tabs_state( element, 1, 0, 0 );
|
state( element, 1, 0, 0 );
|
||||||
element.tabs( "select", 0 );
|
element.tabs( "select", 0 );
|
||||||
tabs_state( element, 0, 0, 0 );
|
state( element, 0, 0, 0 );
|
||||||
equal( element.tabs( "option", "active" ), false, "active" );
|
equal( element.tabs( "option", "active" ), false, "active" );
|
||||||
equal( element.tabs( "option", "selected" ), -1, "selected" );
|
equal( element.tabs( "option", "selected" ), -1, "selected" );
|
||||||
element.tabs( "destroy" );
|
element.tabs( "destroy" );
|
||||||
|
|
||||||
element.tabs({ collapsible: true });
|
element.tabs({ collapsible: true });
|
||||||
element.tabs( "select", -1 );
|
element.tabs( "select", -1 );
|
||||||
tabs_state( element, 0, 0, 0 );
|
state( element, 0, 0, 0 );
|
||||||
equal( element.tabs( "option", "active" ), false, "active" );
|
equal( element.tabs( "option", "active" ), false, "active" );
|
||||||
equal( element.tabs( "option", "selected" ), -1, "selected" );
|
equal( element.tabs( "option", "selected" ), -1, "selected" );
|
||||||
element.tabs( "destroy" );
|
element.tabs( "destroy" );
|
||||||
|
|
||||||
element.tabs();
|
element.tabs();
|
||||||
tabs_state( element, 1, 0, 0 );
|
state( element, 1, 0, 0 );
|
||||||
equal( element.tabs( "option", "active" ), 0, "active" );
|
equal( element.tabs( "option", "active" ), 0, "active" );
|
||||||
equal( element.tabs( "option", "selected" ), 0, "selected" );
|
equal( element.tabs( "option", "selected" ), 0, "selected" );
|
||||||
element.tabs( "select", 0 );
|
element.tabs( "select", 0 );
|
||||||
tabs_state( element, 1, 0, 0 );
|
state( element, 1, 0, 0 );
|
||||||
equal( element.tabs( "option", "active" ), 0, "active" );
|
equal( element.tabs( "option", "active" ), 0, "active" );
|
||||||
equal( element.tabs( "option", "selected" ), 0, "selected" );
|
equal( element.tabs( "option", "selected" ), 0, "selected" );
|
||||||
element.tabs( "select", -1 );
|
element.tabs( "select", -1 );
|
||||||
tabs_state( element, 1, 0, 0 );
|
state( element, 1, 0, 0 );
|
||||||
equal( element.tabs( "option", "active" ), 0, "active" );
|
equal( element.tabs( "option", "active" ), 0, "active" );
|
||||||
equal( element.tabs( "option", "selected" ), 0, "selected" );
|
equal( element.tabs( "option", "selected" ), 0, "selected" );
|
||||||
|
|
||||||
element.tabs( "select", "#fragment-2" );
|
element.tabs( "select", "#fragment-2" );
|
||||||
tabs_state( element, 0, 1, 0 );
|
state( element, 0, 1, 0 );
|
||||||
equal( element.tabs( "option", "active" ), 1, "active" );
|
equal( element.tabs( "option", "active" ), 1, "active" );
|
||||||
equal( element.tabs( "option", "selected" ), 1, "selected" );
|
equal( element.tabs( "option", "selected" ), 1, "selected" );
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
(function( $ ) {
|
(function( $ ) {
|
||||||
|
|
||||||
|
var state = TestHelpers.tabs.state;
|
||||||
|
|
||||||
module( "tabs: events" );
|
module( "tabs: events" );
|
||||||
|
|
||||||
test( "create", function() {
|
test( "create", function() {
|
||||||
@ -60,10 +62,10 @@ test( "beforeActivate", function() {
|
|||||||
strictEqual( ui.newTab[ 0 ], tabs[ 0 ], "newTab" );
|
strictEqual( ui.newTab[ 0 ], tabs[ 0 ], "newTab" );
|
||||||
equal( ui.newPanel.size(), 1, "newPanel size" );
|
equal( ui.newPanel.size(), 1, "newPanel size" );
|
||||||
strictEqual( ui.newPanel[ 0 ], panels[ 0 ], "newPanel" );
|
strictEqual( ui.newPanel[ 0 ], panels[ 0 ], "newPanel" );
|
||||||
tabs_state( element, 0, 0, 0 );
|
state( element, 0, 0, 0 );
|
||||||
});
|
});
|
||||||
element.tabs( "option", "active", 0 );
|
element.tabs( "option", "active", 0 );
|
||||||
tabs_state( element, 1, 0, 0 );
|
state( element, 1, 0, 0 );
|
||||||
|
|
||||||
// switching tabs
|
// switching tabs
|
||||||
element.one( "tabsbeforeactivate", function( event, ui ) {
|
element.one( "tabsbeforeactivate", function( event, ui ) {
|
||||||
@ -76,10 +78,10 @@ test( "beforeActivate", function() {
|
|||||||
strictEqual( ui.newTab[ 0 ], tabs[ 1 ], "newTab" );
|
strictEqual( ui.newTab[ 0 ], tabs[ 1 ], "newTab" );
|
||||||
equal( ui.newPanel.size(), 1, "newPanel size" );
|
equal( ui.newPanel.size(), 1, "newPanel size" );
|
||||||
strictEqual( ui.newPanel[ 0 ], panels[ 1 ], "newPanel" );
|
strictEqual( ui.newPanel[ 0 ], panels[ 1 ], "newPanel" );
|
||||||
tabs_state( element, 1, 0, 0 );
|
state( element, 1, 0, 0 );
|
||||||
});
|
});
|
||||||
tabs.eq( 1 ).click();
|
tabs.eq( 1 ).click();
|
||||||
tabs_state( element, 0, 1, 0 );
|
state( element, 0, 1, 0 );
|
||||||
|
|
||||||
// collapsing
|
// collapsing
|
||||||
element.one( "tabsbeforeactivate", function( event, ui ) {
|
element.one( "tabsbeforeactivate", function( event, ui ) {
|
||||||
@ -90,10 +92,10 @@ test( "beforeActivate", function() {
|
|||||||
strictEqual( ui.oldPanel[ 0 ], panels[ 1 ], "oldPanel" );
|
strictEqual( ui.oldPanel[ 0 ], panels[ 1 ], "oldPanel" );
|
||||||
equal( ui.newTab.size(), 0, "newTab size" );
|
equal( ui.newTab.size(), 0, "newTab size" );
|
||||||
equal( ui.newPanel.size(), 0, "newPanel size" );
|
equal( ui.newPanel.size(), 0, "newPanel size" );
|
||||||
tabs_state( element, 0, 1, 0 );
|
state( element, 0, 1, 0 );
|
||||||
});
|
});
|
||||||
element.tabs( "option", "active", false );
|
element.tabs( "option", "active", false );
|
||||||
tabs_state( element, 0, 0, 0 );
|
state( element, 0, 0, 0 );
|
||||||
|
|
||||||
// prevent activation
|
// prevent activation
|
||||||
element.one( "tabsbeforeactivate", function( event, ui ) {
|
element.one( "tabsbeforeactivate", function( event, ui ) {
|
||||||
@ -105,10 +107,10 @@ test( "beforeActivate", function() {
|
|||||||
equal( ui.newPanel.size(), 1, "newPanel size" );
|
equal( ui.newPanel.size(), 1, "newPanel size" );
|
||||||
strictEqual( ui.newPanel[ 0 ], panels[ 1 ], "newPanel" );
|
strictEqual( ui.newPanel[ 0 ], panels[ 1 ], "newPanel" );
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
tabs_state( element, 0, 0, 0 );
|
state( element, 0, 0, 0 );
|
||||||
});
|
});
|
||||||
element.tabs( "option", "active", 1 );
|
element.tabs( "option", "active", 1 );
|
||||||
tabs_state( element, 0, 0, 0 );
|
state( element, 0, 0, 0 );
|
||||||
});
|
});
|
||||||
|
|
||||||
test( "activate", function() {
|
test( "activate", function() {
|
||||||
@ -130,10 +132,10 @@ test( "activate", function() {
|
|||||||
strictEqual( ui.newTab[ 0 ], tabs[ 0 ], "newTab" );
|
strictEqual( ui.newTab[ 0 ], tabs[ 0 ], "newTab" );
|
||||||
equal( ui.newPanel.size(), 1, "newPanel size" );
|
equal( ui.newPanel.size(), 1, "newPanel size" );
|
||||||
strictEqual( ui.newPanel[ 0 ], panels[ 0 ], "newPanel" );
|
strictEqual( ui.newPanel[ 0 ], panels[ 0 ], "newPanel" );
|
||||||
tabs_state( element, 1, 0, 0 );
|
state( element, 1, 0, 0 );
|
||||||
});
|
});
|
||||||
element.tabs( "option", "active", 0 );
|
element.tabs( "option", "active", 0 );
|
||||||
tabs_state( element, 1, 0, 0 );
|
state( element, 1, 0, 0 );
|
||||||
|
|
||||||
// switching tabs
|
// switching tabs
|
||||||
element.one( "tabsactivate", function( event, ui ) {
|
element.one( "tabsactivate", function( event, ui ) {
|
||||||
@ -146,10 +148,10 @@ test( "activate", function() {
|
|||||||
strictEqual( ui.newTab[ 0 ], tabs[ 1 ], "newTab" );
|
strictEqual( ui.newTab[ 0 ], tabs[ 1 ], "newTab" );
|
||||||
equal( ui.newPanel.size(), 1, "newPanel size" );
|
equal( ui.newPanel.size(), 1, "newPanel size" );
|
||||||
strictEqual( ui.newPanel[ 0 ], panels[ 1 ], "newPanel" );
|
strictEqual( ui.newPanel[ 0 ], panels[ 1 ], "newPanel" );
|
||||||
tabs_state( element, 0, 1, 0 );
|
state( element, 0, 1, 0 );
|
||||||
});
|
});
|
||||||
tabs.eq( 1 ).click();
|
tabs.eq( 1 ).click();
|
||||||
tabs_state( element, 0, 1, 0 );
|
state( element, 0, 1, 0 );
|
||||||
|
|
||||||
// collapsing
|
// collapsing
|
||||||
element.one( "tabsactivate", function( event, ui ) {
|
element.one( "tabsactivate", function( event, ui ) {
|
||||||
@ -160,10 +162,10 @@ test( "activate", function() {
|
|||||||
strictEqual( ui.oldPanel[ 0 ], panels[ 1 ], "oldPanel" );
|
strictEqual( ui.oldPanel[ 0 ], panels[ 1 ], "oldPanel" );
|
||||||
equal( ui.newTab.size(), 0, "newTab size" );
|
equal( ui.newTab.size(), 0, "newTab size" );
|
||||||
equal( ui.newPanel.size(), 0, "newPanel size" );
|
equal( ui.newPanel.size(), 0, "newPanel size" );
|
||||||
tabs_state( element, 0, 0, 0 );
|
state( element, 0, 0, 0 );
|
||||||
});
|
});
|
||||||
element.tabs( "option", "active", false );
|
element.tabs( "option", "active", false );
|
||||||
tabs_state( element, 0, 0, 0 );
|
state( element, 0, 0, 0 );
|
||||||
|
|
||||||
// prevent activation
|
// prevent activation
|
||||||
element.one( "tabsbeforeactivate", function( event ) {
|
element.one( "tabsbeforeactivate", function( event ) {
|
||||||
@ -197,10 +199,10 @@ test( "beforeLoad", function() {
|
|||||||
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
|
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
|
||||||
equal( ui.panel.html(), "", "panel html" );
|
equal( ui.panel.html(), "", "panel html" );
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
tabs_state( element, 0, 0, 1, 0, 0 );
|
state( element, 0, 0, 1, 0, 0 );
|
||||||
});
|
});
|
||||||
element.tabs({ active: 2 });
|
element.tabs({ active: 2 });
|
||||||
tabs_state( element, 0, 0, 1, 0, 0 );
|
state( element, 0, 0, 1, 0, 0 );
|
||||||
equal( panel.html(), "", "panel html after" );
|
equal( panel.html(), "", "panel html after" );
|
||||||
element.tabs( "destroy" );
|
element.tabs( "destroy" );
|
||||||
|
|
||||||
@ -219,11 +221,11 @@ test( "beforeLoad", function() {
|
|||||||
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
|
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
|
||||||
equal( ui.panel.html(), "", "panel html" );
|
equal( ui.panel.html(), "", "panel html" );
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
tabs_state( element, 1, 0, 0, 0, 0 );
|
state( element, 1, 0, 0, 0, 0 );
|
||||||
});
|
});
|
||||||
element.tabs();
|
element.tabs();
|
||||||
element.tabs( "option", "active", 2 );
|
element.tabs( "option", "active", 2 );
|
||||||
tabs_state( element, 0, 0, 1, 0, 0 );
|
state( element, 0, 0, 1, 0, 0 );
|
||||||
equal( panel.html(), "", "panel html after" );
|
equal( panel.html(), "", "panel html after" );
|
||||||
|
|
||||||
// click, change panel content
|
// click, change panel content
|
||||||
@ -241,10 +243,10 @@ test( "beforeLoad", function() {
|
|||||||
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
|
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
|
||||||
ui.panel.html( "<p>testing</p>" );
|
ui.panel.html( "<p>testing</p>" );
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
tabs_state( element, 0, 0, 1, 0, 0 );
|
state( element, 0, 0, 1, 0, 0 );
|
||||||
});
|
});
|
||||||
element.find( ".ui-tabs-nav a" ).eq( 3 ).click();
|
element.find( ".ui-tabs-nav a" ).eq( 3 ).click();
|
||||||
tabs_state( element, 0, 0, 0, 1, 0 );
|
state( element, 0, 0, 0, 1, 0 );
|
||||||
// .toLowerCase() is needed to convert <P> to <p> in old IEs
|
// .toLowerCase() is needed to convert <P> to <p> in old IEs
|
||||||
equal( panel.html().toLowerCase(), "<p>testing</p>", "panel html after" );
|
equal( panel.html().toLowerCase(), "<p>testing</p>", "panel html after" );
|
||||||
});
|
});
|
||||||
@ -268,7 +270,7 @@ if ( $.uiBackCompat === false ) {
|
|||||||
equal( ui.panel.size(), 1, "panel size" );
|
equal( ui.panel.size(), 1, "panel size" );
|
||||||
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
|
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
|
||||||
equal( ui.panel.find( "p" ).length, 1, "panel html" );
|
equal( ui.panel.find( "p" ).length, 1, "panel html" );
|
||||||
tabs_state( element, 0, 0, 1, 0, 0 );
|
state( element, 0, 0, 1, 0, 0 );
|
||||||
tabsload1();
|
tabsload1();
|
||||||
});
|
});
|
||||||
element.tabs({ active: 2 });
|
element.tabs({ active: 2 });
|
||||||
@ -286,7 +288,7 @@ if ( $.uiBackCompat === false ) {
|
|||||||
equal( ui.panel.size(), 1, "panel size" );
|
equal( ui.panel.size(), 1, "panel size" );
|
||||||
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
|
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
|
||||||
equal( ui.panel.find( "p" ).length, 1, "panel html" );
|
equal( ui.panel.find( "p" ).length, 1, "panel html" );
|
||||||
tabs_state( element, 0, 0, 0, 1, 0 );
|
state( element, 0, 0, 0, 1, 0 );
|
||||||
tabsload2();
|
tabsload2();
|
||||||
});
|
});
|
||||||
element.tabs( "option", "active", 3 );
|
element.tabs( "option", "active", 3 );
|
||||||
@ -305,7 +307,7 @@ if ( $.uiBackCompat === false ) {
|
|||||||
equal( ui.panel.size(), 1, "panel size" );
|
equal( ui.panel.size(), 1, "panel size" );
|
||||||
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
|
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
|
||||||
equal( ui.panel.find( "p" ).length, 1, "panel html" );
|
equal( ui.panel.find( "p" ).length, 1, "panel html" );
|
||||||
tabs_state( element, 0, 0, 0, 0, 1 );
|
state( element, 0, 0, 0, 0, 1 );
|
||||||
start();
|
start();
|
||||||
});
|
});
|
||||||
element.find( ".ui-tabs-nav a" ).eq( 4 ).click();
|
element.find( ".ui-tabs-nav a" ).eq( 4 ).click();
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
(function( $ ) {
|
(function( $ ) {
|
||||||
|
|
||||||
|
var disabled = TestHelpers.tabs.disabled,
|
||||||
|
state = TestHelpers.tabs.state;
|
||||||
|
|
||||||
module( "tabs: methods" );
|
module( "tabs: methods" );
|
||||||
|
|
||||||
test( "destroy", function() {
|
test( "destroy", function() {
|
||||||
@ -12,95 +15,95 @@ test( "enable", function() {
|
|||||||
expect( 8 );
|
expect( 8 );
|
||||||
|
|
||||||
var element = $( "#tabs1" ).tabs({ disabled: true });
|
var element = $( "#tabs1" ).tabs({ disabled: true });
|
||||||
tabs_disabled( element, true );
|
disabled( element, true );
|
||||||
element.tabs( "enable" );
|
element.tabs( "enable" );
|
||||||
tabs_disabled( element, false );
|
disabled( element, false );
|
||||||
element.tabs( "destroy" );
|
element.tabs( "destroy" );
|
||||||
|
|
||||||
element.tabs({ disabled: [ 0, 1 ] });
|
element.tabs({ disabled: [ 0, 1 ] });
|
||||||
tabs_disabled( element, [ 0, 1 ] );
|
disabled( element, [ 0, 1 ] );
|
||||||
element.tabs( "enable" );
|
element.tabs( "enable" );
|
||||||
tabs_disabled( element, false );
|
disabled( element, false );
|
||||||
});
|
});
|
||||||
|
|
||||||
test( "enable( index )", function() {
|
test( "enable( index )", function() {
|
||||||
expect( 10 );
|
expect( 10 );
|
||||||
|
|
||||||
var element = $( "#tabs1" ).tabs({ disabled: true });
|
var element = $( "#tabs1" ).tabs({ disabled: true });
|
||||||
tabs_disabled( element, true );
|
disabled( element, true );
|
||||||
// fully disabled -> partially disabled
|
// fully disabled -> partially disabled
|
||||||
element.tabs( "enable", 1 );
|
element.tabs( "enable", 1 );
|
||||||
tabs_disabled( element, [ 0, 2 ] );
|
disabled( element, [ 0, 2 ] );
|
||||||
// partially disabled -> partially disabled
|
// partially disabled -> partially disabled
|
||||||
element.tabs( "enable", 2 );
|
element.tabs( "enable", 2 );
|
||||||
tabs_disabled( element, [ 0 ] );
|
disabled( element, [ 0 ] );
|
||||||
// already enabled tab, no change
|
// already enabled tab, no change
|
||||||
element.tabs( "enable", 2 );
|
element.tabs( "enable", 2 );
|
||||||
tabs_disabled( element, [ 0 ] );
|
disabled( element, [ 0 ] );
|
||||||
// partially disabled -> fully enabled
|
// partially disabled -> fully enabled
|
||||||
element.tabs( "enable", 0 );
|
element.tabs( "enable", 0 );
|
||||||
tabs_disabled( element, false );
|
disabled( element, false );
|
||||||
});
|
});
|
||||||
|
|
||||||
test( "disable", function() {
|
test( "disable", function() {
|
||||||
expect( 8 );
|
expect( 8 );
|
||||||
|
|
||||||
var element = $( "#tabs1" ).tabs({ disabled: false });
|
var element = $( "#tabs1" ).tabs({ disabled: false });
|
||||||
tabs_disabled( element, false );
|
disabled( element, false );
|
||||||
element.tabs( "disable" );
|
element.tabs( "disable" );
|
||||||
tabs_disabled( element, true );
|
disabled( element, true );
|
||||||
element.tabs( "destroy" );
|
element.tabs( "destroy" );
|
||||||
|
|
||||||
element.tabs({ disabled: [ 0, 1 ] });
|
element.tabs({ disabled: [ 0, 1 ] });
|
||||||
tabs_disabled( element, [ 0, 1 ] );
|
disabled( element, [ 0, 1 ] );
|
||||||
element.tabs( "disable" );
|
element.tabs( "disable" );
|
||||||
tabs_disabled( element, true );
|
disabled( element, true );
|
||||||
});
|
});
|
||||||
|
|
||||||
test( "disable( index )", function() {
|
test( "disable( index )", function() {
|
||||||
expect( 10 );
|
expect( 10 );
|
||||||
|
|
||||||
var element = $( "#tabs1" ).tabs({ disabled: false });
|
var element = $( "#tabs1" ).tabs({ disabled: false });
|
||||||
tabs_disabled( element, false );
|
disabled( element, false );
|
||||||
// fully enabled -> partially disabled
|
// fully enabled -> partially disabled
|
||||||
element.tabs( "disable", 1 );
|
element.tabs( "disable", 1 );
|
||||||
tabs_disabled( element, [ 1 ] );
|
disabled( element, [ 1 ] );
|
||||||
// partially disabled -> partially disabled
|
// partially disabled -> partially disabled
|
||||||
element.tabs( "disable", 2 );
|
element.tabs( "disable", 2 );
|
||||||
tabs_disabled( element, [ 1, 2 ] );
|
disabled( element, [ 1, 2 ] );
|
||||||
// already disabled tab, no change
|
// already disabled tab, no change
|
||||||
element.tabs( "disable", 2 );
|
element.tabs( "disable", 2 );
|
||||||
tabs_disabled( element, [ 1, 2 ] );
|
disabled( element, [ 1, 2 ] );
|
||||||
// partially disabled -> fully disabled
|
// partially disabled -> fully disabled
|
||||||
element.tabs( "disable", 0 );
|
element.tabs( "disable", 0 );
|
||||||
tabs_disabled( element, true );
|
disabled( element, true );
|
||||||
});
|
});
|
||||||
|
|
||||||
test( "refresh", function() {
|
test( "refresh", function() {
|
||||||
expect( 27 );
|
expect( 27 );
|
||||||
|
|
||||||
var element = $( "#tabs1" ).tabs();
|
var element = $( "#tabs1" ).tabs();
|
||||||
tabs_state( element, 1, 0, 0 );
|
state( element, 1, 0, 0 );
|
||||||
tabs_disabled( element, false );
|
disabled( element, false );
|
||||||
|
|
||||||
// disable tab via markup
|
// disable tab via markup
|
||||||
element.find( ".ui-tabs-nav li" ).eq( 1 ).addClass( "ui-state-disabled" );
|
element.find( ".ui-tabs-nav li" ).eq( 1 ).addClass( "ui-state-disabled" );
|
||||||
element.tabs( "refresh" );
|
element.tabs( "refresh" );
|
||||||
tabs_state( element, 1, 0, 0 );
|
state( element, 1, 0, 0 );
|
||||||
tabs_disabled( element, [ 1 ] );
|
disabled( element, [ 1 ] );
|
||||||
|
|
||||||
// add remote tab
|
// add remote tab
|
||||||
element.find( ".ui-tabs-nav" ).append( "<li id='newTab'><a href='data/test.html'>new</a></li>" );
|
element.find( ".ui-tabs-nav" ).append( "<li id='newTab'><a href='data/test.html'>new</a></li>" );
|
||||||
element.tabs( "refresh" );
|
element.tabs( "refresh" );
|
||||||
tabs_state( element, 1, 0, 0, 0 );
|
state( element, 1, 0, 0, 0 );
|
||||||
tabs_disabled( element, [ 1 ] );
|
disabled( element, [ 1 ] );
|
||||||
equal( element.find( "#" + $( "#newTab a" ).attr( "aria-controls" ) ).length, 1,
|
equal( element.find( "#" + $( "#newTab a" ).attr( "aria-controls" ) ).length, 1,
|
||||||
"panel added for remote tab" );
|
"panel added for remote tab" );
|
||||||
|
|
||||||
// remove all tabs
|
// remove all tabs
|
||||||
element.find( ".ui-tabs-nav li, .ui-tabs-panel" ).remove();
|
element.find( ".ui-tabs-nav li, .ui-tabs-panel" ).remove();
|
||||||
element.tabs( "refresh" );
|
element.tabs( "refresh" );
|
||||||
tabs_state( element );
|
state( element );
|
||||||
equal( element.tabs( "option", "active" ), false, "no active tab" );
|
equal( element.tabs( "option", "active" ), false, "no active tab" );
|
||||||
|
|
||||||
// add tabs
|
// add tabs
|
||||||
@ -115,34 +118,34 @@ test( "refresh", function() {
|
|||||||
.append( "<div id='newTab4'>new 4</div>" )
|
.append( "<div id='newTab4'>new 4</div>" )
|
||||||
.append( "<div id='newTab5'>new 5</div>" );
|
.append( "<div id='newTab5'>new 5</div>" );
|
||||||
element.tabs( "refresh" );
|
element.tabs( "refresh" );
|
||||||
tabs_state( element, 0, 0, 0, 0 );
|
state( element, 0, 0, 0, 0 );
|
||||||
tabs_disabled( element, [ 0 ] );
|
disabled( element, [ 0 ] );
|
||||||
|
|
||||||
// activate third tab
|
// activate third tab
|
||||||
element.tabs( "option", "active", 2 );
|
element.tabs( "option", "active", 2 );
|
||||||
tabs_state( element, 0, 0, 1, 0 );
|
state( element, 0, 0, 1, 0 );
|
||||||
tabs_disabled( element, [ 0 ] );
|
disabled( element, [ 0 ] );
|
||||||
|
|
||||||
// remove fourth tab, third tab should stay active
|
// remove fourth tab, third tab should stay active
|
||||||
element.find( ".ui-tabs-nav li" ).eq( 3 ).remove();
|
element.find( ".ui-tabs-nav li" ).eq( 3 ).remove();
|
||||||
element.find( ".ui-tabs-panel" ).eq( 3 ).remove();
|
element.find( ".ui-tabs-panel" ).eq( 3 ).remove();
|
||||||
element.tabs( "refresh" );
|
element.tabs( "refresh" );
|
||||||
tabs_state( element, 0, 0, 1 );
|
state( element, 0, 0, 1 );
|
||||||
tabs_disabled( element, [ 0 ] );
|
disabled( element, [ 0 ] );
|
||||||
|
|
||||||
// remove third (active) tab, second tab should become active
|
// remove third (active) tab, second tab should become active
|
||||||
element.find( ".ui-tabs-nav li" ).eq( 2 ).remove();
|
element.find( ".ui-tabs-nav li" ).eq( 2 ).remove();
|
||||||
element.find( ".ui-tabs-panel" ).eq( 2 ).remove();
|
element.find( ".ui-tabs-panel" ).eq( 2 ).remove();
|
||||||
element.tabs( "refresh" );
|
element.tabs( "refresh" );
|
||||||
tabs_state( element, 0, 1 );
|
state( element, 0, 1 );
|
||||||
tabs_disabled( element, [ 0 ] );
|
disabled( element, [ 0 ] );
|
||||||
|
|
||||||
// remove first tab, previously active tab (now first) should stay active
|
// remove first tab, previously active tab (now first) should stay active
|
||||||
element.find( ".ui-tabs-nav li" ).eq( 0 ).remove();
|
element.find( ".ui-tabs-nav li" ).eq( 0 ).remove();
|
||||||
element.find( ".ui-tabs-panel" ).eq( 0 ).remove();
|
element.find( ".ui-tabs-panel" ).eq( 0 ).remove();
|
||||||
element.tabs( "refresh" );
|
element.tabs( "refresh" );
|
||||||
tabs_state( element, 1 );
|
state( element, 1 );
|
||||||
tabs_disabled( element, false );
|
disabled( element, false );
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest( "load", function() {
|
asyncTest( "load", function() {
|
||||||
@ -162,7 +165,7 @@ asyncTest( "load", function() {
|
|||||||
strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
|
strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
|
||||||
equal( ui.panel.size(), 1, "panel size" );
|
equal( ui.panel.size(), 1, "panel size" );
|
||||||
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
|
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
|
||||||
tabs_state( element, 1, 0, 0, 0, 0 );
|
state( element, 1, 0, 0, 0, 0 );
|
||||||
});
|
});
|
||||||
element.one( "tabsload", function( event, ui ) {
|
element.one( "tabsload", function( event, ui ) {
|
||||||
// TODO: remove wrapping in 2.0
|
// TODO: remove wrapping in 2.0
|
||||||
@ -178,11 +181,11 @@ asyncTest( "load", function() {
|
|||||||
equal( uiPanel.size(), 1, "panel size" );
|
equal( uiPanel.size(), 1, "panel size" );
|
||||||
strictEqual( uiPanel[ 0 ], panel[ 0 ], "panel" );
|
strictEqual( uiPanel[ 0 ], panel[ 0 ], "panel" );
|
||||||
equal( uiPanel.find( "p" ).length, 1, "panel html" );
|
equal( uiPanel.find( "p" ).length, 1, "panel html" );
|
||||||
tabs_state( element, 1, 0, 0, 0, 0 );
|
state( element, 1, 0, 0, 0, 0 );
|
||||||
setTimeout( tabsload1, 100 );
|
setTimeout( tabsload1, 100 );
|
||||||
});
|
});
|
||||||
element.tabs( "load", 3 );
|
element.tabs( "load", 3 );
|
||||||
tabs_state( element, 1, 0, 0, 0, 0 );
|
state( element, 1, 0, 0, 0, 0 );
|
||||||
|
|
||||||
function tabsload1() {
|
function tabsload1() {
|
||||||
// no need to test details of event (tested in events tests)
|
// no need to test details of event (tested in events tests)
|
||||||
@ -194,7 +197,7 @@ asyncTest( "load", function() {
|
|||||||
setTimeout( tabsload2, 100 );
|
setTimeout( tabsload2, 100 );
|
||||||
});
|
});
|
||||||
element.tabs( "option", "active", 3 );
|
element.tabs( "option", "active", 3 );
|
||||||
tabs_state( element, 0, 0, 0, 1, 0 );
|
state( element, 0, 0, 0, 1, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
function tabsload2() {
|
function tabsload2() {
|
||||||
@ -209,7 +212,7 @@ asyncTest( "load", function() {
|
|||||||
strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
|
strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
|
||||||
equal( ui.panel.size(), 1, "panel size" );
|
equal( ui.panel.size(), 1, "panel size" );
|
||||||
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
|
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
|
||||||
tabs_state( element, 0, 0, 0, 1, 0 );
|
state( element, 0, 0, 0, 1, 0 );
|
||||||
});
|
});
|
||||||
element.one( "tabsload", function( event, ui ) {
|
element.one( "tabsload", function( event, ui ) {
|
||||||
// TODO: remove wrapping in 2.0
|
// TODO: remove wrapping in 2.0
|
||||||
@ -224,11 +227,11 @@ asyncTest( "load", function() {
|
|||||||
strictEqual( uiTab[ 0 ], tab[ 0 ], "tab" );
|
strictEqual( uiTab[ 0 ], tab[ 0 ], "tab" );
|
||||||
equal( uiPanel.size(), 1, "panel size" );
|
equal( uiPanel.size(), 1, "panel size" );
|
||||||
strictEqual( uiPanel[ 0 ], panel[ 0 ], "panel" );
|
strictEqual( uiPanel[ 0 ], panel[ 0 ], "panel" );
|
||||||
tabs_state( element, 0, 0, 0, 1, 0 );
|
state( element, 0, 0, 0, 1, 0 );
|
||||||
start();
|
start();
|
||||||
});
|
});
|
||||||
element.tabs( "load", 3 );
|
element.tabs( "load", 3 );
|
||||||
tabs_state( element, 0, 0, 0, 1, 0 );
|
state( element, 0, 0, 0, 1, 0 );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
(function( $ ) {
|
(function( $ ) {
|
||||||
|
|
||||||
|
var disabled = TestHelpers.tabs.disabled,
|
||||||
|
state = TestHelpers.tabs.state;
|
||||||
|
|
||||||
module( "tabs: options" );
|
module( "tabs: options" );
|
||||||
|
|
||||||
test( "{ active: default }", function() {
|
test( "{ active: default }", function() {
|
||||||
@ -7,13 +10,13 @@ test( "{ active: default }", function() {
|
|||||||
|
|
||||||
var element = $( "#tabs1" ).tabs();
|
var element = $( "#tabs1" ).tabs();
|
||||||
equal( element.tabs( "option", "active" ), 0, "should be 0 by default" );
|
equal( element.tabs( "option", "active" ), 0, "should be 0 by default" );
|
||||||
tabs_state( element, 1, 0, 0 );
|
state( element, 1, 0, 0 );
|
||||||
element.tabs( "destroy" );
|
element.tabs( "destroy" );
|
||||||
|
|
||||||
location.hash = "#fragment-3";
|
location.hash = "#fragment-3";
|
||||||
element = $( "#tabs1" ).tabs();
|
element = $( "#tabs1" ).tabs();
|
||||||
equal( element.tabs( "option", "active" ), 2, "should be 2 based on URL" );
|
equal( element.tabs( "option", "active" ), 2, "should be 2 based on URL" );
|
||||||
tabs_state( element, 0, 0, 1 );
|
state( element, 0, 0, 1 );
|
||||||
element.tabs( "destroy" );
|
element.tabs( "destroy" );
|
||||||
location.hash = "#";
|
location.hash = "#";
|
||||||
});
|
});
|
||||||
@ -25,19 +28,19 @@ test( "{ active: false }", function() {
|
|||||||
active: false,
|
active: false,
|
||||||
collapsible: true
|
collapsible: true
|
||||||
});
|
});
|
||||||
tabs_state( element, 0, 0, 0 );
|
state( element, 0, 0, 0 );
|
||||||
equal( element.find( ".ui-tabs-nav .ui-state-active" ).size(), 0, "no tabs selected" );
|
equal( element.find( ".ui-tabs-nav .ui-state-active" ).size(), 0, "no tabs selected" );
|
||||||
strictEqual( element.tabs( "option", "active" ), false );
|
strictEqual( element.tabs( "option", "active" ), false );
|
||||||
|
|
||||||
element.tabs( "option", "collapsible", false );
|
element.tabs( "option", "collapsible", false );
|
||||||
tabs_state( element, 1, 0, 0 );
|
state( element, 1, 0, 0 );
|
||||||
equal( element.tabs( "option", "active" ), 0 );
|
equal( element.tabs( "option", "active" ), 0 );
|
||||||
|
|
||||||
element.tabs( "destroy" );
|
element.tabs( "destroy" );
|
||||||
element.tabs({
|
element.tabs({
|
||||||
active: false
|
active: false
|
||||||
});
|
});
|
||||||
tabs_state( element, 1, 0, 0 );
|
state( element, 1, 0, 0 );
|
||||||
strictEqual( element.tabs( "option", "active" ), 0 );
|
strictEqual( element.tabs( "option", "active" ), 0 );
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -48,19 +51,19 @@ test( "{ active: Number }", function() {
|
|||||||
active: 2
|
active: 2
|
||||||
});
|
});
|
||||||
equal( element.tabs( "option", "active" ), 2 );
|
equal( element.tabs( "option", "active" ), 2 );
|
||||||
tabs_state( element, 0, 0, 1 );
|
state( element, 0, 0, 1 );
|
||||||
|
|
||||||
element.tabs( "option", "active", 0 );
|
element.tabs( "option", "active", 0 );
|
||||||
equal( element.tabs( "option", "active" ), 0 );
|
equal( element.tabs( "option", "active" ), 0 );
|
||||||
tabs_state( element, 1, 0, 0 );
|
state( element, 1, 0, 0 );
|
||||||
|
|
||||||
element.find( ".ui-tabs-nav a" ).eq( 1 ).click();
|
element.find( ".ui-tabs-nav a" ).eq( 1 ).click();
|
||||||
equal( element.tabs( "option", "active" ), 1 );
|
equal( element.tabs( "option", "active" ), 1 );
|
||||||
tabs_state( element, 0, 1, 0 );
|
state( element, 0, 1, 0 );
|
||||||
|
|
||||||
element.tabs( "option", "active", 10 );
|
element.tabs( "option", "active", 10 );
|
||||||
equal( element.tabs( "option", "active" ), 1 );
|
equal( element.tabs( "option", "active" ), 1 );
|
||||||
tabs_state( element, 0, 1, 0 );
|
state( element, 0, 1, 0 );
|
||||||
});
|
});
|
||||||
|
|
||||||
if ( $.uiBackCompat === false ) {
|
if ( $.uiBackCompat === false ) {
|
||||||
@ -69,19 +72,19 @@ if ( $.uiBackCompat === false ) {
|
|||||||
active: -1
|
active: -1
|
||||||
});
|
});
|
||||||
equal( element.tabs( "option", "active" ), 2 );
|
equal( element.tabs( "option", "active" ), 2 );
|
||||||
tabs_state( element, 0, 0, 1 );
|
state( element, 0, 0, 1 );
|
||||||
|
|
||||||
element.tabs( "option", "active", -2 );
|
element.tabs( "option", "active", -2 );
|
||||||
equal( element.tabs( "option", "active" ), 1 );
|
equal( element.tabs( "option", "active" ), 1 );
|
||||||
tabs_state( element, 0, 1, 0 );
|
state( element, 0, 1, 0 );
|
||||||
|
|
||||||
element.tabs( "option", "active", -10 );
|
element.tabs( "option", "active", -10 );
|
||||||
equal( element.tabs( "option", "active" ), 1 );
|
equal( element.tabs( "option", "active" ), 1 );
|
||||||
tabs_state( element, 0, 1, 0 );
|
state( element, 0, 1, 0 );
|
||||||
|
|
||||||
element.tabs( "option", "active", -3 );
|
element.tabs( "option", "active", -3 );
|
||||||
equal( element.tabs( "option", "active" ), 0 );
|
equal( element.tabs( "option", "active" ), 0 );
|
||||||
tabs_state( element, 1, 0, 0 );
|
state( element, 1, 0, 0 );
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,9 +94,9 @@ test( "active - mismatched tab/panel order", function() {
|
|||||||
location.hash = "#tabs7-2";
|
location.hash = "#tabs7-2";
|
||||||
var element = $( "#tabs7" ).tabs();
|
var element = $( "#tabs7" ).tabs();
|
||||||
equal( element.tabs( "option", "active" ), 1, "should be 1 based on URL" );
|
equal( element.tabs( "option", "active" ), 1, "should be 1 based on URL" );
|
||||||
tabs_state( element, 0, 1 );
|
state( element, 0, 1 );
|
||||||
element.tabs( "option", "active", 0 );
|
element.tabs( "option", "active", 0 );
|
||||||
tabs_state( element, 1, 0 );
|
state( element, 1, 0 );
|
||||||
location.hash = "#";
|
location.hash = "#";
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -105,11 +108,11 @@ test( "{ collapsible: false }", function() {
|
|||||||
});
|
});
|
||||||
element.tabs( "option", "active", false );
|
element.tabs( "option", "active", false );
|
||||||
equal( element.tabs( "option", "active" ), 1 );
|
equal( element.tabs( "option", "active" ), 1 );
|
||||||
tabs_state( element, 0, 1, 0 );
|
state( element, 0, 1, 0 );
|
||||||
|
|
||||||
element.find( ".ui-state-active a" ).eq( 1 ).click();
|
element.find( ".ui-state-active a" ).eq( 1 ).click();
|
||||||
equal( element.tabs( "option", "active" ), 1 );
|
equal( element.tabs( "option", "active" ), 1 );
|
||||||
tabs_state( element, 0, 1, 0 );
|
state( element, 0, 1, 0 );
|
||||||
});
|
});
|
||||||
|
|
||||||
test( "{ collapsible: true }", function() {
|
test( "{ collapsible: true }", function() {
|
||||||
@ -122,15 +125,15 @@ test( "{ collapsible: true }", function() {
|
|||||||
|
|
||||||
element.tabs( "option", "active", false );
|
element.tabs( "option", "active", false );
|
||||||
equal( element.tabs( "option", "active" ), false );
|
equal( element.tabs( "option", "active" ), false );
|
||||||
tabs_state( element, 0, 0, 0 );
|
state( element, 0, 0, 0 );
|
||||||
|
|
||||||
element.tabs( "option", "active", 1 );
|
element.tabs( "option", "active", 1 );
|
||||||
equal( element.tabs( "option", "active" ), 1 );
|
equal( element.tabs( "option", "active" ), 1 );
|
||||||
tabs_state( element, 0, 1, 0 );
|
state( element, 0, 1, 0 );
|
||||||
|
|
||||||
element.find( ".ui-state-active a" ).click();
|
element.find( ".ui-state-active a" ).click();
|
||||||
equal( element.tabs( "option", "active" ), false );
|
equal( element.tabs( "option", "active" ), false );
|
||||||
tabs_state( element, 0, 0, 0 );
|
state( element, 0, 0, 0 );
|
||||||
});
|
});
|
||||||
|
|
||||||
test( "disabled", function() {
|
test( "disabled", function() {
|
||||||
@ -138,23 +141,23 @@ test( "disabled", function() {
|
|||||||
|
|
||||||
// fully enabled by default
|
// fully enabled by default
|
||||||
var element = $( "#tabs1" ).tabs();
|
var element = $( "#tabs1" ).tabs();
|
||||||
tabs_disabled( element, false );
|
disabled( element, false );
|
||||||
|
|
||||||
// disable single tab
|
// disable single tab
|
||||||
element.tabs( "option", "disabled", [ 1 ] );
|
element.tabs( "option", "disabled", [ 1 ] );
|
||||||
tabs_disabled( element, [ 1 ] );
|
disabled( element, [ 1 ] );
|
||||||
|
|
||||||
// disabled active tab
|
// disabled active tab
|
||||||
element.tabs( "option", "disabled", [ 0, 1 ] );
|
element.tabs( "option", "disabled", [ 0, 1 ] );
|
||||||
tabs_disabled( element, [ 0, 1 ] );
|
disabled( element, [ 0, 1 ] );
|
||||||
|
|
||||||
// disable all tabs
|
// disable all tabs
|
||||||
element.tabs( "option", "disabled", [ 0, 1, 2 ] );
|
element.tabs( "option", "disabled", [ 0, 1, 2 ] );
|
||||||
tabs_disabled( element, true );
|
disabled( element, true );
|
||||||
|
|
||||||
// enable all tabs
|
// enable all tabs
|
||||||
element.tabs( "option", "disabled", [] );
|
element.tabs( "option", "disabled", [] );
|
||||||
tabs_disabled( element, false );
|
disabled( element, false );
|
||||||
});
|
});
|
||||||
|
|
||||||
test( "{ event: null }", function() {
|
test( "{ event: null }", function() {
|
||||||
@ -163,16 +166,16 @@ test( "{ event: null }", function() {
|
|||||||
var element = $( "#tabs1" ).tabs({
|
var element = $( "#tabs1" ).tabs({
|
||||||
event: null
|
event: null
|
||||||
});
|
});
|
||||||
tabs_state( element, 1, 0, 0 );
|
state( element, 1, 0, 0 );
|
||||||
|
|
||||||
element.tabs( "option", "active", 1 );
|
element.tabs( "option", "active", 1 );
|
||||||
equal( element.tabs( "option", "active" ), 1 );
|
equal( element.tabs( "option", "active" ), 1 );
|
||||||
tabs_state( element, 0, 1, 0 );
|
state( element, 0, 1, 0 );
|
||||||
|
|
||||||
// ensure default click handler isn't bound
|
// ensure default click handler isn't bound
|
||||||
element.find( ".ui-tabs-nav a" ).eq( 2 ).click();
|
element.find( ".ui-tabs-nav a" ).eq( 2 ).click();
|
||||||
equal( element.tabs( "option", "active" ), 1 );
|
equal( element.tabs( "option", "active" ), 1 );
|
||||||
tabs_state( element, 0, 1, 0 );
|
state( element, 0, 1, 0 );
|
||||||
});
|
});
|
||||||
|
|
||||||
test( "{ event: custom }", function() {
|
test( "{ event: custom }", function() {
|
||||||
@ -181,31 +184,31 @@ test( "{ event: custom }", function() {
|
|||||||
var element = $( "#tabs1" ).tabs({
|
var element = $( "#tabs1" ).tabs({
|
||||||
event: "custom1 custom2"
|
event: "custom1 custom2"
|
||||||
});
|
});
|
||||||
tabs_state( element, 1, 0, 0 );
|
state( element, 1, 0, 0 );
|
||||||
|
|
||||||
element.find( ".ui-tabs-nav a" ).eq( 1 ).trigger( "custom1" );
|
element.find( ".ui-tabs-nav a" ).eq( 1 ).trigger( "custom1" );
|
||||||
equal( element.tabs( "option", "active" ), 1 );
|
equal( element.tabs( "option", "active" ), 1 );
|
||||||
tabs_state( element, 0, 1, 0 );
|
state( element, 0, 1, 0 );
|
||||||
|
|
||||||
// ensure default click handler isn't bound
|
// ensure default click handler isn't bound
|
||||||
element.find( ".ui-tabs-nav a" ).eq( 2 ).trigger( "click" );
|
element.find( ".ui-tabs-nav a" ).eq( 2 ).trigger( "click" );
|
||||||
equal( element.tabs( "option", "active" ), 1 );
|
equal( element.tabs( "option", "active" ), 1 );
|
||||||
tabs_state( element, 0, 1, 0 );
|
state( element, 0, 1, 0 );
|
||||||
|
|
||||||
element.find( ".ui-tabs-nav a" ).eq( 2 ).trigger( "custom2" );
|
element.find( ".ui-tabs-nav a" ).eq( 2 ).trigger( "custom2" );
|
||||||
equal( element.tabs( "option", "active" ), 2 );
|
equal( element.tabs( "option", "active" ), 2 );
|
||||||
tabs_state( element, 0, 0, 1 );
|
state( element, 0, 0, 1 );
|
||||||
|
|
||||||
element.tabs( "option", "event", "custom3" );
|
element.tabs( "option", "event", "custom3" );
|
||||||
|
|
||||||
// ensure old event handlers are unbound
|
// ensure old event handlers are unbound
|
||||||
element.find( ".ui-tabs-nav a" ).eq( 1 ).trigger( "custom1" );
|
element.find( ".ui-tabs-nav a" ).eq( 1 ).trigger( "custom1" );
|
||||||
equal( element.tabs( "option", "active" ), 2 );
|
equal( element.tabs( "option", "active" ), 2 );
|
||||||
tabs_state( element, 0, 0, 1 );
|
state( element, 0, 0, 1 );
|
||||||
|
|
||||||
element.find( ".ui-tabs-nav a" ).eq( 1 ).trigger( "custom3" );
|
element.find( ".ui-tabs-nav a" ).eq( 1 ).trigger( "custom3" );
|
||||||
equal( element.tabs( "option", "active" ), 1 );
|
equal( element.tabs( "option", "active" ), 1 );
|
||||||
tabs_state( element, 0, 1, 0 );
|
state( element, 0, 1, 0 );
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: add animation tests
|
// TODO: add animation tests
|
||||||
|
61
tests/unit/tabs/tabs_test_helpers.js
Normal file
61
tests/unit/tabs/tabs_test_helpers.js
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
TestHelpers.tabs = {
|
||||||
|
disabled: function( tabs, state ) {
|
||||||
|
var expected, actual,
|
||||||
|
internalState = tabs.tabs( "option", "disabled" );
|
||||||
|
|
||||||
|
if ( internalState === false ) {
|
||||||
|
internalState = [];
|
||||||
|
}
|
||||||
|
if ( internalState === true ) {
|
||||||
|
internalState = $.map( new Array( tabs.find( ".ui-tabs-nav li" ).length ), function( _, index ) {
|
||||||
|
return index;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
expected = $.map( new Array( tabs.find ( ".ui-tabs-nav li" ).length ), function( _, index ) {
|
||||||
|
if ( typeof state === "boolean" ) {
|
||||||
|
return state ? 1 : 0;
|
||||||
|
} else {
|
||||||
|
return $.inArray( index, state ) !== -1 ? 1 : 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
actual = tabs.find( ".ui-tabs-nav li" ).map(function( index ) {
|
||||||
|
var tab = $( this ),
|
||||||
|
tabIsDisabled = tab.hasClass( "ui-state-disabled" );
|
||||||
|
|
||||||
|
if ( tabIsDisabled && $.inArray( index, internalState ) !== -1 ) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if ( !tabIsDisabled && $.inArray( index, internalState ) === -1 ) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// mixed state - invalid
|
||||||
|
return -1;
|
||||||
|
}).get();
|
||||||
|
|
||||||
|
deepEqual( tabs.tabs( "option", "disabled" ), state );
|
||||||
|
deepEqual( actual, expected );
|
||||||
|
},
|
||||||
|
|
||||||
|
state: function( tabs ) {
|
||||||
|
var expected = $.makeArray( arguments ).slice( 1 ),
|
||||||
|
actual = tabs.find( ".ui-tabs-nav li" ).map(function() {
|
||||||
|
var tab = $( this ),
|
||||||
|
panel = $( $.ui.tabs.prototype._sanitizeSelector(
|
||||||
|
"#" + tab.find( "a" ).attr( "aria-controls" ) ) ),
|
||||||
|
tabIsActive = tab.hasClass( "ui-state-active" ),
|
||||||
|
panelIsActive = panel.css( "display" ) !== "none";
|
||||||
|
|
||||||
|
if ( tabIsActive && panelIsActive ) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if ( !tabIsActive && !panelIsActive ) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return -1; // mixed state - invalid
|
||||||
|
}).get();
|
||||||
|
deepEqual( actual, expected );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user