From fbc6ff5f812b673c5263d0ccaf3b2c2bf4d34790 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Thu, 5 Feb 2009 19:36:31 +0000 Subject: [PATCH] Tabs: fixed bug related to setting selected via data method, cleaned up mess in tests --- tests/unit/tabs/tabs_options.js | 49 +++++++++++++++------------------ ui/ui.tabs.js | 7 +++-- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/tests/unit/tabs/tabs_options.js b/tests/unit/tabs/tabs_options.js index 51193b8cc..e6554f6ce 100644 --- a/tests/unit/tabs/tabs_options.js +++ b/tests/unit/tabs/tabs_options.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() { diff --git a/ui/ui.tabs.js b/ui/ui.tabs.js index 1564af841..4b92cf249 100644 --- a/ui/ui.tabs.js +++ b/ui/ui.tabs.js @@ -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') -- 2.39.5