Skip to content
Permalink
Browse files

Tabs: fixed bug related to setting selected via data method, cleaned …

…up mess in tests
  • Loading branch information
Klaus Hartl
Klaus Hartl committed Feb 5, 2009
1 parent 78adee1 commit fbc6ff5f812b673c5263d0ccaf3b2c2bf4d34790
Showing with 27 additions and 29 deletions.
  1. +22 −27 tests/unit/tabs/tabs_options.js
  2. +5 −2 ui/ui.tabs.js
@@ -99,39 +99,34 @@ test('panelTemplate', function() {
ok(false, "missing test - untested code is broken code.");
});

test('selected: null', function() { // TODO move to selected
expect(2);

el = $('#tabs1');

el.tabs({ selected: null });
test('selected', function() {
expect(8);

el = $('#tabs1').tabs();
equals(el.data('selected.tabs'), 0, 'should be 0 by default');

el.tabs('destroy');
el.tabs({ selected: -1 });
equals(el.data('selected.tabs'), -1, 'should be -1 for all tabs unselected');
equals( $('li.ui-tabs-selected', el).length, 0, 'no tab should be selected' );
equals( $('div.ui-tabs-hide', '#tabs1').length, 3, 'all panels should be hidden' );

});

test('selected', function() {
expect(5);

$('#tabs1').tabs();
equals($('#tabs1').data('selected.tabs'), 0, 'selected should be 0 by default');

reset();
$('#tabs1').tabs({ selected: null });
equals($('#tabs1').data('selected.tabs'), -1, 'selected should be -1 for all tabs unselected');

reset();
$('#tabs1').tabs({ selected: -1 });
equals($('#tabs1').data('selected.tabs'), -1, 'selected should be -1 for all tabs unselected');
el.tabs('destroy');
el.tabs({ selected: null });
equals(el.data('selected.tabs'), -1, 'should be -1 for all tabs unselected with value null (deprecated)');

reset();
$('#tabs1').tabs({ selected: 1 });
equals($('#tabs1').data('selected.tabs'), 1, 'selected should be specified tab');
el.tabs('destroy');
el.tabs({ selected: 1 });
equals(el.data('selected.tabs'), 1, 'should be specified tab');

reset();
$('#tabs1').tabs({ selected: 8 });
equals($('#tabs1').data('selected.tabs'), 0, 'selected should default to zero if given value is out of index');
el.tabs('destroy');
el.tabs({ selected: 99 });
equals(el.data('selected.tabs'), 0, 'selected should default to zero if given value is out of index');

el.tabs('destroy');
el.tabs({ collapsible: true });
el.data('selected.tabs', 0);
equals(el.data('selected.tabs'), 0, 'should not collapse tab if value is same as selected');
});

test('spinner', function() {
@@ -21,9 +21,12 @@ $.widget("ui.tabs", {
},

_setData: function(key, value) {
if (key == 'selected')
if (key == 'selected') {
if (this.options.collapsible
&& value == this.options.selected) return;

this.select(value);

}
else {
this.options[key] = value;
if (key == 'deselectable')

0 comments on commit fbc6ff5

Please sign in to comment.
You can’t perform that action at this time.