diff options
author | Scott González <scott.gonzalez@gmail.com> | 2010-08-26 10:50:26 -0400 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2010-08-26 10:50:26 -0400 |
commit | 001b4b08f0cfff8f69a61662ebebdcd8dce2dacb (patch) | |
tree | 10fbc8463203817f2bb74b5a5016e4fa1d0b683a | |
parent | da2be6a2af88ab6e81cc64282abcc1c2703c43bb (diff) | |
download | jquery-ui-001b4b08f0cfff8f69a61662ebebdcd8dce2dacb.tar.gz jquery-ui-001b4b08f0cfff8f69a61662ebebdcd8dce2dacb.zip |
Widget: Added more unit tests.
-rw-r--r-- | tests/unit/widget/widget_core.js | 95 |
1 files changed, 89 insertions, 6 deletions
diff --git a/tests/unit/widget/widget_core.js b/tests/unit/widget/widget_core.js index 39cdf3e9c..63ea31576 100644 --- a/tests/unit/widget/widget_core.js +++ b/tests/unit/widget/widget_core.js @@ -35,8 +35,10 @@ test('jQuery usage', function() { }, methodWithParams: function(param1, param2) { ok(true, 'method called via .pluginName(methodName)'); - equals(param1, 'value1', 'parameter passed via .pluginName(methodName, param)'); - equals(param2, 'value2', 'multiple parameter passed via .pluginName(methodName, param, param)'); + equals(param1, 'value1', + 'parameter passed via .pluginName(methodName, param)'); + equals(param2, 'value2', + 'multiple parameters passed via .pluginName(methodName, param, param)'); return this; }, @@ -77,9 +79,9 @@ test('direct usage', function() { ok(shouldInit, 'init called on instantiation'); }, methodWithParams: function(param1, param2) { - ok(true, 'method called via .pluginName(methodName)'); - equals(param1, 'value1', 'parameter passed via .pluginName(methodName, param)'); - equals(param2, 'value2', 'multiple parameter passed via .pluginName(methodName, param, param)'); + ok(true, 'method called dirctly'); + equals(param1, 'value1', 'parameter passed via direct call'); + equals(param2, 'value2', 'multiple parameters passed via direct call'); return this; }, @@ -175,11 +177,92 @@ test("re-init", function() { same( actions, [ "optionfoo", "init" ], "correct methods called on re-init with options" ); }); +test( ".option() - getter", function() { + $.widget( "ui.testWidget", { + _create: function() {} + }); + + var div = $( "<div></div>" ).testWidget({ + foo: "bar", + baz: 5, + qux: [ "quux", "quuux" ] + }); + + same( div.testWidget( "option", "foo"), "bar", "single option - string" ); + same( div.testWidget( "option", "baz"), 5, "single option - number" ); + same( div.testWidget( "option", "qux"), [ "quux", "quuux" ], + "single option - array" ); + + var options = div.testWidget( "option" ); + same( options, { + disabled: false, + foo: "bar", + baz: 5, + qux: [ "quux", "quuux" ] + }, "full options hash returned" ); + options.foo = "notbar"; + same( div.testWidget( "option", "foo"), "bar", + "modifying returned options hash does not modify plugin instance" ); +}); + +test( ".option() - setter", function() { + var calls = []; + $.widget( "ui.testWidget", { + _create: function() {}, + _setOption: function( key, val ) { + calls.push({ + key: key, + val: val + }); + } + }); + var div = $( "<div></div>" ).testWidget(); + + calls = []; + div.testWidget( "option", "foo", "bar" ); + same( calls, [{ key: "foo", val: "bar" }], + "_setOption called for single option" ); + + calls = []; + div.testWidget( "option", { + bar: "qux", + quux: "quuux" + }); + same( calls, [ + { key: "bar", val: "qux" }, + { key: "quux", val: "quuux" } + ], "_setOption called with multiple options" ); +}); + +test( ".enable()", function() { + expect( 2 ); + $.widget("ui.testWidget", { + _create: function() {}, + _setOption: function( key, val ) { + same( key, "disabled", "_setOption called with disabled option" ); + same( val, false, "disabled set to false" ); + } + }); + $( "<div></div>" ).testWidget().testWidget( "enable" ); +}); + +test( ".disable()", function() { + expect( 2 ); + $.widget("ui.testWidget", { + _create: function() {}, + _setOption: function( key, val ) { + same( key, "disabled", "_setOption called with disabled option" ); + same( val, true, "disabled set to true" ); + } + }); + $( "<div></div>" ).testWidget().testWidget( "disable" ); +}); + test(".widget() - base", function() { $.widget("ui.testWidget", { _create: function() {} }); - var div = $("<div></div>").testWidget() + var div = $("<div></div>").testWidget(); same(div[0], div.testWidget("widget")[0]); }); |