-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: forward with optional callback (#19959)
* fix: forwarding with optional callback
- Loading branch information
Showing
9 changed files
with
158 additions
and
13 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
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
9 changes: 9 additions & 0 deletions
9
flow-tests/test-react-router/src/main/java/com/vaadin/flow/ForwardTargetView.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,9 @@ | ||
package com.vaadin.flow; | ||
|
||
import com.vaadin.flow.component.html.Div; | ||
import com.vaadin.flow.router.Route; | ||
|
||
@Route("com.vaadin.flow.ForwardTargetView") | ||
public class ForwardTargetView extends Div { | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
...ests/test-react-router/src/main/java/com/vaadin/flow/ForwardTargetWithParametersView.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,19 @@ | ||
package com.vaadin.flow; | ||
|
||
import com.vaadin.flow.component.html.Div; | ||
import com.vaadin.flow.component.html.Span; | ||
import com.vaadin.flow.router.BeforeEvent; | ||
import com.vaadin.flow.router.HasUrlParameter; | ||
import com.vaadin.flow.router.OptionalParameter; | ||
import com.vaadin.flow.router.Route; | ||
|
||
@Route("com.vaadin.flow.ForwardTargetWithParametersView") | ||
public class ForwardTargetWithParametersView extends Div | ||
implements HasUrlParameter<String> { | ||
|
||
@Override | ||
public void setParameter(BeforeEvent event, | ||
@OptionalParameter String parameter) { | ||
add(new Span("setParameter")); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
flow-tests/test-react-router/src/main/java/com/vaadin/flow/ForwardingToParametersView.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,15 @@ | ||
package com.vaadin.flow; | ||
|
||
import com.vaadin.flow.component.html.Div; | ||
import com.vaadin.flow.router.BeforeEnterEvent; | ||
import com.vaadin.flow.router.BeforeEnterObserver; | ||
import com.vaadin.flow.router.Route; | ||
|
||
@Route("com.vaadin.flow.ForwardingToParametersView") | ||
public class ForwardingToParametersView extends Div | ||
implements BeforeEnterObserver { | ||
@Override | ||
public void beforeEnter(BeforeEnterEvent event) { | ||
event.forwardTo(ForwardTargetWithParametersView.class); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
flow-tests/test-react-router/src/main/java/com/vaadin/flow/ForwardingView.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,14 @@ | ||
package com.vaadin.flow; | ||
|
||
import com.vaadin.flow.component.html.Div; | ||
import com.vaadin.flow.router.BeforeEnterEvent; | ||
import com.vaadin.flow.router.BeforeEnterObserver; | ||
import com.vaadin.flow.router.Route; | ||
|
||
@Route("com.vaadin.flow.ForwardingView") | ||
public class ForwardingView extends Div implements BeforeEnterObserver { | ||
@Override | ||
public void beforeEnter(BeforeEnterEvent event) { | ||
event.forwardTo(ForwardTargetView.class); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
flow-tests/test-react-router/src/test/java/com/vaadin/flow/ForwardTargetIT.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,61 @@ | ||
package com.vaadin.flow; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.openqa.selenium.TimeoutException; | ||
|
||
import com.vaadin.flow.component.html.testbench.SpanElement; | ||
import com.vaadin.flow.testutil.ChromeBrowserTest; | ||
|
||
public class ForwardTargetIT extends ChromeBrowserTest { | ||
|
||
public static final String FORWARD_TARGET_VIEW = "/view/com.vaadin.flow.ForwardTargetView"; | ||
|
||
// Test for https://github.com/vaadin/flow/issues/19794 | ||
@Test | ||
public void testUrlIsCorrectAfterForward() { | ||
getDriver().get(getTestURL(getRootURL(), FORWARD_TARGET_VIEW, null)); | ||
|
||
try { | ||
waitUntil(arg -> driver.getCurrentUrl() | ||
.endsWith(FORWARD_TARGET_VIEW)); | ||
} catch (TimeoutException e) { | ||
Assert.fail("URL wasn't updated to expected one: " | ||
+ FORWARD_TARGET_VIEW); | ||
} | ||
|
||
getDriver().get(getTestURL(getRootURL(), | ||
"/view/com.vaadin.flow.ForwardingView", null)); | ||
|
||
try { | ||
waitUntil(arg -> driver.getCurrentUrl() | ||
.endsWith(FORWARD_TARGET_VIEW)); | ||
} catch (TimeoutException e) { | ||
Assert.fail("URL wasn't updated to expected one: " | ||
+ FORWARD_TARGET_VIEW); | ||
} | ||
|
||
Assert.assertTrue("URL was not the expected one after forward call", | ||
driver.getCurrentUrl().endsWith(FORWARD_TARGET_VIEW)); | ||
} | ||
|
||
// Test for https://github.com/vaadin/flow/issues/19822 | ||
@Test | ||
public void testSetParameterCalledOnlyOnceAfterForward() { | ||
getDriver().get(getTestURL(getRootURL(), | ||
"/view/com.vaadin.flow.ForwardingToParametersView", null)); | ||
|
||
try { | ||
waitUntil(arg -> driver.getCurrentUrl().endsWith( | ||
"/view/com.vaadin.flow.ForwardTargetWithParametersView")); | ||
} catch (TimeoutException e) { | ||
Assert.fail("URL wasn't updated to expected one: " | ||
+ "/view/com.vaadin.flow.ForwardTargetWithParametersView"); | ||
} | ||
|
||
Assert.assertEquals("setParameter was called more than once", 1, | ||
$(SpanElement.class).all().stream() | ||
.filter(span -> span.getText().equals("setParameter")) | ||
.count()); | ||
} | ||
} |