+
+
diff --git a/tests/unit/tabs/tabs_deprecated.js b/tests/unit/tabs/tabs_deprecated.js
new file mode 100644
index 000000000..b784c724e
--- /dev/null
+++ b/tests/unit/tabs/tabs_deprecated.js
@@ -0,0 +1,343 @@
+(function( $ ) {
+
+module("tabs (deprecated): core");
+
+test( "#4581 - title attribute for remote tabs does not support foreign languages", function() {
+ expect( 1 );
+
+ $( "#tabs2" ).tabs({
+ selected: 3,
+ beforeload: function( event, ui ) {
+ event.preventDefault();
+ equal( ui.panel.id, "∫ßáö_Սե", "proper title" );
+ }
+ });
+});
+
+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: '',
+ 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(11);
+
+ 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-selected', 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: null });
+ equals(el.tabs('option', 'selected'), -1, 'should be -1 for all tabs unselected with value null (deprecated)');
+
+ 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(4);
+
+ var uiObj;
+ el = $('#tabs1').tabs({
+ disabled: [ 0, 1 ],
+ enable: function (event, ui) {
+ uiObj = ui;
+ }
+ });
+ el.tabs('enable', 1);
+ ok(uiObj !== undefined, 'trigger callback');
+ equals(uiObj.tab, $('a', el)[1], 'contain tab as DOM anchor element');
+ equals(uiObj.panel, $('div', el)[1], 'contain panel as DOM div element');
+ equals(uiObj.index, 1, 'contain index');
+});
+
+test('disable', function() {
+ expect(4);
+
+ var uiObj;
+ el = $('#tabs1').tabs({
+ disable: function (event, ui) {
+ uiObj = ui;
+ }
+ });
+ el.tabs('disable', 1);
+ ok(uiObj !== undefined, 'trigger callback');
+ equals(uiObj.tab, $('a', el)[1], 'contain tab as DOM anchor element');
+ equals(uiObj.panel, $('div', el)[1], 'contain panel as DOM div element');
+ equals(uiObj.index, 1, 'contain index');
+});
+
+test('add', function() {
+
+ // TODO move to methods, not at all event related...
+
+ var el = $('
').tabs();
+ equals(el.tabs('option', 'selected'), -1, 'Initially empty, no selected tab');
+
+ el.tabs('add', '#test1', 'Test 1');
+ equals(el.tabs('option', 'selected'), 0, 'First tab added should be auto selected');
+
+ el.tabs('add', '#test2', 'Test 2');
+ equals(el.tabs('option', 'selected'), 0, 'Second tab added should not be auto selected');
+
+});
+
+test('remove', function() {
+ ok(false, "missing test - untested code is broken code.");
+});
+
+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(4);
+
+ el = $('#tabs1').tabs();
+ el.tabs('add', '#new', 'New');
+
+ var added = $('li:last', el).simulate('mouseover');
+ ok(added.is('.ui-state-hover'), 'should add mouseover handler to added tab');
+ added.simulate('mouseout');
+ var other = $('li:first', el).simulate('mouseover');
+ ok(other.is('.ui-state-hover'), 'should not remove mouseover handler from existing tab');
+ other.simulate('mouseout');
+
+ equals($('a', added).attr('href'), '#new', 'should not expand href to full url of current page');
+
+ ok(false, "missing test - untested code is broken code.");
+});
+
+test('remove', function() {
+ expect(4);
+
+ el = $('#tabs1').tabs();
+
+ el.tabs('remove', 0);
+ equals(el.tabs('length'), 2, 'remove tab');
+ equals($('li a[href$="fragment-1"]', el).length, 0, 'remove associated list item');
+ equals($('#fragment-1').length, 0, 'remove associated panel');
+
+ // TODO delete tab -> focus tab to right
+ // TODO delete last tab -> focus tab to left
+
+ el.tabs('select', 1);
+ el.tabs('remove', 1);
+ equals(el.tabs('option', 'selected'), 0, 'update selected property');
+});
+
+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('#5069 - ui.tabs.add creates two tab panels when using a full URL', function() {
+ // http://dev.jqueryui.com/ticket/5069
+ expect(2);
+
+ el = $('#tabs2').tabs();
+ equals(el.children('div').length, el.find('> ul > li').length, 'After creation, number of panels should be equal to number of tabs');
+ el.tabs('add', '/ajax_html_echo', 'Test');
+ equals(el.children('div').length, el.find('> ul > li').length, 'After add, number of panels should be equal to number of tabs');
+});
+
+test('length', function() {
+ expect(1);
+
+ el = $('#tabs1').tabs();
+ equals(el.tabs('length'), $('ul a', el).length, ' should return length');
+});
+
+test('url', function() {
+ el = $('#tabs2').tabs();
+ var tab = el.find('a:eq(3)'),
+ url = tab.attr('href');
+
+ el.tabs('url', 3, "data/test2.html");
+ equals(tab.attr('href'), 'data/test2.html', 'Url was updated');
+ tab.attr('href', url );
+});
+
+}( jQuery ) );
diff --git a/tests/unit/tabs/tabs_events.js b/tests/unit/tabs/tabs_events.js
index 24fb62f9b..381326533 100644
--- a/tests/unit/tabs/tabs_events.js
+++ b/tests/unit/tabs/tabs_events.js
@@ -5,37 +5,59 @@
module("tabs: events");
-test('select', function() {
+test('beforeActivate', function() {
expect(7);
- var eventObj;
el = $('#tabs1').tabs({
- select: function(event, ui) {
- ok(true, 'select triggered after initialization');
+ beforeActivate: function(event, ui) {
+ ok(true, 'beforeActivate triggered after initialization');
equals(this, el[0], "context of callback");
- equals(event.type, 'tabsselect', 'event type in callback');
+ equals(event.type, 'tabsbeforeactivate', '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.tabs('option', 'active', 1);
+ el.tabs('destroy');
+ el.tabs({
+ beforeActivate: function(event, ui) {
+ equals( event.originalEvent.type, "click", "beforeActivate triggered by click" );
+ }
+ });
el.find( "li:eq(1) a" ).simulate( "click" );
- equals( evenObj.originalEvent.type, "click", "select triggered by click" );
+});
+
+test('beforeload', function() {
+ expect( 5 );
+
+ el = $('#tabs2');
+
+ el.tabs({
+ active: 2,
+ beforeload: function( event, ui ) {
+ ok( $.isFunction( ui.jqXHR.promise ), 'contain jqXHR object');
+ equals( ui.settings.url, "data/test.html", 'contain ajax settings url');
+ equals( ui.tab, el.find('a')[ 2 ], 'contain tab as DOM anchor element');
+ equals( ui.panel, el.find('div')[ 2 ], 'contain panel as DOM div element');
+ equals( ui.index, 2, 'contain index');
+ event.preventDefault();
+ }
+ });
+
});
test('load', function() {
ok(false, "missing test - untested code is broken code.");
});
-test('show', function() {
+test('activate', function() {
expect(5);
var uiObj, eventObj;
el = $('#tabs1').tabs({
- show: function(event, ui) {
+ activate: function(event, ui) {
uiObj = ui;
eventObj = event;
}
@@ -50,56 +72,4 @@ test('show', function() {
});
-test('add', function() {
-
- // TODO move to methods, not at all event related...
-
- var el = $('
').tabs();
- equals(el.tabs('option', 'selected'), -1, 'Initially empty, no selected tab');
-
- el.tabs('add', '#test1', 'Test 1');
- equals(el.tabs('option', 'selected'), 0, 'First tab added should be auto selected');
-
- el.tabs('add', '#test2', 'Test 2');
- equals(el.tabs('option', 'selected'), 0, 'Second tab added should not be auto selected');
-
-});
-
-test('remove', function() {
- ok(false, "missing test - untested code is broken code.");
-});
-
-test('enable', function() {
- expect(4);
-
- var uiObj;
- el = $('#tabs1').tabs({
- disabled: [ 0, 1 ],
- enable: function (event, ui) {
- uiObj = ui;
- }
- });
- el.tabs('enable', 1);
- ok(uiObj !== undefined, 'trigger callback');
- equals(uiObj.tab, $('a', el)[1], 'contain tab as DOM anchor element');
- equals(uiObj.panel, $('div', el)[1], 'contain panel as DOM div element');
- equals(uiObj.index, 1, 'contain index');
-});
-
-test('disable', function() {
- expect(4);
-
- var uiObj;
- el = $('#tabs1').tabs({
- disable: function (event, ui) {
- uiObj = ui;
- }
- });
- el.tabs('disable', 1);
- ok(uiObj !== undefined, 'trigger callback');
- equals(uiObj.tab, $('a', el)[1], 'contain tab as DOM anchor element');
- equals(uiObj.panel, $('div', el)[1], 'contain panel as DOM div element');
- equals(uiObj.index, 1, 'contain index');
-});
-
})(jQuery);
diff --git a/tests/unit/tabs/tabs_methods.js b/tests/unit/tabs/tabs_methods.js
index 0209af697..c33bebe65 100644
--- a/tests/unit/tabs/tabs_methods.js
+++ b/tests/unit/tabs/tabs_methods.js
@@ -14,11 +14,11 @@ test('init', function() {
ok( el.is('.ui-tabs.ui-widget.ui-widget-content.ui-corner-all'), 'attach classes to container');
ok( $('ul', el).is('.ui-tabs-nav.ui-helper-reset.ui-helper-clearfix.ui-widget-header.ui-corner-all'), 'attach classes to list' );
ok( $('div:eq(0)', el).is('.ui-tabs-panel.ui-widget-content.ui-corner-bottom'), 'attach classes to panel' );
- ok( $('li:eq(0)', el).is('.ui-tabs-selected.ui-state-active.ui-corner-top'), 'attach classes to active li');
+ ok( $('li:eq(0)', el).is('.ui-tabs-active.ui-state-active.ui-corner-top'), 'attach classes to active li');
ok( $('li:eq(1)', el).is('.ui-state-default.ui-corner-top'), 'attach classes to inactive li');
- equals( el.tabs('option', 'selected'), 0, 'selected option set' );
- equals( $('li', el).index( $('li.ui-tabs-selected', el) ), 0, 'second tab active');
- equals( $('div', el).index( $('div.ui-tabs-hide', '#tabs1') ), 1, 'second panel should be hidden' );
+ equals( el.tabs('option', 'active'), 0, 'active option set' );
+ equals( $('li', el).index( $('li.ui-tabs-active', el) ), 0, 'second tab active');
+ equals( $('div', el).index( $('div:hidden', '#tabs1') ), 1, 'second panel should be hidden' );
});
test('init with hash', function() {
@@ -30,13 +30,13 @@ test('init with hash', function() {
//selection of tab with divs ordered differently than list
el = $('#tabs1').tabs();
- equals(el.tabs('option', 'selected'), 1, 'second tab should be selected');
+ equals(el.tabs('option', 'active'), 1, 'second tab should be active');
- ok(!$('#tabs1 ul li:eq(0)').is('.ui-tabs-selected.ui-state-active'), 'first tab should not be selected nor active');
- ok($('#tabs1 div:eq(0)').is('.ui-tabs-hide'), 'first div for first tab should be hidden');
+ ok(!$('#tabs1 ul li:eq(0)').is('.ui-tabs-active.ui-state-active'), 'first tab should not be selected nor active');
+ ok($('#tabs1 div:eq(0)').is(':hidden'), 'first div for first tab should be hidden');
- ok($('#tabs1 ul li:eq(1)').is('.ui-tabs-selected.ui-state-active'), 'second tab should be selected and active');
- ok(!$('#tabs1 div:eq(1)').is('.ui-tabs-hide'), 'second div for second tab should not be hidden');
+ ok($('#tabs1 ul li:eq(1)').is('.ui-tabs-active.ui-state-active'), 'second tab should be selected and active');
+ ok(!$('#tabs1 div:eq(1)').is(':hidden'), 'second div for second tab should not be hidden');
});
test('init mismatched order with hash', function() {
@@ -48,13 +48,13 @@ test('init mismatched order with hash', function() {
//selection of tab with divs ordered differently than list
el = $('#tabs7').tabs();
- equals(el.tabs('option', 'selected'), 1, 'second tab should be selected');
+ equals(el.tabs('option', 'active'), 1, 'second tab should be active');
- ok(!$('#tabs7-list li:eq(0)').is('.ui-tabs-selected.ui-state-active'), 'first tab should not be selected nor active');
- ok($('#tabs7 div:eq(1)').is('.ui-tabs-hide'), 'second div for first tab should be hidden');
+ ok(!$('#tabs7-list li:eq(0)').is('.ui-tabs-active.ui-state-active'), 'first tab should not be selected nor active');
+ ok($('#tabs7 div:eq(1)').is(':hidden'), 'second div for first tab should be hidden');
- ok($('#tabs7-list li:eq(1)').is('.ui-tabs-selected.ui-state-active'), 'second tab should be selected and active');
- ok(!$('#tabs7 div:eq(0)').is('.ui-tabs-hide'), 'first div for second tab should not be hidden');
+ ok($('#tabs7-list li:eq(1)').is('.ui-tabs-active.ui-state-active'), 'second tab should be selected and active');
+ ok(!$('#tabs7 div:eq(0)').is(':hidden'), 'first div for second tab should not be hidden');
});
test('destroy', function() {
@@ -66,8 +66,8 @@ test('destroy', function() {
ok( el.is(':not(.ui-tabs, .ui-widget, .ui-widget-content, .ui-corner-all, .ui-tabs-collapsible)'), 'remove classes from container');
ok( $('ul', el).is(':not(.ui-tabs-nav, .ui-helper-reset, .ui-helper-clearfix, .ui-widget-header, .ui-corner-all)'), 'remove classes from list' );
- ok( $('div:eq(1)', el).is(':not(.ui-tabs-panel, .ui-widget-content, .ui-corner-bottom, .ui-tabs-hide)'), 'remove classes to panel' );
- ok( $('li:eq(0)', el).is(':not(.ui-tabs-selected, .ui-state-active, .ui-corner-top)'), 'remove classes from active li');
+ ok( $('div:eq(1)', el).is(':not(.ui-tabs-panel, .ui-widget-content, .ui-corner-bottom)'), 'remove classes to panel' );
+ ok( $('li:eq(0)', el).is(':not(.ui-tabs-active, .ui-state-active, .ui-corner-top)'), 'remove classes from active li');
ok( $('li:eq(1)', el).is(':not(.ui-state-default, .ui-corner-top)'), 'remove classes from inactive li');
ok( $('li:eq(2)', el).is(':not(.ui-state-hover, .ui-state-focus)'), 'remove classes from mouseovered or focused li');
});
@@ -130,84 +130,36 @@ test('disable', function() {
same(el.tabs('option', 'disabled'), true, 'set to true');
});
-test('add', function() {
- expect(4);
+test('refresh', function() {
+ expect(5);
- el = $('#tabs1').tabs();
- el.tabs('add', '#new', 'New');
+ var el = $('
').tabs(),
+ ul = el.find('ul');
- var added = $('li:last', el).simulate('mouseover');
- ok(added.is('.ui-state-hover'), 'should add mouseover handler to added tab');
- added.simulate('mouseout');
- var other = $('li:first', el).simulate('mouseover');
- ok(other.is('.ui-state-hover'), 'should not remove mouseover handler from existing tab');
- other.simulate('mouseout');
+ equals(el.tabs('option', 'active'), -1, 'Initially empty, no active tab');
- equals($('a', added).attr('href'), '#new', 'should not expand href to full url of current page');
+ ul.append('