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,
|
|
|
|
disabled: [],
|
|
|
|
event: 'click',
|
|
|
|
fx: null,
|
|
|
|
idPrefix: 'ui-tabs-',
|
|
|
|
panelTemplate: '<div></div>',
|
|
|
|
spinner: 'Loading…',
|
|
|
|
tabTemplate: '<li><a href="#{href}"><span>#{label}</span></a></li>'
|
|
|
|
};
|
|
|
|
|
|
|
|
var el;
|
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() {
|
2008-12-22 11:44:30 +00:00
|
|
|
expect(9);
|
2008-10-06 11:41:48 +00:00
|
|
|
|
2009-01-31 00:45:14 +00:00
|
|
|
el = $('#tabs1').tabs();
|
2008-12-22 11:44:30 +00:00
|
|
|
|
2009-01-18 21:47:50 +00:00
|
|
|
ok(true, '.tabs() called on element');
|
2008-12-22 11:44:30 +00:00
|
|
|
ok( el.is('.ui-tabs.ui-widget.ui-widget-content.ui-corner-all'), 'attach classes to container');
|
|
|
|
ok( $('ul', el).is('.ui-tabs-nav.ui-helper-reset.ui-helper-clearfix.ui-widget-header.ui-corner-all'), 'attach classes to list' );
|
|
|
|
ok( $('div:eq(0)', el).is('.ui-tabs-panel.ui-widget-content.ui-corner-bottom'), 'attach classes to panel' );
|
2009-01-18 21:47:50 +00:00
|
|
|
ok( $('li:eq(0)', el).is('.ui-tabs-selected.ui-state-active.ui-corner-top'), 'attach classes to active li');
|
|
|
|
ok( $('li:eq(1)', el).is('.ui-state-default.ui-corner-top'), 'attach classes to inactive li');
|
|
|
|
equals( el.data('selected.tabs'), 0, 'selected.tabs set' );
|
|
|
|
equals( $('li', el).index( $('li.ui-tabs-selected', el) ), 0, 'second tab active');
|
|
|
|
equals( $('div', el).index( $('div.ui-tabs-hide', '#tabs1') ), 1, 'second panel should be hidden' );
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('destroy', function() {
|
2009-01-18 21:47:50 +00:00
|
|
|
expect(5);
|
2009-01-18 21:09:31 +00:00
|
|
|
|
2009-01-31 00:45:14 +00:00
|
|
|
el = $('#tabs1').tabs();
|
2009-01-18 21:09:31 +00:00
|
|
|
el.tabs('destroy');
|
|
|
|
|
2009-01-18 21:47:50 +00:00
|
|
|
ok( el.is(':not(.ui-tabs, .ui-widget, .ui-widget-content, .ui-corner-all)'), 'remove classes from container');
|
|
|
|
ok( $('ul', el).is(':not(.ui-tabs-nav, .ui-helper-reset, .ui-helper-clearfix, .ui-widget-header, .ui-corner-all)'), 'remove classes from list' );
|
|
|
|
ok( $('div:eq(1)', el).is(':not(.ui-tabs-panel, .ui-widget-content, .ui-corner-bottom, .ui-tabs-hide)'), 'remove classes to panel' );
|
|
|
|
ok( $('li:eq(0)', el).is(':not(.ui-tabs-selected, .ui-state-active, .ui-corner-top)'), 'remove classes from active li');
|
|
|
|
ok( $('li:eq(1)', el).is(':not(.ui-state-default, .ui-corner-top)'), 'remove classes from inactive li');
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("defaults", function() {
|
2009-01-31 00:45:14 +00:00
|
|
|
el = $('#tabs1').tabs();
|
2008-11-12 02:52:31 +00:00
|
|
|
$.each(defaults, function(key, val) {
|
2008-12-22 11:44:30 +00:00
|
|
|
var actual = el.data(key + '.tabs'), expected = val;
|
2008-11-12 02:52:31 +00:00
|
|
|
same(actual, expected, key);
|
|
|
|
});
|
2008-12-22 11:44:30 +00:00
|
|
|
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-11-18 02:55:25 +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() {
|
2008-12-22 11:45:29 +00:00
|
|
|
expect(4);
|
|
|
|
|
2009-01-31 00:45:14 +00:00
|
|
|
el = $('#tabs1').tabs();
|
2009-01-19 23:11:30 +00:00
|
|
|
|
2008-12-22 11:45:29 +00:00
|
|
|
el.tabs('remove', 0);
|
|
|
|
equals(el.tabs('length'), 2, 'remove tab');
|
|
|
|
equals($('li a[href$="fragment-1"]', el).length, 0, 'remove associated list item');
|
|
|
|
equals($('#fragment-1').length, 0, 'remove associated panel');
|
|
|
|
|
|
|
|
// TODO delete tab -> focus tab to right
|
|
|
|
// TODO delete last tab -> focus tab to left
|
|
|
|
|
2009-01-19 23:11:30 +00:00
|
|
|
el.tabs('select', 1);
|
2008-12-22 11:45:29 +00:00
|
|
|
el.tabs('remove', 1);
|
2009-01-19 23:11:30 +00:00
|
|
|
equals(el.data('selected.tabs'), 0, 'update selected property');
|
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-11-18 02:55:25 +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-11-18 02:55:25 +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-11-18 02:55:25 +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-11-18 02:55:25 +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-11-18 02:55:25 +00:00
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
});
|
2009-02-01 21:22:05 +00:00
|
|
|
|
|
|
|
test('length', function() {
|
|
|
|
expect(1);
|
|
|
|
|
|
|
|
el = $('#tabs1').tabs();
|
|
|
|
equals(el.tabs('length'), $('ul a', el).length, ' should return length');
|
|
|
|
|
|
|
|
});
|
2008-10-04 11:25:28 +00:00
|
|
|
|
2009-01-26 11:34:28 +00:00
|
|
|
test('callback ui object', function() {
|
|
|
|
expect(3);
|
|
|
|
|
|
|
|
var uiObj;
|
2009-02-01 21:22:05 +00:00
|
|
|
el = $('#tabs1').tabs({
|
2009-01-26 11:34:28 +00:00
|
|
|
show: function(event, ui) {
|
|
|
|
uiObj = ui;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
equals(uiObj.tab, $('#tabs1 a')[0], 'should have tab as DOM anchor element');
|
|
|
|
equals(uiObj.panel, $('#tabs1 div')[0], 'should have panel as DOM div element');
|
|
|
|
equals(uiObj.index, 0, ' should have index');
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2009-01-25 23:42:56 +00:00
|
|
|
test('selected property', 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');
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
module('tabs: Options');
|
2008-10-04 11:25:28 +00:00
|
|
|
|
2009-01-25 23:42:56 +00:00
|
|
|
test('selected: null', function() {
|
|
|
|
expect(2);
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2009-01-31 00:45:14 +00:00
|
|
|
el = $('#tabs1');
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
el.tabs({ selected: null });
|
2009-01-25 23:42:56 +00:00
|
|
|
equals( $('li.ui-tabs-selected', el).length, 0, 'no tab should be selected' );
|
2008-10-04 11:25:28 +00:00
|
|
|
equals( $('div.ui-tabs-hide', '#tabs1').length, 3, 'all panels should be hidden' );
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
});
|
|
|
|
|
2008-10-08 10:09:55 +00:00
|
|
|
test('deselectable: true', function() {
|
2008-10-06 11:41:48 +00:00
|
|
|
expect(7);
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2009-01-31 00:45:14 +00:00
|
|
|
el = $('#tabs1');
|
2008-11-18 02:55:25 +00:00
|
|
|
|
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-11-18 02:55:25 +00:00
|
|
|
|
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-11-18 02:55:25 +00:00
|
|
|
|
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');
|
2009-01-31 00:45:14 +00:00
|
|
|
equals( $('div.ui-tabs-hide', '#tabs1').length, 3, 'all panels should be hidden' );
|
2008-10-06 11:41:48 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
test('cookie', function() {
|
2009-01-25 23:42:56 +00:00
|
|
|
expect(6);
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2009-01-31 00:45:14 +00:00
|
|
|
el = $('#tabs1');
|
|
|
|
var cookieName = 'tabs_test', cookieObj = { name: cookieName };
|
2008-10-06 11:41:48 +00:00
|
|
|
$.cookie(cookieName, null); // blank state
|
|
|
|
var cookie = function() {
|
|
|
|
return parseInt($.cookie(cookieName), 10);
|
|
|
|
};
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2009-01-31 00:45:14 +00:00
|
|
|
el.tabs({ cookie: cookieObj });
|
|
|
|
equals(cookie(), 0, 'initial cookie value');
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
el.tabs('destroy');
|
2009-01-31 00:45:14 +00:00
|
|
|
el.tabs({ selected: 1, cookie: cookieObj });
|
|
|
|
equals(cookie(), 1, 'initial cookie value, from selected property');
|
2008-10-06 11:41:48 +00:00
|
|
|
|
|
|
|
el.tabs('select', 2);
|
2009-01-31 00:45:14 +00:00
|
|
|
equals(cookie(), 2, 'cookie value updated after select');
|
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
el.tabs('destroy');
|
|
|
|
$.cookie(cookieName, 1);
|
2009-01-31 00:45:14 +00:00
|
|
|
el.tabs({ cookie: cookieObj });
|
2008-10-06 11:41:48 +00:00
|
|
|
equals(cookie(), 1, 'initial cookie value, from existing cookie');
|
2009-01-31 00:45:14 +00:00
|
|
|
|
2009-01-25 23:42:56 +00:00
|
|
|
el.tabs('destroy');
|
2009-01-31 00:45:14 +00:00
|
|
|
el.tabs({ cookie: cookieObj, deselectable: true });
|
2009-01-25 23:42:56 +00:00
|
|
|
el.tabs('select', 0);
|
2009-01-31 00:45:14 +00:00
|
|
|
equals(cookie(), -1, 'cookie value for all tabs unselected');
|
2009-01-25 23:42:56 +00:00
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
el.tabs('destroy');
|
|
|
|
ok($.cookie(cookieName) === null, 'erase cookie after destroy');
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
module('tabs: Tickets');
|
|
|
|
|
2009-01-18 21:09:31 +00:00
|
|
|
test('id containing colon, #2715', function() { // http://ui.jquery.com/bugs/ticket/2715
|
2008-10-06 11:41:48 +00:00
|
|
|
expect(4);
|
|
|
|
|
2009-01-31 00:45:14 +00:00
|
|
|
el = $('#tabs2').tabs();
|
2008-10-06 11:41:48 +00:00
|
|
|
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' );
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
el.tabs('select', 1).tabs('select', 0);
|
2009-01-31 00:45:14 +00:00
|
|
|
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' );
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
});
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
test('panel containing inline style, #????', function() {
|
2008-10-06 21:35:32 +00:00
|
|
|
expect(3);
|
2008-11-18 02:55:25 +00:00
|
|
|
|
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');
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2009-01-31 00:45:14 +00:00
|
|
|
el = $('#tabs2').tabs();
|
2008-10-06 21:35:32 +00:00
|
|
|
equals(inlineStyle('height'), expected, 'init should not remove inline style');
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
el.tabs('select', 1);
|
2009-01-31 00:45:14 +00:00
|
|
|
equals(inlineStyle('height'), expected, 'show tab should not remove inline style');
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2009-01-31 00:45:14 +00:00
|
|
|
el.tabs('select', 0);
|
|
|
|
equals(inlineStyle('height'), expected, 'hide tab should not remove inline style');
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-10-06 11:41:48 +00:00
|
|
|
});
|
2009-01-19 23:11:30 +00:00
|
|
|
|
|
|
|
test('Ajax tab with url containing a fragment identifier fails to load, #3627', function() { // http://ui.jquery.com/bugs/ticket/3627
|
|
|
|
expect(1);
|
|
|
|
|
2009-01-31 00:45:14 +00:00
|
|
|
el = $('#tabs2').tabs();
|
2009-01-19 23:11:30 +00:00
|
|
|
|
2009-02-01 21:28:10 +00:00
|
|
|
ok(/test.html$/.test( $('a:eq(2)', el).data('load.tabs') ), 'should ignore fragment identifier');
|
2009-01-19 23:11:30 +00:00
|
|
|
|
|
|
|
});
|
2009-02-01 21:09:02 +00:00
|
|
|
|
|
|
|
test('IE expands hash to full url and misinterprets tab as ajax, #4033', function() { // http://ui.jquery.com/bugs/ticket/4033
|
|
|
|
expect(1);
|
|
|
|
|
|
|
|
el = $('<div><ul><li><a href="#tab">Tab</a></li></ul><div id="tab"></div></div>')
|
|
|
|
.appendTo('#main').tabs();
|
|
|
|
|
|
|
|
equals($('a', el).data('load.tabs'), undefined, 'should not create ajax tab');
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-10-02 14:20:35 +00:00
|
|
|
// test('', function() {
|
|
|
|
// expect(0);
|
2008-11-18 02:55:25 +00:00
|
|
|
//
|
2008-10-02 14:20:35 +00:00
|
|
|
// });
|
2008-09-28 11:47:07 +00:00
|
|
|
|
|
|
|
})(jQuery);
|