Repository: wicket
Updated Branches:
  refs/heads/wicket-6.x 7fa49b9e3 -> 954c9e1e1


test for ajax init and done


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/954c9e1e
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/954c9e1e
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/954c9e1e

Branch: refs/heads/wicket-6.x
Commit: 954c9e1e1030c8827700d23bc9d2ba63b6806d3e
Parents: 7fa49b9
Author: Sven Meier <svenme...@apache.org>
Authored: Wed Jul 8 15:24:19 2015 +0200
Committer: Sven Meier <svenme...@apache.org>
Committed: Wed Jul 8 15:24:19 2015 +0200

----------------------------------------------------------------------
 wicket-core/src/test/js/ajax.js                 | 56 +++++++++++++++++---
 .../src/docs/guide/ajax/ajax_6.gdoc             |  2 +
 2 files changed, 50 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/954c9e1e/wicket-core/src/test/js/ajax.js
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/js/ajax.js b/wicket-core/src/test/js/ajax.js
index ff0b952..f12078a 100644
--- a/wicket-core/src/test/js/ajax.js
+++ b/wicket-core/src/test/js/ajax.js
@@ -31,6 +31,11 @@
 
                 </Directory>
 
+       ... or tweak wicket-examples' StartExamples.java like so:
+
+               bb.setContextPath("/ajax-tests");
+               bb.setWar("../wicket-core/src");
+
        then run it by opening "http://localhost/ajax-tests/test/js/all.html"; 
in the browser
 
  */
