r2016 - in trunk: tests/unit/tabs ui

r2016 - in trunk: tests/unit/tabs ui


Author: klaus.hartl
Date: Thu Feb 5 11:36:31 2009
New Revision: 2016
Modified:
trunk/tests/unit/tabs/tabs_options.js
trunk/ui/ui.tabs.js
Log:
Tabs: fixed bug related to setting selected via data method, cleaned up
mess in tests
Modified: trunk/tests/unit/tabs/tabs_options.js
==============================================================================
--- trunk/tests/unit/tabs/tabs_options.js    (original)
+++ trunk/tests/unit/tabs/tabs_options.js    Thu Feb 5 11:36:31 2009
@@ -99,39 +99,34 @@
    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');
-    
-    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: null });
+    equals(el.data('selected.tabs'), -1, 'should be -1 for all tabs
unselected with value null (deprecated)');
    
+    el.tabs('destroy');
+    el.tabs({ selected: 1 });
+    equals(el.data('selected.tabs'), 1, 'should be specified tab');
+    
+    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() {
Modified: trunk/ui/ui.tabs.js
==============================================================================
--- trunk/ui/ui.tabs.js    (original)
+++ trunk/ui/ui.tabs.js    Thu Feb 5 11:36:31 2009
@@ -21,9 +21,12 @@
    },
    _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')