-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: resolve route parameters when rerouting and forwardin with query…
- Loading branch information
1 parent
13fb546
commit f4a6ffc
Showing
5 changed files
with
193 additions
and
19 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
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
67 changes: 67 additions & 0 deletions
67
.../test-root-context/src/main/java/com/vaadin/flow/uitest/ui/SetParameterRerouteToView.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,67 @@ | ||
package com.vaadin.flow.uitest.ui; | ||
|
||
import java.util.List; | ||
|
||
import com.vaadin.flow.component.html.Div; | ||
import com.vaadin.flow.router.AfterNavigationEvent; | ||
import com.vaadin.flow.router.AfterNavigationObserver; | ||
import com.vaadin.flow.router.BeforeEvent; | ||
import com.vaadin.flow.router.HasUrlParameter; | ||
import com.vaadin.flow.router.OptionalParameter; | ||
import com.vaadin.flow.router.QueryParameters; | ||
import com.vaadin.flow.router.Route; | ||
import com.vaadin.flow.uitest.servlet.ViewTestLayout; | ||
|
||
@Route(value = "com.vaadin.flow.uitest.ui.SetParameterRerouteToView", layout = ViewTestLayout.class) | ||
public class SetParameterRerouteToView extends Div | ||
implements HasUrlParameter<String>, AfterNavigationObserver { | ||
|
||
static final String LOCATION_ID = "location"; | ||
static final String PARAMETER_ID = "parameter"; | ||
|
||
private final Div location; | ||
private final Div param; | ||
|
||
public SetParameterRerouteToView() { | ||
location = new Div(); | ||
location.setId(LOCATION_ID); | ||
param = new Div(); | ||
param.setId(PARAMETER_ID); | ||
} | ||
|
||
@Override | ||
public void setParameter(BeforeEvent event, | ||
@OptionalParameter String parameter) { | ||
if (parameter != null) { | ||
switch (parameter) { | ||
case "location": | ||
event.rerouteTo( | ||
"com.vaadin.flow.uitest.ui.SetParameterRerouteToView/locationTwo"); | ||
break; | ||
case "locationRouteParameter": | ||
event.rerouteTo( | ||
"com.vaadin.flow.uitest.ui.SetParameterRerouteToView", | ||
"locationRouteParameterTwo"); | ||
break; | ||
case "locationRouteParameterList": | ||
event.rerouteTo( | ||
"com.vaadin.flow.uitest.ui.SetParameterRerouteToView", | ||
List.of("locationRouteParameterListTwo")); | ||
break; | ||
case "locationQueryParams": | ||
event.rerouteTo( | ||
"com.vaadin.flow.uitest.ui.SetParameterRerouteToView/locationQueryParamsTwo", | ||
QueryParameters.empty()); | ||
break; | ||
} | ||
} | ||
param.setText(parameter); | ||
} | ||
|
||
@Override | ||
public void afterNavigation(AfterNavigationEvent event) { | ||
location.setText(event.getLocation().getPath()); | ||
add(location, param); | ||
} | ||
|
||
} |
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
54 changes: 54 additions & 0 deletions
54
...ts/test-root-context/src/test/java/com/vaadin/flow/uitest/ui/SetParameterRerouteToIT.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,54 @@ | ||
package com.vaadin.flow.uitest.ui; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.openqa.selenium.By; | ||
|
||
import com.vaadin.flow.testutil.ChromeBrowserTest; | ||
|
||
public class SetParameterRerouteToIT extends ChromeBrowserTest { | ||
|
||
@Test | ||
public void testReroutingToViewWithLocation_setParameter() { | ||
testReroutingToView("location"); | ||
} | ||
|
||
@Test | ||
public void testReroutingToViewWithRouteParameter_setParameter() { | ||
testReroutingToView("locationRouteParameter"); | ||
} | ||
|
||
@Test | ||
public void testReroutingToViewWithRouteParameterList_setParameter() { | ||
testReroutingToView("locationRouteParameterList"); | ||
} | ||
|
||
@Test | ||
public void testReroutingToViewWithQueryParameter_setParameter() { | ||
testReroutingToView("locationQueryParams"); | ||
} | ||
|
||
private void testReroutingToView(String location) { | ||
final String baseLoc = "/view/com.vaadin.flow.uitest.ui.SetParameterRerouteToView"; | ||
final String expectedParameter = location + "Two"; | ||
final String expectedLoc = "/" + expectedParameter; | ||
final String originalLoc = baseLoc + "/" + location; | ||
getDriver().get(getRootURL() + originalLoc); | ||
waitForDevServer(); | ||
|
||
waitForElementPresent(By.id(SetParameterForwardToView.LOCATION_ID)); | ||
final String locationId = findElement( | ||
By.id(SetParameterForwardToView.LOCATION_ID)).getText(); | ||
waitForElementPresent(By.id(SetParameterForwardToView.PARAMETER_ID)); | ||
final String parameterValue = findElement( | ||
By.id(SetParameterForwardToView.PARAMETER_ID)).getText(); | ||
|
||
Assert.assertTrue("should redirect to " + baseLoc + expectedLoc, | ||
locationId.endsWith(expectedLoc)); | ||
Assert.assertTrue("should not update the URL", | ||
getDriver().getCurrentUrl().endsWith(originalLoc)); | ||
Assert.assertEquals("rerouted parameter", expectedParameter, | ||
parameterValue); | ||
} | ||
|
||
} |