diff options
author | Tatu Lund <tatu@vaadin.com> | 2019-06-07 13:14:38 +0300 |
---|---|---|
committer | Zhe Sun <31067185+ZheSun88@users.noreply.github.com> | 2019-06-07 13:14:38 +0300 |
commit | 7a453dce177d849305c549296986eb21e171bae0 (patch) | |
tree | fdff2d68f8bbbf9f34b1cbf9d6184de133154d82 /uitest/src | |
parent | a6a21157c426aed6a0211bc0a3f6a5056f1e455e (diff) | |
download | vaadin-framework-7a453dce177d849305c549296986eb21e171bae0.tar.gz vaadin-framework-7a453dce177d849305c549296986eb21e171bae0.zip |
Fix regression that broke PreserveOnRefresh functionality with Navigator (#11615)
* Fix regression that broke PreserveOnRefresh functionality with Navigator
Fixes https://github.com/vaadin/framework/issues/11614
Old patch https://github.com/vaadin/framework/issues/11416 calls navigateTo allways when Navigator is present, which is wrong, since it is needed only when navigation state has truly changed.
* Add test to the fix
Diffstat (limited to 'uitest/src')
-rw-r--r-- | uitest/src/main/java/com/vaadin/tests/components/ui/RefreshUI.java | 29 | ||||
-rw-r--r-- | uitest/src/test/java/com/vaadin/tests/components/ui/RefreshUITest.java | 25 |
2 files changed, 54 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/ui/RefreshUI.java b/uitest/src/main/java/com/vaadin/tests/components/ui/RefreshUI.java new file mode 100644 index 0000000000..135a6880f9 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/ui/RefreshUI.java @@ -0,0 +1,29 @@ +package com.vaadin.tests.components.ui; + +import com.vaadin.annotations.PreserveOnRefresh; +import com.vaadin.navigator.Navigator; +import com.vaadin.navigator.View; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Label; +import com.vaadin.ui.VerticalLayout; + +@PreserveOnRefresh +public class RefreshUI extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + final Navigator navigator = new Navigator(this, this); + navigator.addView("", MyView.class); + setNavigator(navigator); + } + + public static class MyView extends VerticalLayout implements View { + private static int instanceNumber = 0; + + public MyView() { + instanceNumber++; + addComponent(new Label("This is instance no " + instanceNumber)); + } + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/ui/RefreshUITest.java b/uitest/src/test/java/com/vaadin/tests/components/ui/RefreshUITest.java new file mode 100644 index 0000000000..16f279e1e5 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/ui/RefreshUITest.java @@ -0,0 +1,25 @@ +package com.vaadin.tests.components.ui; + +import org.junit.Test; + +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +import static org.junit.Assert.assertEquals; + +public class RefreshUITest extends MultiBrowserTest { + + @Test + public void testUIRefresh_viewNotRecreated() { + openTestURL(); + assertEquals("The Label content is not matching", + "This is instance no 1", + $(LabelElement.class).first().getText()); + + // Reload the page; UI.refresh should be invoked + openTestURL(); + assertEquals("The Label content is not matching", + "This is instance no 1", + $(LabelElement.class).first().getText()); + } +} |