aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/tabs/tabs_test_helpers.js
blob: 5c9625f8c5fd0f0fc8f2122d3e7608c8fb9b0287 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
define( [
	"jquery",
	"lib/helper",
	"ui/tabs"
], function( $, helper ) {

return $.extend( helper, {
	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 );
	},

	equalHeight: function( tabs, height ) {
		tabs.find( ".ui-tabs-panel" ).each(function() {
			equal( $( this ).outerHeight(), height );
		});
	},

	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.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 );
	}
} );

} );