diff --git a/flow-server/src/test/java/com/vaadin/flow/server/communication/PushHandlerTest.java b/flow-server/src/test/java/com/vaadin/flow/server/communication/PushHandlerTest.java index c50e4082db4..eb290e49cbd 100644 --- a/flow-server/src/test/java/com/vaadin/flow/server/communication/PushHandlerTest.java +++ b/flow-server/src/test/java/com/vaadin/flow/server/communication/PushHandlerTest.java @@ -23,7 +23,6 @@ import org.atmosphere.cpr.AtmosphereResource; import org.atmosphere.cpr.AtmosphereResource.TRANSPORT; import org.atmosphere.cpr.AtmosphereResourceEvent; -import org.junit.After; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; diff --git a/flow-tests/test-root-context/src/main/java/com/vaadin/flow/uitest/ui/PushLongPollingWithPreserveOnRefreshView.java b/flow-tests/test-root-context/src/main/java/com/vaadin/flow/uitest/ui/PushLongPollingWithPreserveOnRefreshView.java new file mode 100644 index 00000000000..9a3e632c13e --- /dev/null +++ b/flow-tests/test-root-context/src/main/java/com/vaadin/flow/uitest/ui/PushLongPollingWithPreserveOnRefreshView.java @@ -0,0 +1,46 @@ +/* + * Copyright 2000-2021 Vaadin Ltd. + * + * Licensed 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. + */ + +package com.vaadin.flow.uitest.ui; + +import com.vaadin.flow.component.html.Div; +import com.vaadin.flow.component.html.NativeButton; +import com.vaadin.flow.component.page.Push; +import com.vaadin.flow.router.PreserveOnRefresh; +import com.vaadin.flow.router.Route; +import com.vaadin.flow.shared.ui.Transport; + +@PreserveOnRefresh +@Push(transport = Transport.LONG_POLLING) +@Route("com.vaadin.flow.uitest.ui.PushLongPollingWithPreserveOnRefreshView") +public class PushLongPollingWithPreserveOnRefreshView extends Div { + + public static final String ADD_BUTTON_ID = "add-button-id"; + public static final String TEST_DIV_ID = "test-div-id"; + public static final String TEXT_IN_DIV = "text in div"; + + public PushLongPollingWithPreserveOnRefreshView() { + NativeButton button = new NativeButton("Open Dialog", + e -> e.getSource().getUI().ifPresent(ui -> { + Div div = new Div(); + div.setText(TEXT_IN_DIV); + div.setId(TEST_DIV_ID); + ui.add(div); + })); + button.setId(ADD_BUTTON_ID); + add(button); + } +} diff --git a/flow-tests/test-root-context/src/test/java/com/vaadin/flow/uitest/ui/PushLongPollingWithPreserveOnRefreshIT.java b/flow-tests/test-root-context/src/test/java/com/vaadin/flow/uitest/ui/PushLongPollingWithPreserveOnRefreshIT.java new file mode 100644 index 00000000000..2cb3b9bf864 --- /dev/null +++ b/flow-tests/test-root-context/src/test/java/com/vaadin/flow/uitest/ui/PushLongPollingWithPreserveOnRefreshIT.java @@ -0,0 +1,76 @@ +/* + * Copyright 2000-2021 Vaadin Ltd. + * + * Licensed 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. + */ + +package com.vaadin.flow.uitest.ui; + +import org.junit.Assert; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.NoSuchElementException; + +import com.vaadin.flow.testcategory.IgnoreOSGi; +import com.vaadin.flow.testutil.ChromeBrowserTest; + +import static com.vaadin.flow.uitest.ui.PushLongPollingWithPreserveOnRefreshView.ADD_BUTTON_ID; +import static com.vaadin.flow.uitest.ui.PushLongPollingWithPreserveOnRefreshView.TEST_DIV_ID; +import static com.vaadin.flow.uitest.ui.PushLongPollingWithPreserveOnRefreshView.TEXT_IN_DIV; + +@Category(IgnoreOSGi.class) +public class PushLongPollingWithPreserveOnRefreshIT extends ChromeBrowserTest { + + @Ignore("https://github.com/vaadin/flow/issues/10103") + @Test + public void addDiv_refreshThePage_ensureNoErrorHappensAndDivIsPresent() { + + open(); + + waitPageLoad(); + + findElement(By.id(ADD_BUTTON_ID)).click(); + + ensureDivIsPresent(); + + // refresh the browser + getDriver().navigate().refresh(); + + waitPageLoad(); + + ensureNoErrorIsDisplayed(); + + ensureDivIsPresent(); + } + + private void waitPageLoad() { + WebElement loadingIndicator = findElement( + By.className("v-loading-indicator")); + waitUntil(driver -> !loadingIndicator.isDisplayed()); + } + + private void ensureNoErrorIsDisplayed() { + Assert.assertThrows(NoSuchElementException.class, + () -> findElement(By.className("v-system-error"))); + } + + private void ensureDivIsPresent() { + WebElement div = findElement(By.id(TEST_DIV_ID)); + + Assert.assertNotNull(div); + Assert.assertEquals(TEXT_IN_DIV, div.getText()); + } +}