diff options
author | Artur Signell <artur@vaadin.com> | 2016-09-07 22:21:40 +0300 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2016-09-08 22:12:59 +0300 |
commit | c970a78d42a2d8f1745df7a11a74f3731f8be9a5 (patch) | |
tree | 01a122e1f733f32e0a0ef95aa3dd57acbc765bce | |
parent | ad67f7f43afb0feec5e029aea90297f2abe4f2c1 (diff) | |
download | vaadin-framework-c970a78d42a2d8f1745df7a11a74f3731f8be9a5.tar.gz vaadin-framework-c970a78d42a2d8f1745df7a11a74f3731f8be9a5.zip |
Always show loading indicator for JavaScript RPC (#20235)
The change to not show loading indicator for JS RPC was done in
15a53d305e6648572c11cb988f4988c2c5825af1 and looks like a refactoring
error.
Change-Id: If2a2818e0c4adc06479ecaf17764bf53fc89c095
5 files changed, 93 insertions, 8 deletions
diff --git a/client/src/main/java/com/vaadin/client/communication/ServerRpcQueue.java b/client/src/main/java/com/vaadin/client/communication/ServerRpcQueue.java index e5d5ea8a25..f6d2097e98 100644 --- a/client/src/main/java/com/vaadin/client/communication/ServerRpcQueue.java +++ b/client/src/main/java/com/vaadin/client/communication/ServerRpcQueue.java @@ -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 index 0000000000..67795d629a --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/javascriptcomponent/JSComponentLoadingIndicator.java @@ -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 index 0000000000..522654a930 --- /dev/null +++ b/uitest/src/main/resources/com/vaadin/tests/components/javascriptcomponent/JSComponent.js @@ -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 index 0000000000..c88ea234f6 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/javascriptcomponent/JSComponentLoadingIndicatorTest.java @@ -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()); + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/tb3/AbstractTB3Test.java b/uitest/src/test/java/com/vaadin/tests/tb3/AbstractTB3Test.java index 7029abd9ac..992a1376c8 100644 --- a/uitest/src/test/java/com/vaadin/tests/tb3/AbstractTB3Test.java +++ b/uitest/src/test/java/com/vaadin/tests/tb3/AbstractTB3Test.java @@ -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(); } }); } |