github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

jquery / jquery-ui

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 405
    • 52
  • Source
  • Commits
  • Network (52)
  • Graphs
  • Tree: 73adda4

click here to add a description

click here to add a homepage

  • Switch Branches (6)
    • bind
    • formcontrols
    • master
    • menu
    • panel
    • tooltip
  • Switch Tags (16)
    • 1.8rc3
    • 1.8rc2
    • 1.8rc1
    • 1.8b1
    • 1.8a2
    • 1.8a1
    • 1.8.1
    • 1.8
    • 1.7
    • 1.6rc6
    • 1.6rc5
    • 1.6rc3
    • 1.6rc2
    • 1.6
    • 1.5.2
    • 1.5.1
  • Comments
  • Contributors
Sending Request…

The official jQuery user interface library. — Read more

  Cancel

http://jqueryui.com/

  Cancel
  • HTTP
  • Git Read-Only

This URL has Read+Write access

added tests for enable/disable
carhartl (author)
Mon Apr 19 11:38:04 -0700 2010
rdworth (committer)
Mon Apr 19 12:00:34 -0700 2010
commit  73adda414647c7ecbc16
tree    50f6e382132379db36d4
parent  970ed9a67a533ab44b18
M tests/unit/tabs/tabs_events.js 41 ••••
M tests/unit/tabs/tabs_methods.js 56 ••••
Txt tests/unit/tabs/tabs_events.js
  • View file @ 73adda4
... ...
@@ -22,15 +22,17 @@ test('show', function() {
22 22
       uiObj = ui;
23 23
     }
24 24
   });
25  
-  ok(uiObj !== undefined, 'should fire show after init');
26  
-  equals(uiObj.tab, $('#tabs1 a')[0], 'should have tab as DOM anchor element');
27  
-  equals(uiObj.panel, $('#tabs1 div')[0], 'should have panel as DOM div element');
28  
-  equals(uiObj.index, 0, 'should have index');
29  
-  
  25
+  ok(uiObj !== undefined, 'trigger callback after initialization');
  26
+  equals(uiObj.tab, $('a', el)[0], 'contain tab as DOM anchor element');
  27
+  equals(uiObj.panel, $('div', el)[0], 'contain panel as DOM div element');
  28
+  equals(uiObj.index, 0, 'contain index');
  29
+
30 30
 });
31 31
 
32 32
 test('add', function() {
33 33
 
  34
+  // TODO move to methods, not at all event related...
  35
+
34 36
   var el = $('<div id="tabs"><ul></ul></div>').tabs();
35 37
   equals(el.tabs('option', 'selected'), -1, 'Initially empty, no selected tab');
36 38
 
... ...
@@ -47,11 +49,36 @@ test('remove', function() {
47 49
 });
48 50
 
49 51
 test('enable', function() {
50  
-  ok(false, "missing test - untested code is broken code.");
  52
+  expect(4);
  53
+
  54
+  var uiObj;
  55
+  el = $('#tabs1').tabs({
  56
+    disabled: [ 0, 1 ],
  57
+    enable: function (event, ui) {
  58
+      uiObj = ui;
  59
+    }
  60
+  });
  61
+  el.tabs('enable', 1);
  62
+  ok(uiObj !== undefined, 'trigger callback');
  63
+  equals(uiObj.tab, $('a', el)[1], 'contain tab as DOM anchor element');
  64
+  equals(uiObj.panel, $('div', el)[1], 'contain panel as DOM div element');
  65
+  equals(uiObj.index, 1, 'contain index');
51 66
 });
52 67
 
53 68
 test('disable', function() {
54  
-  ok(false, "missing test - untested code is broken code.");
  69
+  expect(4);
  70
+
  71
+  var uiObj;
  72
+  el = $('#tabs1').tabs({
  73
+    disable: function (event, ui) {
  74
+      uiObj = ui;
  75
+    }
  76
+  });
  77
+  el.tabs('disable', 1);
  78
+  ok(uiObj !== undefined, 'trigger callback');
  79
+  equals(uiObj.tab, $('a', el)[1], 'contain tab as DOM anchor element');
  80
+  equals(uiObj.panel, $('div', el)[1], 'contain panel as DOM div element');
  81
+  equals(uiObj.index, 1, 'contain index');
55 82
 });
56 83
 
57 84
 })(jQuery);
