Skip to content

Commit 33e93ef

Browse files
committed
Tabs tests: Don't pollute the global namespace with helpers.
1 parent c16bd7c commit 33e93ef

File tree

9 files changed

+219
-258
lines changed

9 files changed

+219
-258
lines changed

grunt.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,6 @@ grunt.initConfig({
388388
start: true,
389389
strictEqual: true,
390390
stop: true,
391-
tabs_state: true,
392-
tabs_disabled: true,
393391
test: true,
394392
TestHelpers: true,
395393
widthAfter: true

tests/unit/tabs/tabs.html

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -25,68 +25,13 @@
2525
<script src="../../jquery.simulate.js"></script>
2626
<script src="../testsuite.js"></script>
2727

28+
<script src="tabs_test_helpers.js"></script>
2829
<script src="tabs_defaults.js"></script>
2930
<script src="tabs_core.js"></script>
3031
<script src="tabs_events.js"></script>
3132
<script src="tabs_methods.js"></script>
3233
<script src="tabs_options.js"></script>
3334

34-
<script>
35-
function tabs_state( tabs ) {
36-
var expected = $.makeArray( arguments ).slice( 1 );
37-
var actual = tabs.find( ".ui-tabs-nav li" ).map(function() {
38-
var tab = $( this ),
39-
panel = $( $.ui.tabs.prototype._sanitizeSelector(
40-
"#" + tab.find( "a" ).attr( "aria-controls" ) ) ),
41-
tabIsActive = tab.hasClass( "ui-state-active" ),
42-
panelIsActive = panel.css( "display" ) !== "none";
43-
44-
if ( tabIsActive && panelIsActive ) {
45-
return 1;
46-
}
47-
if ( !tabIsActive && !panelIsActive ) {
48-
return 0;
49-
}
50-
return -1; // mixed state - invalid
51-
}).get();
52-
deepEqual( actual, expected );
53-
}
54-
55-
function tabs_disabled( tabs, state ) {
56-
var expected = $.map( new Array( tabs.find ( ".ui-tabs-nav li" ).length ), function( _, index ) {
57-
if ( typeof state === "boolean" ) {
58-
return state ? 1 : 0;
59-
} else {
60-
return $.inArray( index, state ) !== -1 ? 1 : 0;
61-
}
62-
});
63-
64-
var internalState = tabs.tabs( "option", "disabled" );
65-
if ( internalState === false ) {
66-
internalState = [];
67-
}
68-
if ( internalState === true ) {
69-
internalState = $.map( new Array( tabs.find( ".ui-tabs-nav li" ).length ), function( _, index ) {
70-
return index;
71-
});
72-
}
73-
74-
var actual = tabs.find( ".ui-tabs-nav li" ).map(function( index ) {
75-
var tab = $( this ),
76-
tabIsDisabled = tab.hasClass( "ui-state-disabled" );
77-
78-
if ( tabIsDisabled && $.inArray( index, internalState ) !== -1 ) {
79-
return 1;
80-
}
81-
if ( !tabIsDisabled && $.inArray( index, internalState ) === -1 ) {
82-
return 0;
83-
}
84-
return -1; // mixed state - invalid
85-
}).get();
86-
deepEqual( tabs.tabs( "option", "disabled" ), state );
87-
deepEqual( actual, expected );
88-
}
89-
</script>
9035
<script src="../swarminject.js"></script>
9136
</head>
9237
<body>

tests/unit/tabs/tabs_core.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
(function( $ ) {
22

3+
var state = TestHelpers.tabs.state;
4+
35
module( "tabs: core" );
46

57
test( "markup structure", function() {
@@ -89,7 +91,7 @@ test( "#4033 - IE expands hash to full url and misinterprets tab as ajax", funct
8991
});
9092

9193
equal( element.find( ".ui-tabs-nav a" ).attr( "aria-controls" ), "tab", "aria-contorls attribute is correct" );
92-
tabs_state( element, 1 );
94+
state( element, 1 );
9395
});
9496

9597
}( jQuery ) );

tests/unit/tabs/tabs_deprecated.html

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -23,69 +23,14 @@
2323
<script src="../../jquery.simulate.js"></script>
2424
<script src="../testsuite.js"></script>
2525

26+
<script src="tabs_test_helpers.js"></script>
2627
<script src="tabs_defaults_deprecated.js"></script>
2728
<script src="tabs_core.js"></script>
2829
<script src="tabs_events.js"></script>
2930
<script src="tabs_methods.js"></script>
3031
<script src="tabs_options.js"></script>
3132
<script src="tabs_deprecated.js"></script>
3233

33-
<script>
34-
function tabs_state( tabs ) {
35-
var expected = $.makeArray( arguments ).slice( 1 );
36-
var actual = tabs.find( ".ui-tabs-nav li" ).map(function() {
37-
var tab = $( this ),
38-
panel = $( $.ui.tabs.prototype._sanitizeSelector(
39-
"#" + tab.find( "a" ).attr( "aria-controls" ) ) ),
40-
tabIsActive = tab.hasClass( "ui-state-active" ),
41-
panelIsActive = panel.css( "display" ) !== "none";
42-
43-
if ( tabIsActive && panelIsActive ) {
44-
return 1;
45-
}
46-
if ( !tabIsActive && !panelIsActive ) {
47-
return 0;
48-
}
49-
return -1; // mixed state - invalid
50-
}).get();
51-
deepEqual( actual, expected );
52-
}
53-
54-
function tabs_disabled( tabs, state ) {
55-
var expected = $.map( new Array( tabs.find ( ".ui-tabs-nav li" ).length ), function( _, index ) {
56-
if ( typeof state === "boolean" ) {
57-
return state ? 1 : 0;
58-
} else {
59-
return $.inArray( index, state ) !== -1 ? 1 : 0;
60-
}
61-
});
62-
63-
var internalState = tabs.tabs( "option", "disabled" );
64-
if ( internalState === false ) {
65-
internalState = [];
66-
}
67-
if ( internalState === true ) {
68-
internalState = $.map( new Array( tabs.find( ".ui-tabs-nav li" ).length ), function( _, index ) {
69-
return index;
70-
});
71-
}
72-
73-
var actual = tabs.find( ".ui-tabs-nav li" ).map(function( index ) {
74-
var tab = $( this ),
75-
tabIsDisabled = tab.hasClass( "ui-state-disabled" );
76-
77-
if ( tabIsDisabled && $.inArray( index, internalState ) !== -1 ) {
78-
return 1;
79-
}
80-
if ( !tabIsDisabled && $.inArray( index, internalState ) === -1 ) {
81-
return 0;
82-
}
83-
return -1; // mixed state - invalid
84-
}).get();
85-
deepEqual( tabs.tabs( "option", "disabled" ), state );
86-
deepEqual( actual, expected );
87-
}
88-
</script>
8934
<script src="../swarminject.js"></script>
9035
</head>
9136
<body>

0 commit comments

Comments
 (0)