diff options
author | Jörn Zaefferer <joern.zaefferer@gmail.com> | 2011-07-29 14:00:00 +0200 |
---|---|---|
committer | Jörn Zaefferer <joern.zaefferer@gmail.com> | 2011-07-29 14:00:00 +0200 |
commit | 982b752c3507f8e8512ca02f365a2d854d65a5cc (patch) | |
tree | d5ca7624fa6d3bd99120538fd7ab235ce41fad99 /tests | |
parent | 61caba7803d1c3885a8e2a6cd3c1e8b723e8beee (diff) | |
parent | 0ff3396e8853d1858db56e4ad7552f87c09e5504 (diff) | |
download | jquery-ui-982b752c3507f8e8512ca02f365a2d854d65a5cc.tar.gz jquery-ui-982b752c3507f8e8512ca02f365a2d854d65a5cc.zip |
Merge branch 'widget-delegation'
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/widget/widget_core.js | 53 |
1 files changed, 43 insertions, 10 deletions
diff --git a/tests/unit/widget/widget_core.js b/tests/unit/widget/widget_core.js index 9d915291a..8cacdd47d 100644 --- a/tests/unit/widget/widget_core.js +++ b/tests/unit/widget/widget_core.js @@ -89,7 +89,7 @@ test( "jQuery usage", function() { "parameter passed via .pluginName(methodName, param)" ); equals( param2, "value2", "multiple parameters passed via .pluginName(methodName, param, param)" ); - + return this; }, getterSetterMethod: function( val ) { @@ -153,9 +153,9 @@ test( "direct usage", function() { } } }); - + var elem = $( "<div>" )[ 0 ]; - + shouldCreate = true; var instance = new $.ui.testWidget( {}, elem ); shouldCreate = false; @@ -163,7 +163,7 @@ test( "direct usage", function() { equals( $( elem ).data( "testWidget" ), instance, "instance stored in .data(pluginName)" ); equals( instance.element[ 0 ], elem, "element stored on widget" ); - + var ret = instance.methodWithParams( "value1", "value2" ); equals( ret, instance, "plugin returned from method call" ); @@ -193,7 +193,7 @@ test( "error handling", function() { equal( msg, "no such method '_privateMethod' for testWidget widget instance", "invalid method call on widget instance" ); }; - $( "<div>" ).testWidget().testWidget( "_privateMethod" ); + $( "<div>" ).testWidget().testWidget( "_privateMethod" ); $.error = error; }); @@ -463,7 +463,7 @@ test( ".option() - delegate to ._setOptions()", function() { calls = []; div.testWidget( "option", "foo", "bar" ); same( calls, [{ foo: "bar" }], "_setOptions called for single option" ); - + calls = []; div.testWidget( "option", { bar: "qux", @@ -490,7 +490,7 @@ test( ".option() - delegate to ._setOption()", function() { div.testWidget( "option", "foo", "bar" ); same( calls, [{ key: "foo", val: "bar" }], "_setOption called for single option" ); - + calls = []; div.testWidget( "option", { bar: "qux", @@ -666,6 +666,39 @@ test( "._bind() to descendent", function() { .trigger( "keydown" ); }); +test( "_bind() with delegate", function() { + expect( 8 ); + $.widget( "ui.testWidget", { + _create: function() { + this.element = { + bind: function( event, handler ) { + equal( event, "click.testWidget" ); + ok( $.isFunction(handler) ); + }, + delegate: function( selector, event, handler ) { + equal( selector, "a" ); + equal( event, "click.testWidget" ); + ok( $.isFunction(handler) ); + }, + trigger: $.noop + }; + this._bind({ + "click": "handler", + "click a": "handler", + }); + this.element.delegate = function( selector, event, handler ) { + equal( selector, "form fieldset > input" ); + equal( event, "change.testWidget" ); + ok( $.isFunction(handler) ); + }; + this._bind({ + "change form fieldset > input": "handler" + }); + } + }); + $.ui.testWidget(); +}); + test( "._hoverable()", function() { $.widget( "ui.testWidget", { _create: function() { @@ -703,14 +736,14 @@ test( "._focusable()", function() { this._focusable( this.element.children() ); } }); - + var div = $( "#widget" ).testWidget().children(); ok( !div.hasClass( "ui-state-focus" ), "not focused on init" ); div.trigger( "focusin" ); ok( div.hasClass( "ui-state-focus" ), "focused after explicit focus" ); div.trigger( "focusout" ); ok( !div.hasClass( "ui-state-focus" ), "not focused after blur" ); - + div.trigger( "focusin" ); ok( div.hasClass( "ui-state-focus" ), "focused after explicit focus" ); $( "#widget" ).testWidget( "disable" ); @@ -719,7 +752,7 @@ test( "._focusable()", function() { ok( !div.hasClass( "ui-state-focus" ), "can't focus while disabled" ); $( "#widget" ).testWidget( "enable" ); ok( !div.hasClass( "ui-state-focus" ), "enabling doesn't reset focus" ); - + div.trigger( "focusin" ); ok( div.hasClass( "ui-state-focus" ), "focused after explicit focus" ); $( "#widget" ).testWidget( "destroy" ); |