diff options
author | mensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f> | 2008-11-13 09:49:11 +0000 |
---|---|---|
committer | mensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f> | 2008-11-13 09:49:11 +0000 |
commit | e44a7e37b6c7b5961adaffc62b9042b8d442938e (patch) | |
tree | 95b67c356e93163467db2451f2b8cce84ed5d582 /includes/js/dojo/tests/DeferredList.js | |
parent | a62b9742ee5e28bcec6872d88f50f25b820914f6 (diff) | |
download | semanticscuttle-e44a7e37b6c7b5961adaffc62b9042b8d442938e.tar.gz semanticscuttle-e44a7e37b6c7b5961adaffc62b9042b8d442938e.tar.bz2 |
New feature: basic Ajax suggestion for tags and implementation of Dojo toolkit
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@151 b3834d28-1941-0410-a4f8-b48e95affb8f
Diffstat (limited to 'includes/js/dojo/tests/DeferredList.js')
-rw-r--r-- | includes/js/dojo/tests/DeferredList.js | 206 |
1 files changed, 206 insertions, 0 deletions
diff --git a/includes/js/dojo/tests/DeferredList.js b/includes/js/dojo/tests/DeferredList.js new file mode 100644 index 0000000..9353bfa --- /dev/null +++ b/includes/js/dojo/tests/DeferredList.js @@ -0,0 +1,206 @@ +if(!dojo._hasResource["tests.DeferredList"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["tests.DeferredList"] = true; +dojo.provide("tests.DeferredList"); + +dojo.require("dojo.DeferredList"); + +doh.register("tests.DeferredList", + [ + function callback(t){ + var d1 = new dojo.Deferred(); + var d2 = new dojo.Deferred(); + var dl = new dojo.DeferredList([d1, d2]); + var fired = false; + + dl.addCallback(function(res){ + doh.debug("debug from dojo.DeferredList callback"); + return res; + }); + dl.addCallback(function(res){ + console.log("res: ", res, res.length); + t.assertTrue(res.length == 2); + t.assertTrue(res[0][0]); + t.assertEqual(res[0][1], "foo"); + t.assertTrue(res[1][0]); + t.assertEqual(res[1][1], "bar"); + fired = true; + return res; + }); + d1.callback("foo"); + d2.callback("bar"); + t.assertTrue(fired); + }, + + function errback(t){ + var d1 = new dojo.Deferred(); + var d2 = new dojo.Deferred(); + var dl = new dojo.DeferredList([d1, d2]); + var fired = false; + var e1 = new Error("foo"); + var e2 = new Error("bar"); + + dl.addCallback(function(res){ + doh.debug("debug from dojo.DeferredList callback"); + return res; + }); + dl.addCallback(function(res){ + t.assertTrue(res.length == 2); + t.assertTrue(!res[0][0]); + + t.assertEqual(res[0][1], e1); + t.assertTrue(!res[1][0]); + t.assertEqual(res[1][1], e2); + fired = true; + return res; + }); + d1.errback(e1); + d2.errback(e2); + t.assertTrue(fired); + }, + + + function mixed(t){ + var d1 = new dojo.Deferred(); + var d2 = new dojo.Deferred(); + var dl = new dojo.DeferredList([d1, d2]); + var fired = false; + var e = new Error("foo"); + + dl.addCallback(function(res){ + doh.debug("debug from dojo.DeferredList callback"); + return res; + }); + dl.addCallback(function(res){ + t.assertTrue(res.length == 2); + t.assertTrue(!res[0][0]); + + t.assertEqual(res[0][1], e); + t.assertTrue(res[1][0]); + t.assertEqual(res[1][1], "bar"); + fired = true; + return res; + }); + d1.errback(e); + d2.callback("bar"); + t.assertTrue(fired); + }, + + function gather(t){ + var d1 = new dojo.Deferred(); + var d2 = new dojo.Deferred(); + var dl = dojo.DeferredList.prototype.gatherResults([d1, d2]); + var fired = false; + dl.addCallback(function(res){ + t.assertEqual(res[0], "foo"); + t.assertEqual(res[1], "bar"); + fired = true; + return res; + }); + d1.callback("foo"); + d2.callback("bar"); + t.assertTrue(fired); + } + ] +); +dojo.provide("tests.DeferredList"); + +dojo.require("dojo.DeferredList"); + +doh.register("tests.DeferredList", + [ + function callback(t){ + var d1 = new dojo.Deferred(); + var d2 = new dojo.Deferred(); + var dl = new dojo.DeferredList([d1, d2]); + var fired = false; + dl.addCallback(function(res){ + doh.debug("debug from dojo.DeferredList callback"); + return res; + }); + dl.addCallback(function(res){ + t.assertTrue(res.length == 2); + t.assertTrue(res[0][0]); + t.assertEqual(res[0][1], "foo"); + t.assertTrue(res[1][0]); + t.assertEqual(res[1][1], "bar"); + fired = true; + return res; + }); + d1.callback("foo"); + d2.callback("bar"); + t.assertTrue(fired); + }, + + function errback(t){ + var d1 = new dojo.Deferred(); + var d2 = new dojo.Deferred(); + var dl = new dojo.DeferredList([d1, d2]); + var fired = false; + var e1 = new Error("foo"); + var e2 = new Error("bar"); + + dl.addCallback(function(res){ + doh.debug("debug from dojo.DeferredList callback"); + return res; + }); + dl.addCallback(function(res){ + t.assertTrue(res.length == 2); + t.assertTrue(!res[0][0]); + + t.assertEqual(res[0][1], e1); + t.assertTrue(!res[1][0]); + t.assertEqual(res[1][1], e2); + fired = true; + return res; + }); + d1.errback(e1); + d2.errback(e2); + t.assertTrue(fired); + }, + + + function mixed(t){ + var d1 = new dojo.Deferred(); + var d2 = new dojo.Deferred(); + var dl = new dojo.DeferredList([d1, d2]); + var fired = false; + var e = new Error("foo"); + + dl.addCallback(function(res){ + doh.debug("debug from dojo.DeferredList callback"); + return res; + }); + dl.addCallback(function(res){ + t.assertTrue(res.length == 2); + t.assertTrue(!res[0][0]); + + t.assertEqual(res[0][1], e); + t.assertTrue(res[1][0]); + t.assertEqual(res[1][1], "bar"); + fired = true; + return res; + }); + d1.errback(e); + d2.callback("bar"); + t.assertTrue(fired); + }, + + function gather(t){ + var d1 = new dojo.Deferred(); + var d2 = new dojo.Deferred(); + var dl = dojo.DeferredList.prototype.gatherResults([d1, d2]); + var fired = false; + dl.addCallback(function(res){ + t.assertEqual(res[0], "foo"); + t.assertEqual(res[1], "bar"); + fired = true; + return res; + }); + d1.callback("foo"); + d2.callback("bar"); + t.assertTrue(fired); + } + ] +); + +} |