WICKET-5901 Leaving veil when ajax processing ends with redirect

Add unit tests for preserving the ajax indicator until page unload (if there is 
redirect)

(cherry picked from commit 22e6f69b3896c011f113f6d97957e6cd46304223)


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

Branch: refs/heads/WICKET-5906-7.x
Commit: b8b711117367aab897d73033a86f916623f9954e
Parents: eea5c7a
Author: Martin Tzvetanov Grigorov <[email protected]>
Authored: Sat May 30 15:51:03 2015 +0300
Committer: Andrea Del Bene <“[email protected]”>
Committed: Wed Jun 3 10:04:20 2015 +0200

----------------------------------------------------------------------
 .../wicket/ajax/res/js/wicket-ajax-jquery.js    | 15 ++++--
 wicket-core/src/test/js/ajax.js                 | 54 ++++++++++++++++++++
 wicket-core/src/test/js/all.html                |  2 +
 .../test/js/data/ajax/redirectAjaxResponse.xml  | 18 +++++++
 4 files changed, 86 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/b8b71111/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js 
b/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
index 88d3983..e62451f 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
+++ 
b/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
@@ -767,7 +767,7 @@
                                        // support/check for non-relative 
redirectUrl like as provided and needed in a portlet context
                                        if (redirectUrl.charAt(0) === '/' || 
rhttp.test(redirectUrl) || rhttps.test(redirectUrl)) {
                                                context.isRedirecting = true;
-                                               window.location = redirectUrl;
+                                               
Wicket.Ajax.redirect(redirectUrl);
                                        }
                                        else {
                                                var urlDepth = 0;
@@ -792,7 +792,7 @@
                                                }
 
                                                context.isRedirecting = true;
-                                               window.location = 
calculatedRedirect;
+                                               
Wicket.Ajax.redirect(calculatedRedirect);
                                        }
                                }
                                else {
@@ -1241,7 +1241,7 @@
                        var text = Wicket.DOM.text(node);
                        Wicket.Log.info("Redirecting to: " + text);
                        context.isRedirecting = true;
-                       window.location = text;
+                       Wicket.Ajax.redirect(text);
                },
 
                // mark the focused component so that we know if it has been 
replaced by response
@@ -1972,6 +1972,15 @@
                        process: function(data) {
                                var call = new Wicket.Ajax.Call();
                                call.process(data);
+                       },
+
+                       /**
+                        * An abstraction over native window.location.replace() 
to be able to suppress it for unit tests
+                        *
+                        * @param url The url to redirect to
+                        */
+                       redirect: function(url) {
+                               window.location = url;
                        }
                },
 

http://git-wip-us.apache.org/repos/asf/wicket/blob/b8b71111/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 d969d6d..9adf553 100644
--- a/wicket-core/src/test/js/ajax.js
+++ b/wicket-core/src/test/js/ajax.js
@@ -1288,5 +1288,59 @@ jQuery(document).ready(function() {
                        target.off("event1");
                });
 
+               asyncTest('Do not hide the indicator if redirecting.', function 
() {
+
+                       expect(2);
+
+                       var oldRedirect = Wicket.Ajax.redirect;
+                       Wicket.Ajax.redirect = function() {};
+
+                       var attrs = {
+                               u: 'data/ajax/redirectAjaxResponse.xml',
+                               e: 'event1',
+                               i: 'ajaxIndicator',
+                               sh: [function(attrs, jqXHR, data, textStatus) {
+                                       var indicatorEl = Wicket.$(attrs.i);
+                                       equal("1", 
indicatorEl.getAttribute("showIncrementallyCount"));
+                               }],
+                               coh: [function(attrs, jqXHR, textStatus) {
+                                       var indicatorEl = Wicket.$(attrs.i);
+                                       equal("1", 
indicatorEl.getAttribute("showIncrementallyCount"));
+                                       Wicket.Ajax.redirect = oldRedirect;
+                                       start();
+                               }]
+                       };
+
+                       Wicket.Ajax.ajax(attrs);
+                       var target = jQuery(window);
+                       target.triggerHandler("event1");
+                       target.off("event1");
+               });
+
+               asyncTest('Do hide the indicator if not redirecting.', function 
() {
+
+                       expect(2);
+
+                       var attrs = {
+                               u: 'data/ajax/emptyAjaxResponse.xml',
+                               e: 'event1',
+                               i: 'ajaxIndicator',
+                               sh: [function(attrs, jqXHR, data, textStatus) {
+                                       var indicatorEl = Wicket.$(attrs.i);
+                                       equal("1", 
indicatorEl.getAttribute("showIncrementallyCount"));
+                               }],
+                               coh: [function(attrs, jqXHR, textStatus) {
+                                       var indicatorEl = Wicket.$(attrs.i);
+                                       equal("0", 
indicatorEl.getAttribute("showIncrementallyCount"));
+                                       start();
+                               }]
+                       };
+
+                       Wicket.Ajax.ajax(attrs);
+                       var target = jQuery(window);
+                       target.triggerHandler("event1");
+                       target.off("event1");
+               });
+
        }
 });

http://git-wip-us.apache.org/repos/asf/wicket/blob/b8b71111/wicket-core/src/test/js/all.html
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/js/all.html b/wicket-core/src/test/js/all.html
index b58688f..6a03f52 100644
--- a/wicket-core/src/test/js/all.html
+++ b/wicket-core/src/test/js/all.html
@@ -169,6 +169,8 @@
                <div id="usedAsContextWicket5025"></div>
 
                <input type="text" id="inputChangeInput">
+
+               <div id="ajaxIndicator"></div>
        </div>
 </body>
 </html>

http://git-wip-us.apache.org/repos/asf/wicket/blob/b8b71111/wicket-core/src/test/js/data/ajax/redirectAjaxResponse.xml
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/js/data/ajax/redirectAjaxResponse.xml 
b/wicket-core/src/test/js/data/ajax/redirectAjaxResponse.xml
new file mode 100644
index 0000000..19d89e7
--- /dev/null
+++ b/wicket-core/src/test/js/data/ajax/redirectAjaxResponse.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+        http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+-->
+<ajax-response><redirect><![CDATA[http://127.0.0.1]]></redirect></ajax-response>

Reply via email to