Txt tests/unit/tabs/tabs_methods.js
  • View file @ 73adda4
... ...
@@ -9,7 +9,7 @@ test('init', function() {
9 9
   expect(9);
10 10
 
11 11
   el = $('#tabs1').tabs();
12  
-  
  12
+
13 13
   ok(true, '.tabs() called on element');
14 14
   ok( el.is('.ui-tabs.ui-widget.ui-widget-content.ui-corner-all'), 'attach classes to container');
15 15
   ok( $('ul', el).is('.ui-tabs-nav.ui-helper-reset.ui-helper-clearfix.ui-widget-header.ui-corner-all'), 'attach classes to list' );
... ...
@@ -23,32 +23,48 @@ test('init', function() {
23 23
 
24 24
 test('destroy', function() {
25 25
   expect(6);
26  
-  
  26
+
27 27
   el = $('#tabs1').tabs({ collapsible: true });
28 28
   $('li:eq(2)', el).simulate('mouseover').find('a').focus();
29 29
   el.tabs('destroy');
30  
-  
  30
+
31 31
   ok( el.is(':not(.ui-tabs, .ui-widget, .ui-widget-content, .ui-corner-all, .ui-tabs-collapsible)'), 'remove classes from container');
32 32
   ok( $('ul', el).is(':not(.ui-tabs-nav, .ui-helper-reset, .ui-helper-clearfix, .ui-widget-header, .ui-corner-all)'), 'remove classes from list' );
33 33
   ok( $('div:eq(1)', el).is(':not(.ui-tabs-panel, .ui-widget-content, .ui-corner-bottom, .ui-tabs-hide)'), 'remove classes to panel' );
34  
-  ok( $('li:eq(0)', el).is(':not(.ui-tabs-selected, .ui-state-active, .ui-corner-top)'), 'remove classes from active li');  
  34
+  ok( $('li:eq(0)', el).is(':not(.ui-tabs-selected, .ui-state-active, .ui-corner-top)'), 'remove classes from active li');
35 35
   ok( $('li:eq(1)', el).is(':not(.ui-state-default, .ui-corner-top)'), 'remove classes from inactive li');
36 36
   ok( $('li:eq(2)', el).is(':not(.ui-state-hover, .ui-state-focus)'), 'remove classes from mouseovered or focused li');
37 37
 });
38 38
 
39 39
 test('enable', function() {
40  
-  ok(false, "missing test - untested code is broken code.");
  40
+    expect(2);
  41
+
  42
+  el = $('#tabs1').tabs({ disabled: [ 0, 1 ] });
  43
+  el.tabs("enable", 1);
  44
+  ok( $('li:eq(1)', el).is(':not(.ui-state-disabled)'), 'remove class from li');
  45
+  same(el.tabs('option', 'disabled'), [ ], 'update property');
41 46
 });
42 47
 
43 48
 test('disable', function() {
44  
-  ok(false, "missing test - untested code is broken code.");
  49
+    expect(4);
  50
+
  51
+  // normal
  52
+  el = $('#tabs1').tabs();
  53
+  el.tabs('disable', 1);
  54
+  ok( $('li:eq(1)', el).is('.ui-state-disabled'), 'add class to li');
  55
+  same(el.tabs('option', 'disabled'), [ 1 ], 'update disabled property');
  56
+
  57
+  // attempt to disable selected has no effect
  58
+  el.tabs('disable', 0);
  59
+  ok( $('li:eq(0)', el).is(':not(.ui-state-disabled)'), 'not add class to li');
  60
+  same(el.tabs('option', 'disabled'), [ 1 ], 'not update property');
45 61
 });
46 62
 
47 63
 test('add', function() {
48 64
   expect(4);
49  
-  
  65
+
50 66
   el = $('#tabs1').tabs();
51  
-  el.tabs('add', "#new", 'New');
  67
+  el.tabs('add', '#new', 'New');
52 68
 
53 69
   var added = $('li:last', el).simulate('mouseover');
54 70
   ok(added.is('.ui-state-hover'), 'should add mouseover handler to added tab');
... ...
@@ -56,9 +72,9 @@ test('add', function() {
56 72
   var other = $('li:first', el).simulate('mouseover');
57 73
   ok(other.is('.ui-state-hover'), 'should not remove mouseover handler from existing tab');
58 74
   other.simulate('mouseout');
59  
-  
  75
+
60 76
   equals($('a', added).attr('href'), '#new', 'should not expand href to full url of current page');
61  
-  
  77
+
62 78
   ok(false, "missing test - untested code is broken code.");
63 79
 });
64 80
 
... ...
@@ -66,25 +82,25 @@ test('remove', function() {
66 82
   expect(4);
67 83
 
68 84
   el = $('#tabs1').tabs();
69  
-  
  85
+
70 86
   el.tabs('remove', 0);
71 87
   equals(el.tabs('length'), 2, 'remove tab');
72 88
   equals($('li a[href$="fragment-1"]', el).length, 0, 'remove associated list item');
73 89
   equals($('#fragment-1').length, 0, 'remove associated panel');
74  
-  
  90
+
75 91
   // TODO delete tab -> focus tab to right
76 92
   // TODO delete last tab -> focus tab to left
77  
-  
  93
+
78 94
   el.tabs('select', 1);
79 95
   el.tabs('remove', 1);
80  
-  equals(el.tabs('option', 'selected'), 0, 'update selected property');    
  96
+  equals(el.tabs('option', 'selected'), 0, 'update selected property');
81 97
 });
82 98
 
83 99
 test('select', function() {
84 100
   expect(9);
85  
-  
  101
+
86 102
   el = $('#tabs1').tabs();
87  
-  
  103
+
88 104
   el.tabs('select', 1);
89 105
   equals(el.tabs('option', 'selected'), 1, 'should select tab');
90 106
 
... ...
@@ -97,11 +113,11 @@ test('select', function() {
97 113
   el.tabs({ collapsible: true });
98 114
   el.tabs('select', -1);
99 115
   equals(el.tabs('option', 'selected'), -1, 'should collapse tab passing in -1');
100  
-  
  116
+
101 117
   el.tabs('destroy');
102 118
   el.tabs({ collapsible: true });
103 119
   el.tabs('select', null);
104  
-  equals(el.tabs('option', 'selected'), -1, 'should collapse tab passing in null (deprecated)');  
  120
+  equals(el.tabs('option', 'selected'), -1, 'should collapse tab passing in null (deprecated)');
105 121
   el.tabs('select', null);
106 122
   equals(el.tabs('option', 'selected'), -1, 'should not select tab passing in null a second time (deprecated)');
107 123
 
... ...
@@ -113,7 +129,7 @@ test('select', function() {
113 129
   equals(el.tabs('option', 'selected'), 0, 'should not collapse tab if collapsible is not set to true');
114 130
   el.tabs('select', null);
115 131
   equals(el.tabs('option', 'selected'), 0, 'should not collapse tab if collapsible is not set to true');
116  
-  
  132
+
117 133
   el.tabs('select', '#fragment-2');
118 134
   equals(el.tabs('option', 'selected'), 1, 'should select tab by id');
119 135
 });
... ...
@@ -128,7 +144,7 @@ test('url', function() {
128 144
 
129 145
 test('length', function() {
130 146
   expect(1);
131  
-  
  147
+
132 148
   el = $('#tabs1').tabs();
133 149
   equals(el.tabs('length'), $('ul a', el).length, ' should return length');
134 150
 });

0 notes on commit 73adda4

Please log in to comment.
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server