Skip to content

Commit

Permalink
added tests for enable/disable
Browse files Browse the repository at this point in the history
  • Loading branch information
carhartl authored and rdworth committed Apr 19, 2010
1 parent 970ed9a commit 73adda4
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 27 deletions.
41 changes: 34 additions & 7 deletions tests/unit/tabs/tabs_events.js
Expand Up @@ -22,15 +22,17 @@ test('show', function() {
uiObj = ui;
}
});
ok(uiObj !== undefined, 'should fire show after init');
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');
ok(uiObj !== undefined, 'trigger callback after initialization');
equals(uiObj.tab, $('a', el)[0], 'contain tab as DOM anchor element');
equals(uiObj.panel, $('div', el)[0], 'contain panel as DOM div element');
equals(uiObj.index, 0, 'contain index');

});

test('add', function() {

// TODO move to methods, not at all event related...

var el = $('<div id="tabs"><ul></ul></div>').tabs();
equals(el.tabs('option', 'selected'), -1, 'Initially empty, no selected tab');

Expand All @@ -47,11 +49,36 @@ test('remove', function() {
});

test('enable', function() {
ok(false, "missing test - untested code is broken code.");
expect(4);

var uiObj;
el = $('#tabs1').tabs({
disabled: [ 0, 1 ],
enable: function (event, ui) {
uiObj = ui;
}
});
el.tabs('enable', 1);
ok(uiObj !== undefined, 'trigger callback');
equals(uiObj.tab, $('a', el)[1], 'contain tab as DOM anchor element');
equals(uiObj.panel, $('div', el)[1], 'contain panel as DOM div element');
equals(uiObj.index, 1, 'contain index');
});

test('disable', function() {
ok(false, "missing test - untested code is broken code.");
expect(4);

var uiObj;
el = $('#tabs1').tabs({
disable: function (event, ui) {
uiObj = ui;
}
});
el.tabs('disable', 1);
ok(uiObj !== undefined, 'trigger callback');
equals(uiObj.tab, $('a', el)[1], 'contain tab as DOM anchor element');
equals(uiObj.panel, $('div', el)[1], 'contain panel as DOM div element');
equals(uiObj.index, 1, 'contain index');
});

})(jQuery);
56 changes: 36 additions & 20 deletions tests/unit/tabs/tabs_methods.js
Expand Up @@ -9,7 +9,7 @@ test('init', function() {
expect(9);

el = $('#tabs1').tabs();

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' );
Expand All @@ -23,68 +23,84 @@ test('init', function() {

test('destroy', function() {
expect(6);

el = $('#tabs1').tabs({ collapsible: true });
$('li:eq(2)', el).simulate('mouseover').find('a').focus();
el.tabs('destroy');

ok( el.is(':not(.ui-tabs, .ui-widget, .ui-widget-content, .ui-corner-all, .ui-tabs-collapsible)'), '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(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');
ok( $('li:eq(2)', el).is(':not(.ui-state-hover, .ui-state-focus)'), 'remove classes from mouseovered or focused li');
});

test('enable', function() {
ok(false, "missing test - untested code is broken code.");
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');
});

test('disable', function() {
ok(false, "missing test - untested code is broken code.");
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');
});

test('add', function() {
expect(4);

el = $('#tabs1').tabs();
el.tabs('add', "#new", 'New');
el.tabs('add', '#new', 'New');

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');

equals($('a', added).attr('href'), '#new', 'should not expand href to full url of current page');

ok(false, "missing test - untested code is broken code.");
});

test('remove', function() {
expect(4);

el = $('#tabs1').tabs();

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

el.tabs('select', 1);
el.tabs('remove', 1);
equals(el.tabs('option', 'selected'), 0, 'update selected property');
equals(el.tabs('option', 'selected'), 0, 'update selected property');
});

test('select', function() {
expect(9);

el = $('#tabs1').tabs();

el.tabs('select', 1);
equals(el.tabs('option', 'selected'), 1, 'should select tab');

Expand All @@ -97,11 +113,11 @@ test('select', function() {
el.tabs({ collapsible: true });
el.tabs('select', -1);
equals(el.tabs('option', 'selected'), -1, 'should collapse tab passing in -1');

el.tabs('destroy');
el.tabs({ collapsible: true });
el.tabs('select', null);
equals(el.tabs('option', 'selected'), -1, 'should collapse tab passing in null (deprecated)');
equals(el.tabs('option', 'selected'), -1, 'should collapse tab passing in null (deprecated)');
el.tabs('select', null);
equals(el.tabs('option', 'selected'), -1, 'should not select tab passing in null a second time (deprecated)');

Expand All @@ -113,7 +129,7 @@ test('select', function() {
equals(el.tabs('option', 'selected'), 0, 'should not collapse tab if collapsible is not set to true');
el.tabs('select', null);
equals(el.tabs('option', 'selected'), 0, 'should not collapse tab if collapsible is not set to true');

el.tabs('select', '#fragment-2');
equals(el.tabs('option', 'selected'), 1, 'should select tab by id');
});
Expand All @@ -128,7 +144,7 @@ test('url', function() {

test('length', function() {
expect(1);

el = $('#tabs1').tabs();
equals(el.tabs('length'), $('ul a', el).length, ' should return length');
});
Expand Down

0 comments on commit 73adda4

Please sign in to comment.