added tests for enable/disable

This commit is contained in:
carhartl 2010-04-20 02:38:04 +08:00 committed by Richard D. Worth
parent 970ed9a67a
commit 73adda4146
2 changed files with 70 additions and 27 deletions

View File

@ -22,15 +22,17 @@ test('show', function() {
uiObj = ui; uiObj = ui;
} }
}); });
ok(uiObj !== undefined, 'should fire show after init'); ok(uiObj !== undefined, 'trigger callback after initialization');
equals(uiObj.tab, $('#tabs1 a')[0], 'should have tab as DOM anchor element'); equals(uiObj.tab, $('a', el)[0], 'contain tab as DOM anchor element');
equals(uiObj.panel, $('#tabs1 div')[0], 'should have panel as DOM div element'); equals(uiObj.panel, $('div', el)[0], 'contain panel as DOM div element');
equals(uiObj.index, 0, 'should have index'); equals(uiObj.index, 0, 'contain index');
}); });
test('add', function() { test('add', function() {
// TODO move to methods, not at all event related...
var el = $('<div id="tabs"><ul></ul></div>').tabs(); var el = $('<div id="tabs"><ul></ul></div>').tabs();
equals(el.tabs('option', 'selected'), -1, 'Initially empty, no selected tab'); equals(el.tabs('option', 'selected'), -1, 'Initially empty, no selected tab');
@ -47,11 +49,36 @@ test('remove', function() {
}); });
test('enable', 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() { 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); })(jQuery);

View File

@ -37,18 +37,34 @@ test('destroy', function() {
}); });
test('enable', function() { 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() { 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() { test('add', function() {
expect(4); expect(4);
el = $('#tabs1').tabs(); el = $('#tabs1').tabs();
el.tabs('add', "#new", 'New'); el.tabs('add', '#new', 'New');
var added = $('li:last', el).simulate('mouseover'); var added = $('li:last', el).simulate('mouseover');
ok(added.is('.ui-state-hover'), 'should add mouseover handler to added tab'); ok(added.is('.ui-state-hover'), 'should add mouseover handler to added tab');