@@ -430,7 +435,7 @@ jQuery(document).ready(function() {
                 */
                asyncTest('verify default attributes.', function () {
 
-                       expect(24);
+                       expect(25);
 
                        var attrs = {
                                u: 'data/ajax/nonWicketResponse.json',
@@ -456,6 +461,7 @@ jQuery(document).ready(function() {
                                                ok(attributes.sh === undefined, 
'success handlers');
                                                ok(attributes.fh === undefined, 
'failure handlers');
                                                deepEqual(attrs.coh, 
attributes.coh, 'complete handlers');
+                                               ok(attributes.dh === undefined, 
'done handlers');
                                                ok(attributes.ep === undefined, 
'extra parameters');
                                                ok(attributes.dep === 
undefined, 'dynamic extra parameters');
                                                equal(attributes.async, true, 
'asynchronous');
@@ -471,7 +477,7 @@ jQuery(document).ready(function() {
 
                asyncTest('verify arguments to global listeners. Success 
scenario.', function () {
 
-                       expect(11);
+                       expect(13);
 
                        var attrs = {
                                u: 'data/ajax/nonWicketResponse.json',
@@ -480,6 +486,10 @@ jQuery(document).ready(function() {
                                wr: false // not Wicket's <ajax-response>
                        };
 
+                       Wicket.Event.subscribe('/ajax/call/init', 
function(jqEvent, attributes) {
+                               equal(attrs.u, attributes.u, 'Complete: attrs');
+                       });
+
                        Wicket.Event.subscribe('/ajax/call/success', 
function(jqEvent, attributes, jqXHR, data, textStatus) {
                                start();
                                var expected = {
@@ -511,6 +521,10 @@ jQuery(document).ready(function() {
                                ok(jQuery.isFunction(jqXHR.getResponseHeader), 
'Complete: Assert that jqXHR is a XMLHttpRequest');
                                equal('success', textStatus, 'Complete: 
textStatus');
                                equal(attrs.u, attributes.u, 'Complete: attrs');
+                       });
+
+                       Wicket.Event.subscribe('/ajax/call/done', 
function(jqEvent, attributes) {
+                               equal(attrs.u, attributes.u, 'Done: attrs');
 
                                // unregister all subscribers
                                Wicket.Event.unsubscribe();
@@ -525,7 +539,7 @@ jQuery(document).ready(function() {
 
                asyncTest('verify arguments to global listeners. Failure 
scenario.', function () {
 
-                       expect(11);
+                       expect(13);
 
                        var attrs = {
                                u: 'data/ajax/nonExisting.json',
@@ -534,6 +548,10 @@ jQuery(document).ready(function() {
                                wr: false // not Wicket's <ajax-response>
                        };
 
+                       Wicket.Event.subscribe('/ajax/call/init', 
function(jqEvent, attributes) {
+                               equal(attrs.u, attributes.u, 'Complete: attrs');
+                       });
+
                        Wicket.Event.subscribe('/ajax/call/success', 
function(jqEvent, attributes, jqXHR, data, textStatus) {
                                ok(false, 'Success handles should not be 
called');
                        });
@@ -560,6 +578,10 @@ jQuery(document).ready(function() {
                                ok(jQuery.isFunction(jqXHR.getResponseHeader), 
'Complete: Assert that jqXHR is a XMLHttpRequest');
                                equal('error', textStatus, 'Complete: 
textStatus');
                                equal(attrs.u, attributes.u, 'Complete: attrs');
+                       });
+
+                       Wicket.Event.subscribe('/ajax/call/done', 
function(jqEvent, attributes) {
+                               equal(attrs.u, attributes.u, 'Done: attrs');
 
                                // unregister all subscribers
                                Wicket.Event.unsubscribe();
@@ -748,18 +770,18 @@ jQuery(document).ready(function() {
 
                /**
                 * Verifies the order of execution of the callbacks.
-                * The order must be: before, precondition, beforeSend, after, 
success, complete.
+                * The order must be: before, precondition, beforeSend, after, 
success, complete, done.
                 * Three consecutive executions are made on the same Ajax 
channel validating
                 * that they do not overlap.
                 */
                asyncTest('callbacks order - success scenario.', function () {
 
-                       expect(36);
+                       expect(42);
 
                        var order = 0,
 
                        // the number of assertions per iteration
-                       numberOfTests = 12,
+                       numberOfTests = 14,
 
                        // calculates the offset for the order depending on the 
execution number
                        offset = function(extraData) {
@@ -804,6 +826,11 @@ jQuery(document).ready(function() {
                                        function(attrs) {
                                                equal((11 + 
offset(attrs.event.extraData)), ++order, "Complete handler");
                                        }
+                               ],
+                               dh: [
+                                       function(attrs) {
+                                               equal((13 + 
offset(attrs.event.extraData)), ++order, "Done handler");
+                                       }
                                ]
                        };
 
@@ -835,6 +862,10 @@ jQuery(document).ready(function() {
 
                        Wicket.Event.subscribe('/ajax/call/complete', 
function(jqEvent, attrs) {
                                equal((12 + offset(attrs.event.extraData)), 
++order, "Global complete handler");
+                       });
+
+                       Wicket.Event.subscribe('/ajax/call/done', 
function(jqEvent, attrs) {
+                               equal((14 + offset(attrs.event.extraData)), 
++order, "Global done handler");
 
                                if (attrs.event.extraData.round === 2) {
                                        // unregister all global subscribers
@@ -861,12 +892,12 @@ jQuery(document).ready(function() {
                 */
                asyncTest('callbacks order - failure scenario.', function () {
 
-                       expect(36);
+                       expect(42);
 
                        var order = 0,
 
                        // the number of assertions per iteration
-                       numberOfTests = 12,
+                       numberOfTests = 14,
 
                        // calculates the offset for the order depending on the 
execution number
                        offset = function(extraData) {
@@ -911,6 +942,11 @@ jQuery(document).ready(function() {
                                        function(attrs) {
                                                equal((11 + 
offset(attrs.event.extraData)), ++order, "Complete handler");
                                        }
+                               ],
+                               dh: [
+                                       function(attrs) {
+                                               equal((13 + 
offset(attrs.event.extraData)), ++order, "Done handler");
+                                       }
                                ]
                        };
 
@@ -942,6 +978,10 @@ jQuery(document).ready(function() {
 
                        Wicket.Event.subscribe('/ajax/call/complete', 
function(jqEvent, attrs) {
                                equal((12 + offset(attrs.event.extraData)), 
++order, "Global complete handler");
+                       });
+
+                       Wicket.Event.subscribe('/ajax/call/done', 
function(jqEvent, attrs) {
+                               equal((14 + offset(attrs.event.extraData)), 
++order, "Global done handler");
 
                                if (attrs.event.extraData.round === 2) {
                                        // unregister all global subscribers

http://git-wip-us.apache.org/repos/asf/wicket/blob/954c9e1e/wicket-user-guide/src/docs/guide/ajax/ajax_6.gdoc
----------------------------------------------------------------------
diff --git a/wicket-user-guide/src/docs/guide/ajax/ajax_6.gdoc 
b/wicket-user-guide/src/docs/guide/ajax/ajax_6.gdoc
index 1ca5e55..50c80ec 100644
--- a/wicket-user-guide/src/docs/guide/ajax/ajax_6.gdoc
+++ b/wicket-user-guide/src/docs/guide/ajax/ajax_6.gdoc
@@ -141,12 +141,14 @@ So far we have seen how to use an AJAX call listener to 
track the AJAX activity
 
 Global AJAX call events are handled with JavaScript. We can register a 
callback function for a specific event of the AJAX call lifecycle with function 
@Wicket.Event.subscribe('<eventName>', <callback Function>)@. The first 
parameter of this function is the name of the event we want to handle. The 
possible names are:
 
+* '/ajax/call/init': called on initialization of an ajax call
 * '/ajax/call/before': called before any other event handler.
 * '/ajax/call/beforeSend': called just before the AJAX call.
 * '/ajax/call/after': called after the AJAX request has been sent.
 * '/ajax/call/success': called if the AJAX call has successfully returned.
 * '/ajax/call/failure': called if the AJAX call has returned with a failure.
 * '/ajax/call/complete': called when the AJAX call has completed.
+* '/ajax/call/done': called when the AJAX call is done.
 * '/dom/node/removing': called when a component is about to be removed via 
AJAX. This  happens when component markup is updated via AJAX (i.e. the 
component itself or one of its containers has been added to 
@AjaxRequestTarget@) 
 * '/dom/node/added': called when a component has been added via AJAX. Just 
like '/dom/node/removing', this event is triggered when a component is added to 
@AjaxRequestTarget@.
 

Reply via email to