Tabs: fixed bug related to setting selected via data method, cleaned up mess in tests

This commit is contained in:
Klaus Hartl 2009-02-05 19:36:31 +00:00
parent 78adee126c
commit fbc6ff5f81
2 changed files with 27 additions and 29 deletions

View File

@ -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);
test('selected', function() {
expect(8);
el = $('#tabs1');
el = $('#tabs1').tabs();
equals(el.data('selected.tabs'), 0, 'should be 0 by default');
el.tabs({ selected: null });
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' );
});
el.tabs('destroy');
el.tabs({ selected: null });
equals(el.data('selected.tabs'), -1, 'should be -1 for all tabs unselected with value null (deprecated)');
test('selected', function() {
expect(5);
el.tabs('destroy');
el.tabs({ selected: 1 });
equals(el.data('selected.tabs'), 1, 'should be specified tab');
$('#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');
reset();
$('#tabs1').tabs({ selected: 1 });
equals($('#tabs1').data('selected.tabs'), 1, 'selected 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() {

View File

@ -21,9 +21,12 @@ $.widget("ui.tabs", {
},
_setData: function(key, value) {
if (key == 'selected')
this.select(value);
if (key == 'selected') {
if (this.options.collapsible
&& value == this.options.selected) return;
this.select(value);
}
else {
this.options[key] = value;
if (key == 'deselectable')