steal("jquerypp/controller", 'jquerypp/controller/subscribe').then('funcunit/qunit').then(function (){ module("jquerypp/controller"); test("subscribe testing works", function (){ var ta = $("
").appendTo($("#qunit-test-area")); ta.html("click here"); var clicks = 0, destroys = 0; var subscribes = 0; $.Controller.extend("MyTest", { click: function (){ clicks++ ; } , "a.b subscribe": function (){ subscribes++ ; } , destroy: function (){ this._super(); destroys++ ; } } ); ta.my_test(); ta.trigger("click"); equals(clicks, 1, "can listen to clicks"); OpenAjax.hub.publish("a.b", { } ); equals(subscribes, 1, "can subscribe"); var controllerInstance = ta.controller('my_test'); ok(controllerInstance.constructor == MyTest, "can get controller"); controllerInstance.destroy(); equals(destroys, 1, "destroy called once"); ok(!ta.controller(), "controller is removed"); OpenAjax.hub.publish("a.b", { } ); equals(subscribes, 1, "subscription is torn down"); ta.trigger("click"); equals(clicks, 1, "No longer listening"); ta.my_test(); ta.trigger("click"); OpenAjax.hub.publish("a.b", { } ); equals(clicks, 2, "can listen again to clicks"); equals(subscribes, 2, "can listen again to subscription"); ta.remove(); ta.trigger("click"); OpenAjax.hub.publish("a.b", { } ); equals(clicks, 2, "Clicks stopped"); equals(subscribes, 2, "Subscribes stopped"); } ); test("bind to any special", function (){ jQuery.event.special.crazyEvent = { } ; var called = false ; jQuery.Controller.extend("WeirdBind", { crazyEvent: function (){ called = true ; } } ); var a = $("").appendTo($("#qunit-test-area")); a.weird_bind(); a.trigger("crazyEvent"); ok(called, "heard the trigger"); $("#qunit-test-area").html(""); } ); test("parameterized actions", function (){ var called = false ; jQuery.Controller.extend("WeirderBind", { "{parameterized}": function (){ called = true ; } } ); var a = $("").appendTo($("#qunit-test-area")); a.weirder_bind({ parameterized: "sillyEvent"} ); a.trigger("sillyEvent"); ok(called, "heard the trigger"); $("#qunit-test-area").html(""); } ); test("windowresize", function (){ var called = false ; jQuery.Controller.extend("WindowBind", { "{window} resize": function (){ called = true ; } } ); $("#qunit-test-area").html("