]> source.dussan.org Git - vaadin-framework.git/commitdiff
Always show loading indicator for JavaScript RPC (#20235)
authorArtur Signell <artur@vaadin.com>
Wed, 7 Sep 2016 19:21:40 +0000 (22:21 +0300)
committerArtur Signell <artur@vaadin.com>
Thu, 8 Sep 2016 19:12:59 +0000 (22:12 +0300)
The change to not show loading indicator for JS RPC was done in
15a53d305e6648572c11cb988f4988c2c5825af1 and looks like a refactoring
error.

Change-Id: If2a2818e0c4adc06479ecaf17764bf53fc89c095

client/src/main/java/com/vaadin/client/communication/ServerRpcQueue.java
uitest/src/main/java/com/vaadin/tests/components/javascriptcomponent/JSComponentLoadingIndicator.java [new file with mode: 0644]
uitest/src/main/resources/com/vaadin/tests/components/javascriptcomponent/JSComponent.js [new file with mode: 0644]
uitest/src/test/java/com/vaadin/tests/components/javascriptcomponent/JSComponentLoadingIndicatorTest.java [new file with mode: 0644]
uitest/src/test/java/com/vaadin/tests/tb3/AbstractTB3Test.java

index e5d5ea8a251775e0e13cdccabaa0bee793f78c2a..f6d2097e984bc39572bda2aba2a723d6196176fc 100644 (file)
@@ -226,10 +226,12 @@ public class ServerRpcQueue {
      */
     public boolean showLoadingIndicator() {
         for (MethodInvocation invocation : getAll()) {
-            if (isLegacyVariableChange(invocation)) {
-                // Always show loading indicator for legacy requests
+            if (isLegacyVariableChange(invocation)
+                    || isJavascriptRpc(invocation)) {
+                // Always show loading indicator for legacy and JS requests as
+                // they have no @NoLoadingIndicator they can use
                 return true;
-            } else if (!isJavascriptRpc(invocation)) {
+            } else {
                 Type type = new Type(invocation.getInterfaceName(), null);
                 Method method = type.getMethod(invocation.getMethodName());
                 if (!TypeDataStore.isNoLoadingIndicator(method)) {
diff --git a/uitest/src/main/java/com/vaadin/tests/components/javascriptcomponent/JSComponentLoadingIndicator.java b/uitest/src/main/java/com/vaadin/tests/components/javascriptcomponent/JSComponentLoadingIndicator.java
new file mode 100644 (file)
index 0000000..67795d6
--- /dev/null
@@ -0,0 +1,38 @@
+package com.vaadin.tests.components.javascriptcomponent;
+
+import com.vaadin.annotations.JavaScript;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.AbstractJavaScriptComponent;
+import com.vaadin.ui.JavaScriptFunction;
+import com.vaadin.ui.Label;
+
+import elemental.json.JsonArray;
+
+public class JSComponentLoadingIndicator extends AbstractTestUI {
+
+    @JavaScript({ "JSComponent.js" })
+    public class JSComponent extends AbstractJavaScriptComponent {
+        public JSComponent() {
+            addFunction("test", new JavaScriptFunction() {
+                @Override
+                public void call(JsonArray arguments) {
+                    try {
+                        Thread.sleep(1000);
+                        Label label = new Label("pong");
+                        label.addStyleName("pong");
+                        addComponent(label);
+                    } catch (InterruptedException e) {
+                        e.printStackTrace();
+                    }
+                }
+            });
+        }
+    }
+
+    @Override
+    protected void setup(VaadinRequest request) {
+        addComponent(new JSComponent());
+    }
+
+}
diff --git a/uitest/src/main/resources/com/vaadin/tests/components/javascriptcomponent/JSComponent.js b/uitest/src/main/resources/com/vaadin/tests/components/javascriptcomponent/JSComponent.js
new file mode 100644 (file)
index 0000000..522654a
--- /dev/null
@@ -0,0 +1,11 @@
+com_vaadin_tests_components_javascriptcomponent_JSComponentLoadingIndicator_JSComponent = function()
+{
+       var connector = this;
+       var e = this.getElement();
+
+       e.innerText="click me to ping server";
+       e.id="js";
+       e.addEventListener("click", function() {
+               connector.test();
+       });
+}
\ No newline at end of file
diff --git a/uitest/src/test/java/com/vaadin/tests/components/javascriptcomponent/JSComponentLoadingIndicatorTest.java b/uitest/src/test/java/com/vaadin/tests/components/javascriptcomponent/JSComponentLoadingIndicatorTest.java
new file mode 100644 (file)
index 0000000..c88ea23
--- /dev/null
@@ -0,0 +1,29 @@
+package com.vaadin.tests.components.javascriptcomponent;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.By;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class JSComponentLoadingIndicatorTest extends SingleBrowserTest {
+
+    @Test
+    public void ensureLoadingIndicatorShown() {
+        openTestURL();
+        testBench().disableWaitForVaadin();
+
+        WebElement js = findElement(By.id("js"));
+        js.click();
+        waitUntilLoadingIndicatorVisible();
+        waitUntilLoadingIndicatorNotVisible();
+        Assert.assertEquals(1, findElements(By.className("pong")).size());
+
+        js.click();
+        waitUntilLoadingIndicatorVisible();
+        waitUntilLoadingIndicatorNotVisible();
+        Assert.assertEquals(2, findElements(By.className("pong")).size());
+    }
+
+}
index 7029abd9ac09c1bc393fba32fd4322d4e56ad227..992a1376c88adcf39d288e158109f3c031053d30 100644 (file)
@@ -1015,15 +1015,20 @@ public abstract class AbstractTB3Test extends ParallelTest {
         return loadingIndicator.isDisplayed();
     }
 
-    protected void waitUntilLoadingIndicatorNotVisible() {
+    protected void waitUntilLoadingIndicatorVisible() {
         waitUntil(new ExpectedCondition<Boolean>() {
-
             @Override
             public Boolean apply(WebDriver input) {
-                WebElement loadingIndicator = input.findElement(By
-                        .className("v-loading-indicator"));
+                return isLoadingIndicatorVisible();
+            }
+        });
+    }
 
-                return !loadingIndicator.isDisplayed();
+    protected void waitUntilLoadingIndicatorNotVisible() {
+        waitUntil(new ExpectedCondition<Boolean>() {
+            @Override
+            public Boolean apply(WebDriver input) {
+                return !isLoadingIndicatorVisible();
             }
         });
     }