2008-09-28 11:47:07 +00:00
|
|
|
/*
|
|
|
|
* tabs unit tests
|
|
|
|
*/
|
|
|
|
(function($) {
|
2008-11-12 02:52:31 +00:00
|
|
|
//
|
|
|
|
// Tabs Test Helper Functions
|
|
|
|
//
|
|
|
|
|
|
|
|
var defaults = {
|
|
|
|
ajaxOptions: null,
|
|
|
|
cache: false,
|
|
|
|
cookie: null,
|
|
|
|
deselectable: false,
|
|
|
|
deselectableClass: 'ui-tabs-deselectable',
|
|
|
|
disabled: [],
|
|
|
|
disabledClass: 'ui-tabs-disabled',
|
|
|
|
event: 'click',
|
|
|
|
fx: null,
|
|
|
|
hideClass: 'ui-tabs-hide',
|
|
|
|
idPrefix: 'ui-tabs-',
|
|
|
|
loadingClass: 'ui-tabs-loading',
|
|
|
|
navClass: 'ui-tabs-nav',
|
|
|
|
panelClass: 'ui-tabs-panel',
|
|
|
|
panelTemplate: '<div></div>',
|
|
|
|
selectedClass: 'ui-tabs-selected',
|
|
|
|
spinner: 'Loading…',
|
|
|
|
tabTemplate: '<li><a href="#{href}"><span>#{label}</span></a></li>'
|
|
|
|
};
|
|
|
|
|
|
|
|
var el;
|
2008-09-28 11:47:07 +00:00
|
|
|
|
2008-10-06 21:35:32 +00:00
|
|
|
// need to wait a bit for the pseudo animation...
|
2008-10-06 11:41:48 +00:00
|
|
|
function defer(defered, ms) {
|
2008-10-06 21:35:32 +00:00
|
|
|
var queue = defer.queue || (defer.queue = []);
|
|
|
|
if (!queue.length) stop();
|
|
|
|
queue.push(defered);
|
2008-10-06 11:41:48 +00:00
|
|
|
setTimeout(function() {
|
2008-10-06 21:35:32 +00:00
|
|
|
queue.shift()();
|
|
|
|
if (!queue.length) start();
|
2008-10-06 11:41:48 +00:00
|
|
|
}, ms || 100);
|
|
|
|
}
|
2008-09-28 11:47:07 +00:00
|
|
|
|
2008-10-02 14:20:35 +00:00
|
|
|
module('tabs');
|
2008-09-28 11:47:07 +00:00
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
test('init', function() {
|
|
|
|
expect(4);
|
|
|
|
|
|
|
|
var el = $('#tabs1 > ul').tabs();
|
|
|
|
ok(true, '.tabs() called on element');
|
|
|
|
|
|
|
|
el.tabs('destroy').tabs({ selected: 1 });
|
|
|
|
equals( el.data('selected.tabs'), 1, 'selected.tabs set' );
|
|
|
|
equals( $('li', el).index( $('li.ui-tabs-selected', el) ), 1, 'second tab active');
|
|
|
|
equals( $('div', '#tabs1').index( $('div.ui-tabs-hide', '#tabs1') ), 0, 'first panel should be hidden' );
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
test('destroy', function() {
|
|
|
|
expect(0);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
test("defaults", function() {
|
2008-11-12 02:52:31 +00:00
|
|
|
el = $('#tabs1').tabs();
|
|
|
|
$.each(defaults, function(key, val) {
|
|
|
|
var actual = el.data(key + ".tabs"), expected = val;
|
|
|
|
same(actual, expected, key);
|
|
|
|
});
|
|
|
|
el.tabs("destroy");
|
2008-10-06 11:41:48 +00:00
|
|
|
});
|
2008-10-02 14:20:35 +00:00
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
test('add', function() {
|
|
|
|
expect(0);
|
2008-10-02 14:20:35 +00:00
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
});
|
2008-10-02 14:20:35 +00:00
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
test('remove', function() {
|
|
|
|
expect(0);
|
2008-10-02 14:20:35 +00:00
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
});
|
2008-10-02 14:20:35 +00:00
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
test('enable', function() {
|
|
|
|
expect(0);
|
2008-10-02 14:20:35 +00:00
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
});
|
2008-10-02 14:20:35 +00:00
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
test('disable', function() {
|
|
|
|
expect(0);
|
2008-10-02 14:20:35 +00:00
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
});
|
2008-10-02 14:20:35 +00:00
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
test('select', function() {
|
|
|
|
expect(0);
|
2008-10-02 14:20:35 +00:00
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
});
|
2008-10-02 14:20:35 +00:00
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
test('load', function() {
|
|
|
|
expect(0);
|
2008-10-02 14:20:35 +00:00
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
});
|
2008-10-02 14:20:35 +00:00
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
test('url', function() {
|
|
|
|
expect(0);
|
2008-10-02 14:20:35 +00:00
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
});
|
2008-10-04 11:25:28 +00:00
|
|
|
|
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
module('tabs: Options');
|
2008-10-04 11:25:28 +00:00
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
test('select: null', function() {
|
|
|
|
expect(3);
|
2008-10-04 11:25:28 +00:00
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
var el = $('#tabs1 > ul');
|
2008-10-04 11:25:28 +00:00
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
el.tabs({ selected: null });
|
|
|
|
equals( el.data('selected.tabs'), null, 'option set' );
|
2008-10-08 10:09:55 +00:00
|
|
|
equals( $('li.ui-tabs-selected', el).length, 0, 'all tabs should be deselected' );
|
2008-10-04 11:25:28 +00:00
|
|
|
equals( $('div.ui-tabs-hide', '#tabs1').length, 3, 'all panels should be hidden' );
|
2008-10-02 14:20:35 +00:00
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
// TODO select == null with cookie
|
|
|
|
// TODO select == null with select method
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2008-10-08 10:09:55 +00:00
|
|
|
test('deselectable: true', function() {
|
2008-10-06 11:41:48 +00:00
|
|
|
expect(7);
|
|
|
|
|
|
|
|
var el = $('#tabs1 > ul');
|
|
|
|
|
2008-10-08 10:09:55 +00:00
|
|
|
el.tabs({ deselectable: true });
|
|
|
|
equals( el.data('deselectable.tabs'), true, 'option set' );
|
|
|
|
equals( $('li.ui-tabs-deselectable', el).length, 1, 'class "ui-tabs-deselectable" attached once');
|
|
|
|
equals( $('li', el).index( $('li.ui-tabs-deselectable', el) ), 0, 'class "ui-tabs-deselectable" attached to first tab');
|
2008-10-06 11:41:48 +00:00
|
|
|
|
|
|
|
el.tabs('select', 1);
|
2008-10-08 10:09:55 +00:00
|
|
|
equals( $('li.ui-tabs-deselectable', el).length, 1, 'class "ui-tabs-deselectable" attached once');
|
|
|
|
equals( $('li', el).index( $('li.ui-tabs-deselectable', el) ), 1, 'class "ui-tabs-deselectable" attached to second tab');
|
2008-10-06 11:41:48 +00:00
|
|
|
|
|
|
|
el.tabs('select', 1);
|
2008-10-08 10:09:55 +00:00
|
|
|
equals( $('li.ui-tabs-deselectable', el).length, 0, 'class "ui-tabs-deselectable" not attached');
|
2008-10-06 11:41:48 +00:00
|
|
|
defer(function() {
|
|
|
|
equals( $('div.ui-tabs-hide', '#tabs1').length, 3, 'all panels should be hidden' );
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
test('cookie', function() {
|
|
|
|
expect(5);
|
|
|
|
|
|
|
|
var el = $('#tabs1 > ul');
|
|
|
|
var cookieName = 'ui-tabs-' + $.data(el[0]);
|
|
|
|
$.cookie(cookieName, null); // blank state
|
|
|
|
var cookie = function() {
|
|
|
|
return parseInt($.cookie(cookieName), 10);
|
|
|
|
};
|
|
|
|
|
|
|
|
el.tabs({ cookie: {} });
|
|
|
|
equals(cookie(), 0, 'initial cookie value, no cookie given');
|
|
|
|
|
|
|
|
el.tabs('destroy');
|
|
|
|
el.tabs({ selected: 1, cookie: {} });
|
|
|
|
equals(cookie(), 1, 'initial cookie value, given selected');
|
|
|
|
|
|
|
|
el.tabs('select', 2);
|
|
|
|
equals(cookie(), 2, 'cookie value after tabs select');
|
|
|
|
|
|
|
|
el.tabs('destroy');
|
|
|
|
$.cookie(cookieName, 1);
|
|
|
|
el.tabs({ cookie: {} });
|
|
|
|
equals(cookie(), 1, 'initial cookie value, from existing cookie');
|
|
|
|
|
|
|
|
el.tabs('destroy');
|
|
|
|
ok($.cookie(cookieName) === null, 'erase cookie after destroy');
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
module('tabs: Tickets');
|
|
|
|
|
|
|
|
test('id containing colon, #????', function() {
|
|
|
|
expect(4);
|
|
|
|
|
|
|
|
var el = $('#tabs2 > ul').tabs();
|
|
|
|
ok( $('div.ui-tabs-panel:eq(0)', '#tabs2').is(':visible'), 'first panel should be visible' );
|
|
|
|
ok( $('div.ui-tabs-panel:eq(1)', '#tabs2').is(':hidden'), 'second panel should be hidden' );
|
|
|
|
|
|
|
|
el.tabs('select', 1).tabs('select', 0);
|
|
|
|
defer(function() {
|
|
|
|
ok( $('div.ui-tabs-panel:eq(0)', '#tabs2').is(':visible'), 'first panel should be visible' );
|
|
|
|
ok( $('div.ui-tabs-panel:eq(1)', '#tabs2').is(':hidden'), 'second panel should be hidden' );
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
test('panel containing inline style, #????', function() {
|
2008-10-06 21:35:32 +00:00
|
|
|
expect(3);
|
2008-10-06 11:41:48 +00:00
|
|
|
|
|
|
|
var inlineStyle = function(property) {
|
2008-10-06 21:35:32 +00:00
|
|
|
return $('#inline-style')[0].style[property];
|
2008-10-06 11:41:48 +00:00
|
|
|
};
|
|
|
|
var expected = inlineStyle('height');
|
|
|
|
|
|
|
|
var el = $('#tabs2 > ul').tabs();
|
2008-10-06 21:35:32 +00:00
|
|
|
equals(inlineStyle('height'), expected, 'init should not remove inline style');
|
2008-10-06 11:41:48 +00:00
|
|
|
|
|
|
|
el.tabs('select', 1);
|
|
|
|
defer(function() {
|
2008-10-06 21:35:32 +00:00
|
|
|
equals(inlineStyle('height'), expected, 'show tab should not remove inline style');
|
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
el.tabs('select', 0);
|
|
|
|
defer(function() {
|
2008-10-06 21:35:32 +00:00
|
|
|
equals(inlineStyle('height'), expected, 'hide tab should not remove inline style');
|
2008-10-06 11:41:48 +00:00
|
|
|
});
|
2008-10-06 21:35:32 +00:00
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2008-10-06 21:35:32 +00:00
|
|
|
|
2008-10-02 14:20:35 +00:00
|
|
|
// test('', function() {
|
|
|
|
// expect(0);
|
|
|
|
//
|
|
|
|
// });
|
2008-09-28 11:47:07 +00:00
|
|
|
|
|
|
|
})(jQuery);
|