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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
|
(function( $ ) {
module("tabs (deprecated): core");
test( "panel ids", function() {
expect( 2 );
var element = $( "#tabs2" ).tabs();
element.one( "tabsbeforeload", function( event, ui ) {
equal( ui.panel.attr( "id" ), "∫ßáö_Սե", "from title attribute" );
event.preventDefault();
});
element.tabs( "option", "active", 4 );
element.one( "tabsbeforeload", function( event, ui ) {
ok( /^ui-tabs-\d+$/.test( ui.panel.attr( "id" ) ), "generated id" );
event.preventDefault();
});
element.tabs( "option", "active", 2 );
});
module("tabs (deprecated): options");
test('ajaxOptions', function() {
ok(false, "missing test - untested code is broken code.");
});
test('cache', function() {
ok(false, "missing test - untested code is broken code.");
});
test('idPrefix', function() {
ok(false, "missing test - untested code is broken code.");
});
test('tabTemplate', function() {
ok(false, "missing test - untested code is broken code.");
});
test('panelTemplate', function() {
ok(false, "missing test - untested code is broken code.");
});
test('cookie', function() {
expect(6);
el = $('#tabs1');
var cookieName = 'tabs_test', cookieObj = { name: cookieName };
$.cookie(cookieName, null); // blank state
var cookie = function() {
return parseInt($.cookie(cookieName), 10);
};
el.tabs({ cookie: cookieObj });
equals(cookie(), 0, 'initial cookie value');
el.tabs('destroy');
el.tabs({ active: 1, cookie: cookieObj });
equals(cookie(), 1, 'initial cookie value, from active property');
el.tabs('option', 'active', 2);
equals(cookie(), 2, 'cookie value updated after activating');
el.tabs('destroy');
$.cookie(cookieName, 1);
el.tabs({ cookie: cookieObj });
equals(cookie(), 1, 'initial cookie value, from existing cookie');
el.tabs('destroy');
el.tabs({ cookie: cookieObj, collapsible: true });
el.tabs('option', 'active', false);
equals(cookie(), -1, 'cookie value for all tabs unselected');
el.tabs('destroy');
ok($.cookie(cookieName) === null, 'erase cookie after destroy');
});
test('spinner', function() {
expect(4);
stop();
el = $('#tabs2');
el.tabs({
selected: 2,
load: function() {
// spinner: default spinner
setTimeout(function() {
equals($('li:eq(2) > a > span', el).length, 1, "should restore tab markup after spinner is removed");
equals($('li:eq(2) > a > span', el).html(), '3', "should restore tab label after spinner is removed");
el.tabs('destroy');
el.tabs({
selected: 2,
spinner: '<img src="spinner.gif" alt="">',
load: function() {
// spinner: image
equals($('li:eq(2) > a > span', el).length, 1, "should restore tab markup after spinner is removed");
equals($('li:eq(2) > a > span', el).html(), '3', "should restore tab label after spinner is removed");
start();
}
});
}, 1);
}
});
});
test('selected', function() {
expect(10);
el = $('#tabs1').tabs();
equals(el.tabs('option', 'selected'), 0, 'should be 0 by default');
el.tabs('destroy');
//set a hash in the url
location.hash = '#fragment-2';
//selection of tab with divs ordered differently than list
el = $('#tabs1').tabs();
equals(el.tabs('option', 'selected'), 1, 'second tab should be selected');
el.tabs('destroy');
//set a hash in the url
location.hash = '#tabs7-2';
//selection of tab with divs ordered differently than list
el = $('#tabs7').tabs();
equals(el.tabs('option', 'selected'), 1, 'second tab should be selected');
el.tabs('destroy');
el = $('#tabs1').tabs({ selected: -1 });
equals(el.tabs('option', 'selected'), -1, 'should be -1 for all tabs unselected');
equals( $('li.ui-tabs-active', el).length, 0, 'no tab should be selected' );
equals( $('div:hidden', '#tabs1').length, 3, 'all panels should be hidden' );
el.tabs('destroy');
el.tabs({ selected: 1 });
equals(el.tabs('option', 'selected'), 1, 'should be specified tab');
el.tabs('destroy');
el.tabs({ selected: 99 });
equals(el.tabs('option', 'selected'), 0, 'selected should default to zero if given value is out of index');
el.tabs('destroy');
el.tabs({ collapsible: true });
el.tabs('option', 'selected', 0);
equals(el.tabs('option', 'selected'), 0, 'should not collapse tab if value is same as selected');
el.tabs('destroy');
el = $('#tabs1').tabs();
el.tabs('select', 1);
equals(el.tabs('option', 'selected'), 1, 'should select tab');
});
module( "tabs (deprecated): events" );
test( "enable", function() {
expect( 3 );
var element = $( "#tabs1" ).tabs({
disabled: [ 0, 1 ],
enable: function ( event, ui ) {
equals( ui.tab, element.find( ".ui-tabs-nav a" )[ 1 ], "ui.tab" );
equals( ui.panel, element.find( ".ui-tabs-panel" )[ 1 ], "ui.panel" );
equals( ui.index, 1, "ui.index" );
}
});
element.tabs( "enable", 1 );
// shouldn't trigger event
element.tabs( "enable", 2 );
});
test( "disable", function() {
expect( 3 );
var element = $( "#tabs1" ).tabs({
disable: function ( event, ui ) {
equals( ui.tab, element.find( ".ui-tabs-nav a" )[ 1 ], "ui.tab" );
equals( ui.panel, element.find( ".ui-tabs-panel" )[ 1 ], "ui.panel" );
equals( ui.index, 1, "ui.index" );
}
});
element.tabs( "disable", 1 );
// shouldn't trigger event
element.tabs( "disable", 1 );
});
test('show', function() {
expect(5);
var uiObj, eventObj;
el = $('#tabs1').tabs({
show: function(event, ui) {
uiObj = ui;
eventObj = event;
}
});
ok(uiObj !== undefined, 'trigger callback after initialization');
equals(uiObj.tab, $('a', el)[0], 'contain tab as DOM anchor element');
equals(uiObj.panel, $('div', el)[0], 'contain panel as DOM div element');
equals(uiObj.index, 0, 'contain index');
el.find( "li:eq(1) a" ).simulate( "click" );
equals( eventObj.originalEvent.type, "click", "show triggered by click" );
});
test('select', function() {
expect(7);
var eventObj;
el = $('#tabs1').tabs({
select: function(event, ui) {
ok(true, 'select triggered after initialization');
equals(this, el[0], "context of callback");
equals(event.type, 'tabsselect', 'event type in callback');
equals(ui.tab, el.find('a')[1], 'contain tab as DOM anchor element');
equals(ui.panel, el.find('div')[1], 'contain panel as DOM div element');
equals(ui.index, 1, 'contain index');
evenObj = event;
}
});
el.tabs('select', 1);
el.find( "li:eq(1) a" ).simulate( "click" );
equals( evenObj.originalEvent.type, "click", "select triggered by click" );
});
module( "tabs (deprecated): methods" );
test( "add", function() {
expect( 27 );
var element = $( "#tabs1" ).tabs();
tabs_state( element, 1, 0, 0 );
// add without index
element.one( "tabsadd", function( event, ui ) {
equal( ui.index, 3, "ui.index" );
equal( $( ui.tab ).text(), "New", "ui.tab" );
equal( ui.panel.id, "new", "ui.panel" );
});
element.tabs( "add", "#new", "New" );
tabs_state( element, 1, 0, 0, 0 );
var tab = element.find( ".ui-tabs-nav li" ).last(),
anchor = tab.find( "a" );
equals( tab.text(), "New", "label" );
equals( anchor.attr( "href" ), "#new", "href" );
equals( anchor.attr( "aria-controls" ), "new", "aria-controls" );
ok( !tab.hasClass( "ui-state-hover" ), "not hovered" );
anchor.simulate( "mouseover" );
ok( tab.hasClass( "ui-state-hover" ), "hovered" );
anchor.simulate( "click" );
tabs_state( element, 0, 0, 0, 1 );
// add remote tab with index
element.one( "tabsadd", function( event, ui ) {
equal( ui.index, 1, "ui.index" );
equal( $( ui.tab ).text(), "New Remote", "ui.tab" );
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 );
tab = element.find( ".ui-tabs-nav li" ).eq( 1 );
anchor = tab.find( "a" );
equals( tab.text(), "New Remote", "label" );
equals( anchor.attr( "href" ), "data/test.html", "href" );
ok( /^ui-tabs-\d+$/.test( anchor.attr( "aria-controls" ) ), "aria controls" );
ok( !tab.hasClass( "ui-state-hover" ), "not hovered" );
anchor.simulate( "mouseover" );
ok( tab.hasClass( "ui-state-hover" ), "hovered" );
anchor.simulate( "click" );
tabs_state( element, 0, 1, 0, 0, 0 );
// add to empty tab set
element = $( "<div><ul></ul></div>" ).tabs();
equals( element.tabs( "option", "active" ), false, "active: false on init" );
element.one( "tabsadd", function( event, ui ) {
equal( ui.index, 0, "ui.index" );
equal( $( ui.tab ).text(), "First", "ui.tab" );
equal( ui.panel.id, "first", "ui.panel" );
});
element.tabs( "add", "#first", "First" );
tabs_state( element, 1 );
equals( element.tabs( "option", "active" ), 0, "active: 0 after add" );
});
test( "#5069 - ui.tabs.add creates two tab panels when using a full URL", function() {
expect( 2 );
var element = $( "#tabs2" ).tabs();
equals( element.children( "div" ).length, element.find( ".ui-tabs-nav li" ).length );
element.tabs( "add", "/new", "New" );
equals( element.children( "div" ).length, element.find( ".ui-tabs-nav li" ).length );
});
test( "remove", function() {
expect( 17 );
var element = $( "#tabs1" ).tabs({ active: 1 });
tabs_state( element, 0, 1, 0 );
element.one( "tabsremove", function( event, ui ) {
equal( ui.index, -1, "ui.index" );
equal( $( ui.tab ).text(), "2", "ui.tab" );
equal( ui.panel.id, "fragment-2", "ui.panel" );
});
element.tabs( "remove", 1 );
tabs_state( element, 0, 1 );
equals( element.tabs( "option", "active" ), 1 );
equals( element.find( ".ui-tabs-nav li a[href$='fragment-2']" ).length, 0,
"remove correct list item" );
equals( element.find( "#fragment-2" ).length, 0, "remove correct panel" );
element.one( "tabsremove", function( event, ui ) {
equal( ui.index, -1, "ui.index" );
equal( $( ui.tab ).text(), "3", "ui.tab" );
equal( ui.panel.id, "fragment-3", "ui.panel" );
});
element.tabs( "remove", 1 );
tabs_state( element, 1 );
equals( element.tabs( "option", "active"), 0 );
element.one( "tabsremove", function( event, ui ) {
equal( ui.index, -1, "ui.index" );
equal( $( ui.tab ).text(), "1", "ui.tab" );
equal( ui.panel.id, "fragment-1", "ui.panel" );
});
element.tabs( "remove", 0 );
equals( element.tabs( "option", "active" ), false );
});
test('select', function() {
expect(6);
el = $('#tabs1').tabs();
el.tabs('select', 1);
equals(el.tabs('option', 'active'), 1, 'should select tab');
el.tabs('destroy');
el.tabs({ collapsible: true });
el.tabs('select', 0);
equals(el.tabs('option', 'active'), -1, 'should collapse tab passing in the already active tab');
el.tabs('destroy');
el.tabs({ collapsible: true });
el.tabs('select', -1);
equals(el.tabs('option', 'active'), -1, 'should collapse tab passing in -1');
el.tabs('destroy');
el.tabs();
el.tabs('select', 0);
equals(el.tabs('option', 'active'), 0, 'should not collapse tab if collapsible is not set to true');
el.tabs('select', -1);
equals(el.tabs('option', 'active'), 0, 'should not collapse tab if collapsible is not set to true');
el.tabs('select', '#fragment-2');
equals(el.tabs('option', 'active'), 1, 'should select tab by id');
});
test( "length", function() {
expect( 2 );
equals( $( "#tabs1" ).tabs().tabs( "length" ), 3, "basic tabs" );
equals( $( "#tabs2" ).tabs().tabs( "length" ), 5, "ajax tabs with missing panels" );
});
test( "url", function() {
expect( 2 );
var element = $( "#tabs2" ).tabs(),
tab = element.find( "a" ).eq( 3 );
element.tabs( "url", 3, "data/test2.html" );
equals( tab.attr( "href" ), "data/test2.html", "href was updated" );
element.one( "tabsbeforeload", function( event, ui ) {
equals( ui.ajaxSettings.url, "data/test2.html", "ajaxSettings.url" );
event.preventDefault();
});
element.tabs( "option", "active", 3 );
});
}( jQuery ) );
|