2009-02-02 14:36:08 +00:00
|
|
|
/*
|
|
|
|
* tabs_methods.js
|
|
|
|
*/
|
|
|
|
(function($) {
|
|
|
|
|
|
|
|
module("tabs: methods");
|
|
|
|
|
2009-02-03 13:37:54 +00:00
|
|
|
test('init', function() {
|
|
|
|
expect(9);
|
|
|
|
|
|
|
|
el = $('#tabs1').tabs();
|
2010-04-19 18:38:04 +00:00
|
|
|
|
2009-02-03 13:37:54 +00:00
|
|
|
ok(true, '.tabs() called on element');
|
|
|
|
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' );
|
|
|
|
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');
|
2009-11-09 01:50:23 +00:00
|
|
|
equals( el.tabs('option', 'selected'), 0, 'selected option set' );
|
2009-02-03 13:37:54 +00:00
|
|
|
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' );
|
|
|
|
});
|
|
|
|
|
|
|
|
test('destroy', function() {
|
2009-03-01 14:32:29 +00:00
|
|
|
expect(6);
|
2010-04-19 18:38:04 +00:00
|
|
|
|
2009-03-01 14:32:29 +00:00
|
|
|
el = $('#tabs1').tabs({ collapsible: true });
|
|
|
|
$('li:eq(2)', el).simulate('mouseover').find('a').focus();
|
2009-02-03 13:37:54 +00:00
|
|
|
el.tabs('destroy');
|
2010-04-19 18:38:04 +00:00
|
|
|
|
2009-03-01 14:32:29 +00:00
|
|
|
ok( el.is(':not(.ui-tabs, .ui-widget, .ui-widget-content, .ui-corner-all, .ui-tabs-collapsible)'), 'remove classes from container');
|
2009-02-03 13:37:54 +00:00
|
|
|
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' );
|
2010-04-19 18:38:04 +00:00
|
|
|
ok( $('li:eq(0)', el).is(':not(.ui-tabs-selected, .ui-state-active, .ui-corner-top)'), 'remove classes from active li');
|
2009-02-03 13:37:54 +00:00
|
|
|
ok( $('li:eq(1)', el).is(':not(.ui-state-default, .ui-corner-top)'), 'remove classes from inactive li');
|
2009-03-01 14:32:29 +00:00
|
|
|
ok( $('li:eq(2)', el).is(':not(.ui-state-hover, .ui-state-focus)'), 'remove classes from mouseovered or focused li');
|
2009-02-03 13:37:54 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('enable', function() {
|
2010-04-19 18:38:04 +00:00
|
|
|
expect(2);
|
|
|
|
|
|
|
|
el = $('#tabs1').tabs({ disabled: [ 0, 1 ] });
|
|
|
|
el.tabs("enable", 1);
|
|
|
|
ok( $('li:eq(1)', el).is(':not(.ui-state-disabled)'), 'remove class from li');
|
|
|
|
same(el.tabs('option', 'disabled'), [ ], 'update property');
|
2009-02-03 13:37:54 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('disable', function() {
|
2010-04-19 18:38:04 +00:00
|
|
|
expect(4);
|
|
|
|
|
|
|
|
// normal
|
|
|
|
el = $('#tabs1').tabs();
|
|
|
|
el.tabs('disable', 1);
|
|
|
|
ok( $('li:eq(1)', el).is('.ui-state-disabled'), 'add class to li');
|
|
|
|
same(el.tabs('option', 'disabled'), [ 1 ], 'update disabled property');
|
|
|
|
|
|
|
|
// attempt to disable selected has no effect
|
|
|
|
el.tabs('disable', 0);
|
|
|
|
ok( $('li:eq(0)', el).is(':not(.ui-state-disabled)'), 'not add class to li');
|
|
|
|
same(el.tabs('option', 'disabled'), [ 1 ], 'not update property');
|
2009-02-03 13:37:54 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('add', function() {
|
2009-02-19 20:19:13 +00:00
|
|
|
expect(4);
|
2010-04-19 18:38:04 +00:00
|
|
|
|
2009-02-13 23:05:16 +00:00
|
|
|
el = $('#tabs1').tabs();
|
2010-04-19 18:38:04 +00:00
|
|
|
el.tabs('add', '#new', 'New');
|
2009-02-13 23:05:16 +00:00
|
|
|
|
|
|
|
var added = $('li:last', el).simulate('mouseover');
|
|
|
|
ok(added.is('.ui-state-hover'), 'should add mouseover handler to added tab');
|
|
|
|
added.simulate('mouseout');
|
|
|
|
var other = $('li:first', el).simulate('mouseover');
|
|
|
|
ok(other.is('.ui-state-hover'), 'should not remove mouseover handler from existing tab');
|
|
|
|
other.simulate('mouseout');
|
2010-04-19 18:38:04 +00:00
|
|
|
|
2009-02-19 20:19:13 +00:00
|
|
|
equals($('a', added).attr('href'), '#new', 'should not expand href to full url of current page');
|
2010-04-19 18:38:04 +00:00
|
|
|
|
2009-02-03 13:37:54 +00:00
|
|
|
ok(false, "missing test - untested code is broken code.");
|
|
|
|
});
|
|
|
|
|
|
|
|
test('remove', function() {
|
|
|
|
expect(4);
|
|
|
|
|
|
|
|
el = $('#tabs1').tabs();
|
2010-04-19 18:38:04 +00:00
|
|
|
|
2009-02-03 13:37:54 +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');
|
2010-04-19 18:38:04 +00:00
|
|
|
|
2009-02-03 13:37:54 +00:00
|
|
|
// TODO delete tab -> focus tab to right
|
|
|
|
// TODO delete last tab -> focus tab to left
|
2010-04-19 18:38:04 +00:00
|
|
|
|
2009-02-03 13:37:54 +00:00
|
|
|
el.tabs('select', 1);
|
|
|
|
el.tabs('remove', 1);
|
2010-04-19 18:38:04 +00:00
|
|
|
equals(el.tabs('option', 'selected'), 0, 'update selected property');
|
2009-02-03 13:37:54 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('select', function() {
|
2009-02-05 19:02:47 +00:00
|
|
|
expect(9);
|
2010-04-19 18:38:04 +00:00
|
|
|
|
2009-02-05 19:02:47 +00:00
|
|
|
el = $('#tabs1').tabs();
|
2010-04-19 18:38:04 +00:00
|
|
|
|
2009-02-05 19:02:47 +00:00
|
|
|
el.tabs('select', 1);
|
2009-11-09 01:50:23 +00:00
|
|
|
equals(el.tabs('option', 'selected'), 1, 'should select tab');
|
2009-02-05 19:02:47 +00:00
|
|
|
|
|
|
|
el.tabs('destroy');
|
|
|
|
el.tabs({ collapsible: true });
|
|
|
|
el.tabs('select', 0);
|
2009-11-09 01:50:23 +00:00
|
|
|
equals(el.tabs('option', 'selected'), -1, 'should collapse tab passing in the already selected tab');
|
2009-02-05 19:02:47 +00:00
|
|
|
|
|
|
|
el.tabs('destroy');
|
|
|
|
el.tabs({ collapsible: true });
|
|
|
|
el.tabs('select', -1);
|
2009-11-09 01:50:23 +00:00
|
|
|
equals(el.tabs('option', 'selected'), -1, 'should collapse tab passing in -1');
|
2010-04-19 18:38:04 +00:00
|
|
|
|
2009-02-05 19:02:47 +00:00
|
|
|
el.tabs('destroy');
|
|
|
|
el.tabs({ collapsible: true });
|
|
|
|
el.tabs('select', null);
|
2010-04-19 18:38:04 +00:00
|
|
|
equals(el.tabs('option', 'selected'), -1, 'should collapse tab passing in null (deprecated)');
|
2009-02-05 19:02:47 +00:00
|
|
|
el.tabs('select', null);
|
2009-11-09 01:50:23 +00:00
|
|
|
equals(el.tabs('option', 'selected'), -1, 'should not select tab passing in null a second time (deprecated)');
|
2009-02-05 19:02:47 +00:00
|
|
|
|
|
|
|
el.tabs('destroy');
|
|
|
|
el.tabs();
|
|
|
|
el.tabs('select', 0);
|
2009-11-09 01:50:23 +00:00
|
|
|
equals(el.tabs('option', 'selected'), 0, 'should not collapse tab if collapsible is not set to true');
|
2009-02-05 19:02:47 +00:00
|
|
|
el.tabs('select', -1);
|
2009-11-09 01:50:23 +00:00
|
|
|
equals(el.tabs('option', 'selected'), 0, 'should not collapse tab if collapsible is not set to true');
|
2009-02-05 19:02:47 +00:00
|
|
|
el.tabs('select', null);
|
2009-11-09 01:50:23 +00:00
|
|
|
equals(el.tabs('option', 'selected'), 0, 'should not collapse tab if collapsible is not set to true');
|
2010-04-19 18:38:04 +00:00
|
|
|
|
2009-02-05 19:02:47 +00:00
|
|
|
el.tabs('select', '#fragment-2');
|
2009-11-09 01:50:23 +00:00
|
|
|
equals(el.tabs('option', 'selected'), 1, 'should select tab by id');
|
2009-02-03 13:37:54 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('load', function() {
|
|
|
|
ok(false, "missing test - untested code is broken code.");
|
|
|
|
});
|
|
|
|
|
|
|
|
test('url', function() {
|
|
|
|
ok(false, "missing test - untested code is broken code.");
|
|
|
|
});
|
|
|
|
|
|
|
|
test('length', function() {
|
|
|
|
expect(1);
|
2010-04-19 18:38:04 +00:00
|
|
|
|
2009-02-03 13:37:54 +00:00
|
|
|
el = $('#tabs1').tabs();
|
|
|
|
equals(el.tabs('length'), $('ul a', el).length, ' should return length');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('rotate', function() {
|
2009-02-02 14:36:08 +00:00
|
|
|
ok(false, "missing test - untested code is broken code.");
|
|
|
|
});
|
|
|
|
|
|
|
|
})(jQuery);
|