| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 /* 2 * tabs unit tests 3 */ 4 (function($) { 5 // 6 // Tabs Test Helper Functions 7 // 8 9 var defaults = { 10 ajaxOptions: null, 11 cache: false, 12 cookie: null, 13 deselectable: false, 14 deselectableClass: 'ui-tabs-deselectable', 15 disabled: [], 16 disabledClass: 'ui-tabs-disabled', 17 event: 'click', 18 fx: null, 19 hideClass: 'ui-tabs-hide', 20 idPrefix: 'ui-tabs-', 21 loadingClass: 'ui-tabs-loading', 22 navClass: 'ui-tabs-nav', 23 panelClass: 'ui-tabs-panel', 24 panelTemplate: '<div></div>', 25 selectedClass: 'ui-tabs-selected', 26 spinner: 'Loading…', 27 tabTemplate: '<li><a href="#{href}"><span>#{label}</span></a></li>' 28 }; 29 30 var el; 31 32 // need to wait a bit for the pseudo animation... 33 function defer(defered, ms) { 34 var queue = defer.queue || (defer.queue = []); 35 if (!queue.length) stop(); 36 queue.push(defered); 37 setTimeout(function() { 38 queue.shift()(); 39 if (!queue.length) start(); 40 }, ms || 100); 41 } 42 43 module('tabs'); 44 45 test('init', function() { 46 expect(4); 47 48 var el = $('#tabs1 > ul').tabs(); 49 ok(true, '.tabs() called on element'); 50 51 el.tabs('destroy').tabs({ selected: 1 }); 52 equals( el.data('selected.tabs'), 1, 'selected.tabs set' ); 53 equals( $('li', el).index( $('li.ui-tabs-selected', el) ), 1, 'second tab active'); 54 equals( $('div', '#tabs1').index( $('div.ui-tabs-hide', '#tabs1') ), 0, 'first panel should be hidden' ); 55 56 }); 57 58 test('destroy', function() { 59 expect(0); 60 61 }); 62 63 test("defaults", function() { 64 el = $('#tabs1').tabs(); 65 $.each(defaults, function(key, val) { 66 var actual = el.data(key + ".tabs"), expected = val; 67 same(actual, expected, key); 68 }); 69 el.tabs("destroy"); 70 }); 71 72 test('add', function() { 73 expect(0); 74 75 }); 76 77 test('remove', function() { 78 expect(0); 79 80 }); 81 82 test('enable', function() { 83 expect(0); 84 85 }); 86 87 test('disable', function() { 88 expect(0); 89 90 }); 91 92 test('select', function() { 93 expect(0); 94 95 }); 96 97 test('load', function() { 98 expect(0); 99 100 }); 101 102 test('url', function() { 103 expect(0); 104 105 }); 106 107 108 module('tabs: Options'); 109 110 test('select: null', function() { 111 expect(3); 112 113 var el = $('#tabs1 > ul'); 114 115 el.tabs({ selected: null }); 116 equals( el.data('selected.tabs'), null, 'option set' ); 117 equals( $('li.ui-tabs-selected', el).length, 0, 'all tabs should be deselected' ); 118 equals( $('div.ui-tabs-hide', '#tabs1').length, 3, 'all panels should be hidden' ); 119 120 // TODO select == null with cookie 121 // TODO select == null with select method 122 123 }); 124 125 test('deselectable: true', function() { 126 expect(7); 127 128 var el = $('#tabs1 > ul'); 129 130 el.tabs({ deselectable: true }); 131 equals( el.data('deselectable.tabs'), true, 'option set' ); 132 equals( $('li.ui-tabs-deselectable', el).length, 1, 'class "ui-tabs-deselectable" attached once'); 133 equals( $('li', el).index( $('li.ui-tabs-deselectable', el) ), 0, 'class "ui-tabs-deselectable" attached to first tab'); 134 135 el.tabs('select', 1); 136 equals( $('li.ui-tabs-deselectable', el).length, 1, 'class "ui-tabs-deselectable" attached once'); 137 equals( $('li', el).index( $('li.ui-tabs-deselectable', el) ), 1, 'class "ui-tabs-deselectable" attached to second tab'); 138 139 el.tabs('select', 1); 140 equals( $('li.ui-tabs-deselectable', el).length, 0, 'class "ui-tabs-deselectable" not attached'); 141 defer(function() { 142 equals( $('div.ui-tabs-hide', '#tabs1').length, 3, 'all panels should be hidden' ); 143 }); 144 145 }); 146 147 test('cookie', function() { 148 expect(5); 149 150 var el = $('#tabs1 > ul'); 151 var cookieName = 'ui-tabs-' + $.data(el[0]); 152 $.cookie(cookieName, null); // blank state 153 var cookie = function() { 154 return parseInt($.cookie(cookieName), 10); 155 }; 156 157 el.tabs({ cookie: {} }); 158 equals(cookie(), 0, 'initial cookie value, no cookie given'); 159 160 el.tabs('destroy'); 161 el.tabs({ selected: 1, cookie: {} }); 162 equals(cookie(), 1, 'initial cookie value, given selected'); 163 164 el.tabs('select', 2); 165 equals(cookie(), 2, 'cookie value after tabs select'); 166 167 el.tabs('destroy'); 168 $.cookie(cookieName, 1); 169 el.tabs({ cookie: {} }); 170 equals(cookie(), 1, 'initial cookie value, from existing cookie'); 171 172 el.tabs('destroy'); 173 ok($.cookie(cookieName) === null, 'erase cookie after destroy'); 174 175 }); 176 177 178 module('tabs: Tickets'); 179 180 test('id containing colon, #????', function() { 181 expect(4); 182 183 var el = $('#tabs2 > ul').tabs(); 184 ok( $('div.ui-tabs-panel:eq(0)', '#tabs2').is(':visible'), 'first panel should be visible' ); 185 ok( $('div.ui-tabs-panel:eq(1)', '#tabs2').is(':hidden'), 'second panel should be hidden' ); 186 187 el.tabs('select', 1).tabs('select', 0); 188 defer(function() { 189 ok( $('div.ui-tabs-panel:eq(0)', '#tabs2').is(':visible'), 'first panel should be visible' ); 190 ok( $('div.ui-tabs-panel:eq(1)', '#tabs2').is(':hidden'), 'second panel should be hidden' ); 191 }); 192 193 }); 194 195 test('panel containing inline style, #????', function() { 196 expect(3); 197 198 var inlineStyle = function(property) { 199 return $('#inline-style')[0].style[property]; 200 }; 201 var expected = inlineStyle('height'); 202 203 var el = $('#tabs2 > ul').tabs(); 204 equals(inlineStyle('height'), expected, 'init should not remove inline style'); 205 206 el.tabs('select', 1); 207 defer(function() { 208 equals(inlineStyle('height'), expected, 'show tab should not remove inline style'); 209 210 el.tabs('select', 0); 211 defer(function() { 212 equals(inlineStyle('height'), expected, 'hide tab should not remove inline style'); 213 }); 214 215 }); 216 217 }); 218 219 // test('', function() { 220 // expect(0); 221 // 222 // }); 223 224 })(jQuery);
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |