aboutsummaryrefslogtreecommitdiffstats
path: root/tests/tabs.js
blob: e27bd7def156626befd3701d997e66af386be46c (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/*
 * tabs unit tests
 */
(function($) {

// need to wait a bit for the pseudo animation...
function defer(defered, ms) {
	var queue = defer.queue || (defer.queue = []);
	if (!queue.length) stop();
	queue.push(defered);
	setTimeout(function() {
		queue.shift()();
		if (!queue.length) start();
	}, ms || 100);	
}

module('tabs');

	test('init', function() {
		expect(4);

		var el = $('#tabs1 > ul').tabs();
		ok(true, '.tabs() called on element');
	
		el.tabs('destroy').tabs({ selected: 1 });
		equals( el.data('selected.tabs'), 1, 'selected.tabs set' );
		equals( $('li', el).index( $('li.ui-tabs-selected', el) ), 1, 'second tab active');
		equals( $('div', '#tabs1').index( $('div.ui-tabs-hide', '#tabs1') ), 0, 'first panel should be hidden' );
	
	});

	test('destroy', function() {
		expect(0);
	
	});

	test("defaults", function() {
	
		var expected = {
			deselectable: false,
			event: 'click',
			disabled: [],
			cookie: null,
			spinner: 'Loading…',
			cache: false,
			idPrefix: 'ui-tabs-',
			ajaxOptions: null,
			fx: null,
			tabTemplate: '<li><a href="#{href}"><span>#{label}</span></a></li>',
			panelTemplate: '<div></div>',
			navClass: 'ui-tabs-nav',
			selectedClass: 'ui-tabs-selected',
			deselectableClass: 'ui-tabs-deselectable',
			disabledClass: 'ui-tabs-disabled',
			panelClass: 'ui-tabs-panel',
			hideClass: 'ui-tabs-hide',
			loadingClass: 'ui-tabs-loading'
		};

		var el = $("#tabs1").tabs();

		for (var optionName in expected) {
			var actual = el.data(optionName + '.tabs'), expects = expected[optionName];

			if (optionName == 'disabled')
				compare(actual, expects, optionName);
			else
				equals(actual, expects, optionName);
			
		}
	
	});

	test('add', function() {
		expect(0);
	
	});

	test('remove', function() {
		expect(0);
	
	});

	test('enable', function() {
		expect(0);
	
	});

	test('disable', function() {
		expect(0);
	
	});

	test('select', function() {
		expect(0);
	
	});

	test('load', function() {
		expect(0);
	
	});

	test('url', function() {
		expect(0);
	
	});


module('tabs: Options');

	test('select: null', function() {
		expect(3);
	
		var el = $('#tabs1 > ul');
	
		el.tabs({ selected: null });
		equals( el.data('selected.tabs'), null, 'option set' );
		equals( $('li.ui-tabs-selected', el).length, 0, 'all tabs should be deselected' );
		equals( $('div.ui-tabs-hide', '#tabs1').length, 3, 'all panels should be hidden' );
	
		// TODO select == null with cookie
		// TODO select == null with select method
	
	});

	test('deselectable: true', function() {
		expect(7);
	
		var el = $('#tabs1 > ul');
	
		el.tabs({ deselectable: true });
		equals( el.data('deselectable.tabs'), true, 'option set' );
		equals( $('li.ui-tabs-deselectable', el).length, 1, 'class "ui-tabs-deselectable" attached once');
		equals( $('li', el).index( $('li.ui-tabs-deselectable', el) ), 0, 'class "ui-tabs-deselectable" attached to first tab');
	
		el.tabs('select', 1);
		equals( $('li.ui-tabs-deselectable', el).length, 1, 'class "ui-tabs-deselectable" attached once');
		equals( $('li', el).index( $('li.ui-tabs-deselectable', el) ), 1, 'class "ui-tabs-deselectable" attached to second tab');
	
		el.tabs('select', 1);
		equals( $('li.ui-tabs-deselectable', el).length, 0, 'class "ui-tabs-deselectable" not attached');
		defer(function() {
			equals( $('div.ui-tabs-hide', '#tabs1').length, 3, 'all panels should be hidden' );
		});

	});

	test('cookie', function() {
		expect(5);
	
		var el = $('#tabs1 > ul');
		var cookieName = 'ui-tabs-' + $.data(el[0]);
		$.cookie(cookieName, null); // blank state
		var cookie = function() {
			return parseInt($.cookie(cookieName), 10);
		};
	
		el.tabs({ cookie: {} });
		equals(cookie(), 0, 'initial cookie value, no cookie given');
	
		el.tabs('destroy');
		el.tabs({ selected: 1, cookie: {} });
		equals(cookie(), 1, 'initial cookie value, given selected');

		el.tabs('select', 2);
		equals(cookie(), 2, 'cookie value after tabs select');
	
		el.tabs('destroy');
		$.cookie(cookieName, 1);
		el.tabs({ cookie: {} });
		equals(cookie(), 1, 'initial cookie value, from existing cookie');
	
		el.tabs('destroy');
		ok($.cookie(cookieName) === null, 'erase cookie after destroy');
	
	});


module('tabs: Tickets');

	test('id containing colon, #????', function() {
		expect(4);

		var el = $('#tabs2 > ul').tabs();
		ok( $('div.ui-tabs-panel:eq(0)', '#tabs2').is(':visible'), 'first panel should be visible' );
		ok( $('div.ui-tabs-panel:eq(1)', '#tabs2').is(':hidden'), 'second panel should be hidden' );
	
		el.tabs('select', 1).tabs('select', 0);
		defer(function() {
			ok( $('div.ui-tabs-panel:eq(0)', '#tabs2').is(':visible'), 'first panel should be visible' );
			ok( $('div.ui-tabs-panel:eq(1)', '#tabs2').is(':hidden'), 'second panel should be hidden' );	
		});
	
	});
	
	test('panel containing inline style, #????', function() {
		expect(3);
		
		var inlineStyle = function(property) {
			return $('#inline-style')[0].style[property];
		};
		var expected = inlineStyle('height');
		
		var el = $('#tabs2 > ul').tabs();
		equals(inlineStyle('height'), expected, 'init should not remove inline style');
		
		el.tabs('select', 1);
		defer(function() {
			equals(inlineStyle('height'), expected, 'show tab should not remove inline style');
			
			el.tabs('select', 0);
			defer(function() {
				equals(inlineStyle('height'), expected, 'hide tab should not remove inline style');
			});
			
		});
		
	});
	
// test('', function() {
// 	expect(0);
// 	
// });

})(jQuery);