]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix navigation to same view with different parameters (#20029)
authorTeemu Suo-Anttila <teemusa@vaadin.com>
Tue, 5 Jul 2016 10:37:07 +0000 (13:37 +0300)
committerMarko Gronroos <magi@vaadin.com>
Wed, 13 Jul 2016 15:52:03 +0000 (18:52 +0300)
Change-Id: I0ecc18f0ee5aecac42cfc6c9422932e2e308ab83

server/src/main/java/com/vaadin/navigator/Navigator.java
uitest/src/test/java/com/vaadin/tests/navigator/NavigationTest.java [new file with mode: 0644]

index 390e2529061dde8636fbc5b67560b6e7f69ebe8b..9aa3bc468c8fddd5d2368d81a40a2295cca4c7cb 100644 (file)
@@ -558,27 +558,30 @@ public class Navigator implements Serializable {
             longestViewName = errorProvider.getViewName(navigationState);
             viewWithLongestName = errorProvider.getView(longestViewName);
         }
-        if (viewWithLongestName != null) {
-            String parameters = "";
-            if (navigationState.length() > longestViewName.length() + 1) {
-                parameters = navigationState
-                        .substring(longestViewName.length() + 1);
-            }
-            if (getCurrentView() == null
-                    || !SharedUtil
-                            .equals(getCurrentView(), viewWithLongestName)) {
-                navigateTo(viewWithLongestName, longestViewName, parameters);
-            } else {
-                updateNavigationState(new ViewChangeEvent(this,
-                        getCurrentView(), viewWithLongestName, longestViewName,
-                        parameters));
-            }
-        } else {
+
+        if (viewWithLongestName == null) {
             throw new IllegalArgumentException(
                     "Trying to navigate to an unknown state '"
                             + navigationState
                             + "' and an error view provider not present");
         }
+
+        String parameters = "";
+        if (navigationState.length() > longestViewName.length() + 1) {
+            parameters = navigationState
+                    .substring(longestViewName.length() + 1);
+        } else if (navigationState.endsWith("/")) {
+            navigationState = navigationState.substring(0,
+                    navigationState.length() - 1);
+        }
+        if (getCurrentView() == null
+                || !SharedUtil.equals(getCurrentView(), viewWithLongestName)
+                || !SharedUtil.equals(currentNavigationState, navigationState)) {
+            navigateTo(viewWithLongestName, longestViewName, parameters);
+        } else {
+            updateNavigationState(new ViewChangeEvent(this, getCurrentView(),
+                    viewWithLongestName, longestViewName, parameters));
+        }
     }
 
     /**
@@ -677,8 +680,8 @@ public class Navigator implements Serializable {
             }
             if (!navigationState.equals(getStateManager().getState())) {
                 getStateManager().setState(navigationState);
-                currentNavigationState = navigationState;
             }
+            currentNavigationState = navigationState;
         }
     }
 
diff --git a/uitest/src/test/java/com/vaadin/tests/navigator/NavigationTest.java b/uitest/src/test/java/com/vaadin/tests/navigator/NavigationTest.java
new file mode 100644 (file)
index 0000000..59f71f3
--- /dev/null
@@ -0,0 +1,54 @@
+package com.vaadin.tests.navigator;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import com.vaadin.testbench.By;
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.TableElement;
+import com.vaadin.testbench.elements.TableRowElement;
+import com.vaadin.testbench.elements.TextFieldElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class NavigationTest extends SingleBrowserTest {
+
+    @Override
+    protected Class<?> getUIClass() {
+        return NavigatorTest.class;
+    }
+
+    @Test
+    public void testNavigateToSameViewWithDifferentParameters() {
+        openTestURL();
+
+        ButtonElement listButton = $(ButtonElement.class).caption(
+                "Navigate to list").first();
+        listButton.click();
+
+        TableElement table = $(TableElement.class).first();
+        assertEquals("Unexpected navigation message",
+                "2. Navigated to ListView without params", getLogRow(0));
+
+        assertFalse("Table should not have contents",
+                table.isElementPresent(By.vaadin("#row[0]")));
+
+        listButton.click();
+        assertEquals("Should not navigate to same view again.",
+                "2. Navigated to ListView without params", getLogRow(0));
+
+        $(TextFieldElement.class).first().sendKeys("foo=1");
+        listButton.click();
+
+        assertEquals("Should not navigate to same view again.",
+                "3. Navigated to ListView with params foo=1", getLogRow(0));
+
+        assertTrue("Table should have content",
+                table.isElementPresent(By.vaadin("#row[0]")));
+        TableRowElement row = table.getRow(0);
+        assertEquals("Unexpected row content", "foo", row.getCell(0).getText());
+        assertEquals("Unexpected row content", "1", row.getCell(1).getText());
+    }
+}