WICKET-4364 Think of a way to reintroduce show|hideIncrementally with the new Ajax impl
Add a unit test verifying that the indicator is set to 0 at the end. Three requests are fired simultaneously - one successful, one failing due to error 404 and one that doesn't fire because of a precondition. Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/4967decb Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/4967decb Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/4967decb Branch: refs/heads/master Commit: 4967decb28654a6717d31a6fe0f5019c4e994edb Parents: 0e1199e Author: Martin Tzvetanov Grigorov <[email protected]> Authored: Mon Feb 6 10:18:47 2012 +0200 Committer: Martin Tzvetanov Grigorov <[email protected]> Committed: Mon Feb 6 10:18:47 2012 +0200 ---------------------------------------------------------------------- wicket-core/src/test/js/ajax.js | 79 ++++++++++++++++++++++++++++++++++ 1 files changed, 79 insertions(+), 0 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/4967decb/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 77398d4..e12672f 100644 --- a/wicket-core/src/test/js/ajax.js +++ b/wicket-core/src/test/js/ajax.js @@ -541,5 +541,84 @@ jQuery(document).ready(function() { }); + asyncTest('show/hide incrementally (WICKET-4364)', function() { + + expect(4); + + var $indicator = jQuery('<div id="indicator"></div>'); + var $el = jQuery('<div id="elementId"></div>'); + jQuery('#qunit-fixture') + .append($indicator) + .append($el); + + // counts how many complete handlers have been executed + var calls = 0; + + // returns the number of 'shows' of the indicator + var getCurrentCount = function () { + var count = $indicator.attr('showIncrementallyCount'); + return count ? parseInt(count, 10) : 0; + } + + // called as 'success' for requestOne and as 'failure' for requestTwo + var successFailureHandler = function () { + var count = getCurrentCount(); + ok(count === 1 || count === 2, "'showIncrementallyCount' must be 1 or 2. Value is: " + count); + }; + + // notifies when the last (second) complete handler is done + var deferred = jQuery.Deferred(); + + var completeHandler = function () { + if (++calls === 2) { + deferred.resolve(); + } + }; + + var attrs = { + u: 'data/ajax/nonWicketResponse.json', + e: 'event1', + i: $indicator.attr('id'), + c: $el.attr('id'), + dt: 'json', // datatype + sh: [ successFailureHandler ], + fh: [ successFailureHandler ], + coh: [ completeHandler ], + wr: false // not Wicket's <ajax-response> + }; + + // binds requestOne (success) + Wicket.Ajax.ajax(attrs); + + var attrsTwo = jQuery.extend({}, attrs, { + u: 'data/ajax/nonExisting.json' + }); + // binds requestTwo (failure - non-existing URL => error 404) + Wicket.Ajax.ajax(attrsTwo); + + var attrsThree = jQuery.extend({}, attrs, { + pre: [ + function () { + ok(true, 'Request 3: Precondition called.') + return false; + } + ] + }); + // binds requestThree - not executed due to precondition + Wicket.Ajax.ajax(attrsThree); + + // executed when the last request is in its 'onComplete' phase. + jQuery.when(deferred) + .done(function () { + start(); + var count = getCurrentCount(); + equal(0, count, "'showIncrementallyCount' must be 0 after the executions but is: " + count); + $indicator.remove(); + $el.off().remove(); + }); + + // fire all requests + $el.triggerHandler("event1"); + }); } });
