start: true,
strictEqual: true,
stop: true,
- tabs_state: true,
- tabs_disabled: true,
test: true,
TestHelpers: true,
widthAfter: true
<script src="../../jquery.simulate.js"></script>
<script src="../testsuite.js"></script>
+ <script src="tabs_test_helpers.js"></script>
<script src="tabs_defaults.js"></script>
<script src="tabs_core.js"></script>
<script src="tabs_events.js"></script>
<script src="tabs_methods.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>
</head>
<body>
(function( $ ) {
+var state = TestHelpers.tabs.state;
+
module( "tabs: core" );
test( "markup structure", function() {
});
equal( element.find( ".ui-tabs-nav a" ).attr( "aria-controls" ), "tab", "aria-contorls attribute is correct" );
- tabs_state( element, 1 );
+ state( element, 1 );
});
}( jQuery ) );
<script src="../../jquery.simulate.js"></script>
<script src="../testsuite.js"></script>
+ <script src="tabs_test_helpers.js"></script>
<script src="tabs_defaults_deprecated.js"></script>
<script src="tabs_core.js"></script>
<script src="tabs_events.js"></script>
<script src="tabs_options.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>
</head>
<body>
(function( $ ) {
+var state = TestHelpers.tabs.state;
+
module( "tabs (deprecated): core" );
test( "panel ids", function() {
cache: true
});
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 ) {
ok( true, "tabsload" );
setTimeout(function() {
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 ) {
- tabs_state( element, 0, 0, 1, 0, 0 );
+ state( element, 0, 0, 1, 0, 0 );
});
element.one( "tabsload", function( event, ui ) {
ok( false, "should be cached" );
}, 1 );
});
element.tabs( "option", "active", 2 );
- tabs_state( element, 0, 0, 1, 0, 0 );
+ state( element, 0, 0, 1, 0, 0 );
});
test( "idPrefix", function() {
var element = $( "#tabs1" ).tabs();
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" );
location.hash = "#fragment-3";
element = $( "#tabs1" ).tabs();
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" );
el = $('#tabs1').tabs({
selected: -1,
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" );
strictEqual( element.tabs( "option", "selected" ), -1 );
element.tabs( "option", "collapsible", false );
- tabs_state( element, 1, 0, 0 );
+ state( element, 1, 0, 0 );
equal( element.tabs( "option", "selected" ), 0 );
element.tabs( "destroy" );
element.tabs({
selected: -1
});
- tabs_state( element, 1, 0, 0 );
+ state( element, 1, 0, 0 );
strictEqual( element.tabs( "option", "selected" ), 0 );
element.tabs( "destroy" );
element.tabs({ selected: 2 });
equal( element.tabs( "option", "selected" ), 2 );
- tabs_state( element, 0, 0, 1 );
+ state( element, 0, 0, 1 );
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();
equal( element.tabs( "option", "selected" ), 1 );
- tabs_state( element, 0, 1, 0 );
+ state( element, 0, 1, 0 );
element.tabs( "option", "selected", 10 );
equal( element.tabs( "option", "selected" ), 1 );
- tabs_state( element, 0, 1, 0 );
+ state( element, 0, 1, 0 );
location.hash = "#";
});
strictEqual( ui.tab, tab[ 0 ], "tab" );
strictEqual( ui.panel, panel[ 0 ], "panel" );
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();
});
element.tabs({ active: 2 });
strictEqual( ui.tab, tab[ 0 ], "tab" );
strictEqual( ui.panel, panel[ 0 ], "panel" );
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();
});
element.tabs( "option", "active", 3 );
strictEqual( ui.tab, tab[ 0 ], "tab" );
strictEqual( ui.panel, panel[ 0 ], "panel" );
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();
});
element.find( ".ui-tabs-nav a" ).eq( 4 ).click();
strictEqual( ui.tab, tabs[ 0 ], "ui.tab" );
strictEqual( ui.panel, panels[ 0 ], "ui.panel" );
equal( ui.index, 0, "ui.index" );
- tabs_state( element, 1, 0, 0 );
+ state( element, 1, 0, 0 );
});
element.tabs( "option", "active", 0 );
- tabs_state( element, 1, 0, 0 );
+ state( element, 1, 0, 0 );
// switching tabs
element.one( "tabsshow", function( event, ui ) {
strictEqual( ui.tab, tabs[ 1 ], "ui.tab" );
strictEqual( ui.panel, panels[ 1 ], "ui.panel" );
equal( ui.index, 1, "ui.index" );
- tabs_state( element, 0, 1, 0 );
+ state( element, 0, 1, 0 );
});
tabs.eq( 1 ).click();
- tabs_state( element, 0, 1, 0 );
+ state( element, 0, 1, 0 );
// collapsing
element.one( "tabsshow", function( event, ui ) {
ok( false, "collapsing" );
});
element.tabs( "option", "active", false );
- tabs_state( element, 0, 0, 0 );
+ state( element, 0, 0, 0 );
});
test( "select", function() {
strictEqual( ui.tab, tabs[ 0 ], "ui.tab" );
strictEqual( ui.panel, panels[ 0 ], "ui.panel" );
equal( ui.index, 0, "ui.index" );
- tabs_state( element, 0, 0, 0 );
+ state( element, 0, 0, 0 );
});
element.tabs( "option", "active", 0 );
- tabs_state( element, 1, 0, 0 );
+ state( element, 1, 0, 0 );
// switching tabs
element.one( "tabsselect", function( event, ui ) {
strictEqual( ui.tab, tabs[ 1 ], "ui.tab" );
strictEqual( ui.panel, panels[ 1 ], "ui.panel" );
equal( ui.index, 1, "ui.index" );
- tabs_state( element, 1, 0, 0 );
+ state( element, 1, 0, 0 );
});
tabs.eq( 1 ).click();
- tabs_state( element, 0, 1, 0 );
+ state( element, 0, 1, 0 );
// collapsing
element.one( "tabsselect", function( event, ui ) {
ok( false, "collapsing" );
});
element.tabs( "option", "active", false );
- tabs_state( element, 0, 0, 0 );
+ state( element, 0, 0, 0 );
});
module( "tabs (deprecated): methods" );
var tab, anchor,
element = $( "#tabs1" ).tabs();
- tabs_state( element, 1, 0, 0 );
+ state( element, 1, 0, 0 );
// add without index
element.one( "tabsadd", function( event, ui ) {
equal( ui.panel.id, "new", "ui.panel" );
});
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();
anchor = tab.find( "a" );
equal( tab.text(), "New", "label" );
anchor.simulate( "mouseover" );
ok( tab.hasClass( "ui-state-hover" ), "hovered" );
anchor.simulate( "click" );
- tabs_state( element, 0, 0, 0, 1 );
+ state( element, 0, 0, 0, 1 );
// add remote tab with index
element.one( "tabsadd", function( event, ui ) {
equal( ui.panel.id, $( ui.tab ).attr( "aria-controls" ), "ui.panel" );
});
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 );
anchor = tab.find( "a" );
equal( tab.text(), "New Remote", "label" );
anchor.simulate( "mouseover" );
ok( tab.hasClass( "ui-state-hover" ), "hovered" );
anchor.simulate( "click" );
- tabs_state( element, 0, 1, 0, 0, 0 );
+ state( element, 0, 1, 0, 0, 0 );
// add to empty tab set
element = $( "<div><ul></ul></div>" ).tabs();
equal( ui.panel.id, "first", "ui.panel" );
});
element.tabs( "add", "#first", "First" );
- tabs_state( element, 1 );
+ state( element, 1 );
equal( element.tabs( "option", "active" ), 0, "active: 0 after add" );
});
expect( 17 );
var element = $( "#tabs1" ).tabs({ active: 1 });
- tabs_state( element, 0, 1, 0 );
+ state( element, 0, 1, 0 );
element.one( "tabsremove", function( event, ui ) {
equal( ui.index, -1, "ui.index" );
equal( ui.panel.id, "fragment-2", "ui.panel" );
});
element.tabs( "remove", 1 );
- tabs_state( element, 0, 1 );
+ state( element, 0, 1 );
equal( element.tabs( "option", "active" ), 1 );
equal( element.find( ".ui-tabs-nav li a[href$='fragment-2']" ).length, 0,
"remove correct list item" );
equal( ui.panel.id, "fragment-3", "ui.panel" );
});
element.tabs( "remove", 1 );
- tabs_state( element, 1 );
+ state( element, 1 );
equal( element.tabs( "option", "active"), 0 );
element.one( "tabsremove", function( event, ui ) {
expect( 23 );
var element = $( "#tabs1" ).tabs();
- tabs_state( element, 1, 0, 0 );
+ state( element, 1, 0, 0 );
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", "selected" ), 1, "selected" );
element.tabs( "destroy" );
element.tabs({ collapsible: true });
- tabs_state( element, 1, 0, 0 );
+ state( element, 1, 0, 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", "selected" ), -1, "selected" );
element.tabs( "destroy" );
element.tabs({ collapsible: true });
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", "selected" ), -1, "selected" );
element.tabs( "destroy" );
element.tabs();
- tabs_state( element, 1, 0, 0 );
+ state( element, 1, 0, 0 );
equal( element.tabs( "option", "active" ), 0, "active" );
equal( element.tabs( "option", "selected" ), 0, "selected" );
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", "selected" ), 0, "selected" );
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", "selected" ), 0, "selected" );
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", "selected" ), 1, "selected" );
});
(function( $ ) {
+var state = TestHelpers.tabs.state;
+
module( "tabs: events" );
test( "create", function() {
strictEqual( ui.newTab[ 0 ], tabs[ 0 ], "newTab" );
equal( ui.newPanel.size(), 1, "newPanel size" );
strictEqual( ui.newPanel[ 0 ], panels[ 0 ], "newPanel" );
- tabs_state( element, 0, 0, 0 );
+ state( element, 0, 0, 0 );
});
element.tabs( "option", "active", 0 );
- tabs_state( element, 1, 0, 0 );
+ state( element, 1, 0, 0 );
// switching tabs
element.one( "tabsbeforeactivate", function( event, ui ) {
strictEqual( ui.newTab[ 0 ], tabs[ 1 ], "newTab" );
equal( ui.newPanel.size(), 1, "newPanel size" );
strictEqual( ui.newPanel[ 0 ], panels[ 1 ], "newPanel" );
- tabs_state( element, 1, 0, 0 );
+ state( element, 1, 0, 0 );
});
tabs.eq( 1 ).click();
- tabs_state( element, 0, 1, 0 );
+ state( element, 0, 1, 0 );
// collapsing
element.one( "tabsbeforeactivate", function( event, ui ) {
strictEqual( ui.oldPanel[ 0 ], panels[ 1 ], "oldPanel" );
equal( ui.newTab.size(), 0, "newTab size" );
equal( ui.newPanel.size(), 0, "newPanel size" );
- tabs_state( element, 0, 1, 0 );
+ state( element, 0, 1, 0 );
});
element.tabs( "option", "active", false );
- tabs_state( element, 0, 0, 0 );
+ state( element, 0, 0, 0 );
// prevent activation
element.one( "tabsbeforeactivate", function( event, ui ) {
equal( ui.newPanel.size(), 1, "newPanel size" );
strictEqual( ui.newPanel[ 0 ], panels[ 1 ], "newPanel" );
event.preventDefault();
- tabs_state( element, 0, 0, 0 );
+ state( element, 0, 0, 0 );
});
element.tabs( "option", "active", 1 );
- tabs_state( element, 0, 0, 0 );
+ state( element, 0, 0, 0 );
});
test( "activate", function() {
strictEqual( ui.newTab[ 0 ], tabs[ 0 ], "newTab" );
equal( ui.newPanel.size(), 1, "newPanel size" );
strictEqual( ui.newPanel[ 0 ], panels[ 0 ], "newPanel" );
- tabs_state( element, 1, 0, 0 );
+ state( element, 1, 0, 0 );
});
element.tabs( "option", "active", 0 );
- tabs_state( element, 1, 0, 0 );
+ state( element, 1, 0, 0 );
// switching tabs
element.one( "tabsactivate", function( event, ui ) {
strictEqual( ui.newTab[ 0 ], tabs[ 1 ], "newTab" );
equal( ui.newPanel.size(), 1, "newPanel size" );
strictEqual( ui.newPanel[ 0 ], panels[ 1 ], "newPanel" );
- tabs_state( element, 0, 1, 0 );
+ state( element, 0, 1, 0 );
});
tabs.eq( 1 ).click();
- tabs_state( element, 0, 1, 0 );
+ state( element, 0, 1, 0 );
// collapsing
element.one( "tabsactivate", function( event, ui ) {
strictEqual( ui.oldPanel[ 0 ], panels[ 1 ], "oldPanel" );
equal( ui.newTab.size(), 0, "newTab size" );
equal( ui.newPanel.size(), 0, "newPanel size" );
- tabs_state( element, 0, 0, 0 );
+ state( element, 0, 0, 0 );
});
element.tabs( "option", "active", false );
- tabs_state( element, 0, 0, 0 );
+ state( element, 0, 0, 0 );
// prevent activation
element.one( "tabsbeforeactivate", function( event ) {
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
equal( ui.panel.html(), "", "panel html" );
event.preventDefault();
- tabs_state( element, 0, 0, 1, 0, 0 );
+ state( element, 0, 0, 1, 0, 0 );
});
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" );
element.tabs( "destroy" );
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
equal( ui.panel.html(), "", "panel html" );
event.preventDefault();
- tabs_state( element, 1, 0, 0, 0, 0 );
+ state( element, 1, 0, 0, 0, 0 );
});
element.tabs();
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" );
// click, change panel content
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
ui.panel.html( "<p>testing</p>" );
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();
- 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
equal( panel.html().toLowerCase(), "<p>testing</p>", "panel html after" );
});
equal( ui.panel.size(), 1, "panel size" );
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
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();
});
element.tabs({ active: 2 });
equal( ui.panel.size(), 1, "panel size" );
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
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();
});
element.tabs( "option", "active", 3 );
equal( ui.panel.size(), 1, "panel size" );
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
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();
});
element.find( ".ui-tabs-nav a" ).eq( 4 ).click();
(function( $ ) {
+var disabled = TestHelpers.tabs.disabled,
+ state = TestHelpers.tabs.state;
+
module( "tabs: methods" );
test( "destroy", function() {
expect( 8 );
var element = $( "#tabs1" ).tabs({ disabled: true });
- tabs_disabled( element, true );
+ disabled( element, true );
element.tabs( "enable" );
- tabs_disabled( element, false );
+ disabled( element, false );
element.tabs( "destroy" );
element.tabs({ disabled: [ 0, 1 ] });
- tabs_disabled( element, [ 0, 1 ] );
+ disabled( element, [ 0, 1 ] );
element.tabs( "enable" );
- tabs_disabled( element, false );
+ disabled( element, false );
});
test( "enable( index )", function() {
expect( 10 );
var element = $( "#tabs1" ).tabs({ disabled: true });
- tabs_disabled( element, true );
+ disabled( element, true );
// fully disabled -> partially disabled
element.tabs( "enable", 1 );
- tabs_disabled( element, [ 0, 2 ] );
+ disabled( element, [ 0, 2 ] );
// partially disabled -> partially disabled
element.tabs( "enable", 2 );
- tabs_disabled( element, [ 0 ] );
+ disabled( element, [ 0 ] );
// already enabled tab, no change
element.tabs( "enable", 2 );
- tabs_disabled( element, [ 0 ] );
+ disabled( element, [ 0 ] );
// partially disabled -> fully enabled
element.tabs( "enable", 0 );
- tabs_disabled( element, false );
+ disabled( element, false );
});
test( "disable", function() {
expect( 8 );
var element = $( "#tabs1" ).tabs({ disabled: false });
- tabs_disabled( element, false );
+ disabled( element, false );
element.tabs( "disable" );
- tabs_disabled( element, true );
+ disabled( element, true );
element.tabs( "destroy" );
element.tabs({ disabled: [ 0, 1 ] });
- tabs_disabled( element, [ 0, 1 ] );
+ disabled( element, [ 0, 1 ] );
element.tabs( "disable" );
- tabs_disabled( element, true );
+ disabled( element, true );
});
test( "disable( index )", function() {
expect( 10 );
var element = $( "#tabs1" ).tabs({ disabled: false });
- tabs_disabled( element, false );
+ disabled( element, false );
// fully enabled -> partially disabled
element.tabs( "disable", 1 );
- tabs_disabled( element, [ 1 ] );
+ disabled( element, [ 1 ] );
// partially disabled -> partially disabled
element.tabs( "disable", 2 );
- tabs_disabled( element, [ 1, 2 ] );
+ disabled( element, [ 1, 2 ] );
// already disabled tab, no change
element.tabs( "disable", 2 );
- tabs_disabled( element, [ 1, 2 ] );
+ disabled( element, [ 1, 2 ] );
// partially disabled -> fully disabled
element.tabs( "disable", 0 );
- tabs_disabled( element, true );
+ disabled( element, true );
});
test( "refresh", function() {
expect( 27 );
var element = $( "#tabs1" ).tabs();
- tabs_state( element, 1, 0, 0 );
- tabs_disabled( element, false );
+ state( element, 1, 0, 0 );
+ disabled( element, false );
// disable tab via markup
element.find( ".ui-tabs-nav li" ).eq( 1 ).addClass( "ui-state-disabled" );
element.tabs( "refresh" );
- tabs_state( element, 1, 0, 0 );
- tabs_disabled( element, [ 1 ] );
+ state( element, 1, 0, 0 );
+ disabled( element, [ 1 ] );
// add remote tab
element.find( ".ui-tabs-nav" ).append( "<li id='newTab'><a href='data/test.html'>new</a></li>" );
element.tabs( "refresh" );
- tabs_state( element, 1, 0, 0, 0 );
- tabs_disabled( element, [ 1 ] );
+ state( element, 1, 0, 0, 0 );
+ disabled( element, [ 1 ] );
equal( element.find( "#" + $( "#newTab a" ).attr( "aria-controls" ) ).length, 1,
"panel added for remote tab" );
// remove all tabs
element.find( ".ui-tabs-nav li, .ui-tabs-panel" ).remove();
element.tabs( "refresh" );
- tabs_state( element );
+ state( element );
equal( element.tabs( "option", "active" ), false, "no active tab" );
// add tabs
.append( "<div id='newTab4'>new 4</div>" )
.append( "<div id='newTab5'>new 5</div>" );
element.tabs( "refresh" );
- tabs_state( element, 0, 0, 0, 0 );
- tabs_disabled( element, [ 0 ] );
+ state( element, 0, 0, 0, 0 );
+ disabled( element, [ 0 ] );
// activate third tab
element.tabs( "option", "active", 2 );
- tabs_state( element, 0, 0, 1, 0 );
- tabs_disabled( element, [ 0 ] );
+ state( element, 0, 0, 1, 0 );
+ disabled( element, [ 0 ] );
// remove fourth tab, third tab should stay active
element.find( ".ui-tabs-nav li" ).eq( 3 ).remove();
element.find( ".ui-tabs-panel" ).eq( 3 ).remove();
element.tabs( "refresh" );
- tabs_state( element, 0, 0, 1 );
- tabs_disabled( element, [ 0 ] );
+ state( element, 0, 0, 1 );
+ disabled( element, [ 0 ] );
// remove third (active) tab, second tab should become active
element.find( ".ui-tabs-nav li" ).eq( 2 ).remove();
element.find( ".ui-tabs-panel" ).eq( 2 ).remove();
element.tabs( "refresh" );
- tabs_state( element, 0, 1 );
- tabs_disabled( element, [ 0 ] );
+ state( element, 0, 1 );
+ disabled( element, [ 0 ] );
// remove first tab, previously active tab (now first) should stay active
element.find( ".ui-tabs-nav li" ).eq( 0 ).remove();
element.find( ".ui-tabs-panel" ).eq( 0 ).remove();
element.tabs( "refresh" );
- tabs_state( element, 1 );
- tabs_disabled( element, false );
+ state( element, 1 );
+ disabled( element, false );
});
asyncTest( "load", function() {
strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
equal( ui.panel.size(), 1, "panel size" );
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 ) {
// TODO: remove wrapping in 2.0
equal( uiPanel.size(), 1, "panel size" );
strictEqual( uiPanel[ 0 ], panel[ 0 ], "panel" );
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 );
});
element.tabs( "load", 3 );
- tabs_state( element, 1, 0, 0, 0, 0 );
+ state( element, 1, 0, 0, 0, 0 );
function tabsload1() {
// no need to test details of event (tested in events tests)
setTimeout( tabsload2, 100 );
});
element.tabs( "option", "active", 3 );
- tabs_state( element, 0, 0, 0, 1, 0 );
+ state( element, 0, 0, 0, 1, 0 );
}
function tabsload2() {
strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
equal( ui.panel.size(), 1, "panel size" );
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 ) {
// TODO: remove wrapping in 2.0
strictEqual( uiTab[ 0 ], tab[ 0 ], "tab" );
equal( uiPanel.size(), 1, "panel size" );
strictEqual( uiPanel[ 0 ], panel[ 0 ], "panel" );
- tabs_state( element, 0, 0, 0, 1, 0 );
+ state( element, 0, 0, 0, 1, 0 );
start();
});
element.tabs( "load", 3 );
- tabs_state( element, 0, 0, 0, 1, 0 );
+ state( element, 0, 0, 0, 1, 0 );
}
});
(function( $ ) {
+var disabled = TestHelpers.tabs.disabled,
+ state = TestHelpers.tabs.state;
+
module( "tabs: options" );
test( "{ active: default }", function() {
var element = $( "#tabs1" ).tabs();
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" );
location.hash = "#fragment-3";
element = $( "#tabs1" ).tabs();
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" );
location.hash = "#";
});
active: false,
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" );
strictEqual( element.tabs( "option", "active" ), false );
element.tabs( "option", "collapsible", false );
- tabs_state( element, 1, 0, 0 );
+ state( element, 1, 0, 0 );
equal( element.tabs( "option", "active" ), 0 );
element.tabs( "destroy" );
element.tabs({
active: false
});
- tabs_state( element, 1, 0, 0 );
+ state( element, 1, 0, 0 );
strictEqual( element.tabs( "option", "active" ), 0 );
});
active: 2
});
equal( element.tabs( "option", "active" ), 2 );
- tabs_state( element, 0, 0, 1 );
+ state( element, 0, 0, 1 );
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();
equal( element.tabs( "option", "active" ), 1 );
- tabs_state( element, 0, 1, 0 );
+ state( element, 0, 1, 0 );
element.tabs( "option", "active", 10 );
equal( element.tabs( "option", "active" ), 1 );
- tabs_state( element, 0, 1, 0 );
+ state( element, 0, 1, 0 );
});
if ( $.uiBackCompat === false ) {
active: -1
});
equal( element.tabs( "option", "active" ), 2 );
- tabs_state( element, 0, 0, 1 );
+ state( element, 0, 0, 1 );
element.tabs( "option", "active", -2 );
equal( element.tabs( "option", "active" ), 1 );
- tabs_state( element, 0, 1, 0 );
+ state( element, 0, 1, 0 );
element.tabs( "option", "active", -10 );
equal( element.tabs( "option", "active" ), 1 );
- tabs_state( element, 0, 1, 0 );
+ state( element, 0, 1, 0 );
element.tabs( "option", "active", -3 );
equal( element.tabs( "option", "active" ), 0 );
- tabs_state( element, 1, 0, 0 );
+ state( element, 1, 0, 0 );
});
}
location.hash = "#tabs7-2";
var element = $( "#tabs7" ).tabs();
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 );
- tabs_state( element, 1, 0 );
+ state( element, 1, 0 );
location.hash = "#";
});
});
element.tabs( "option", "active", false );
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();
equal( element.tabs( "option", "active" ), 1 );
- tabs_state( element, 0, 1, 0 );
+ state( element, 0, 1, 0 );
});
test( "{ collapsible: true }", function() {
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 );
equal( element.tabs( "option", "active" ), 1 );
- tabs_state( element, 0, 1, 0 );
+ state( element, 0, 1, 0 );
element.find( ".ui-state-active a" ).click();
equal( element.tabs( "option", "active" ), false );
- tabs_state( element, 0, 0, 0 );
+ state( element, 0, 0, 0 );
});
test( "disabled", function() {
// fully enabled by default
var element = $( "#tabs1" ).tabs();
- tabs_disabled( element, false );
+ disabled( element, false );
// disable single tab
element.tabs( "option", "disabled", [ 1 ] );
- tabs_disabled( element, [ 1 ] );
+ disabled( element, [ 1 ] );
// disabled active tab
element.tabs( "option", "disabled", [ 0, 1 ] );
- tabs_disabled( element, [ 0, 1 ] );
+ disabled( element, [ 0, 1 ] );
// disable all tabs
element.tabs( "option", "disabled", [ 0, 1, 2 ] );
- tabs_disabled( element, true );
+ disabled( element, true );
// enable all tabs
element.tabs( "option", "disabled", [] );
- tabs_disabled( element, false );
+ disabled( element, false );
});
test( "{ event: null }", function() {
var element = $( "#tabs1" ).tabs({
event: null
});
- tabs_state( element, 1, 0, 0 );
+ state( element, 1, 0, 0 );
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
element.find( ".ui-tabs-nav a" ).eq( 2 ).click();
equal( element.tabs( "option", "active" ), 1 );
- tabs_state( element, 0, 1, 0 );
+ state( element, 0, 1, 0 );
});
test( "{ event: custom }", function() {
var element = $( "#tabs1" ).tabs({
event: "custom1 custom2"
});
- tabs_state( element, 1, 0, 0 );
+ state( element, 1, 0, 0 );
element.find( ".ui-tabs-nav a" ).eq( 1 ).trigger( "custom1" );
equal( element.tabs( "option", "active" ), 1 );
- tabs_state( element, 0, 1, 0 );
+ state( element, 0, 1, 0 );
// ensure default click handler isn't bound
element.find( ".ui-tabs-nav a" ).eq( 2 ).trigger( "click" );
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" );
equal( element.tabs( "option", "active" ), 2 );
- tabs_state( element, 0, 0, 1 );
+ state( element, 0, 0, 1 );
element.tabs( "option", "event", "custom3" );
// ensure old event handlers are unbound
element.find( ".ui-tabs-nav a" ).eq( 1 ).trigger( "custom1" );
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" );
equal( element.tabs( "option", "active" ), 1 );
- tabs_state( element, 0, 1, 0 );
+ state( element, 0, 1, 0 );
});
// TODO: add animation tests
--- /dev/null
+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 );
+ }
+};
+