Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix regression that broke PreserveOnRefresh functionality with Naviga…
…tor (#11615) * Fix regression that broke PreserveOnRefresh functionality with Navigator Fixes #11614 Old patch #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
- Loading branch information
Showing
3 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
uitest/src/main/java/com/vaadin/tests/components/ui/RefreshUI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
uitest/src/test/java/com/vaadin/tests/components/ui/RefreshUITest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} |