-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix navigating with full url for instance when adding a query parameter at the end. Fixes #19580
- Loading branch information
Showing
3 changed files
with
86 additions
and
1 deletion.
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
51 changes: 51 additions & 0 deletions
51
flow-tests/test-react-router/src/main/java/com/vaadin/flow/AddQueryParamView.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,51 @@ | ||
/* | ||
* Copyright 2000-2024 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package com.vaadin.flow; | ||
|
||
import com.vaadin.flow.component.UI; | ||
import com.vaadin.flow.component.html.Div; | ||
import com.vaadin.flow.component.html.NativeButton; | ||
import com.vaadin.flow.component.page.Page; | ||
import com.vaadin.flow.router.BeforeEnterEvent; | ||
import com.vaadin.flow.router.BeforeEnterObserver; | ||
import com.vaadin.flow.router.Route; | ||
|
||
@Route("com.vaadin.flow.AddQueryParamView") | ||
public class AddQueryParamView extends Div { | ||
|
||
public static final String PARAM_BUTTON_ID = "setParameter"; | ||
public static final String QUERY_ID = "query"; | ||
|
||
public AddQueryParamView() { | ||
NativeButton button = new NativeButton("Add URL Parameter", e -> { | ||
updateUrlRequestParameter("test", "HELLO!"); | ||
}); | ||
button.setId(PARAM_BUTTON_ID); | ||
add(button); | ||
} | ||
|
||
public void updateUrlRequestParameter(String key, String value) { | ||
Page page = UI.getCurrent().getPage(); | ||
page.fetchCurrentURL(url -> { | ||
String newLocation = url + "?" + key + "=" + value; | ||
page.getHistory().replaceState(null, newLocation); | ||
Div div = new Div(newLocation); | ||
div.setId(QUERY_ID); | ||
add(div); | ||
}); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
flow-tests/test-react-router/src/test/java/com/vaadin/flow/AddQueryParamIT.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,30 @@ | ||
package com.vaadin.flow; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.openqa.selenium.By; | ||
|
||
import com.vaadin.flow.component.html.testbench.DivElement; | ||
import com.vaadin.flow.component.html.testbench.NativeButtonElement; | ||
import com.vaadin.flow.component.html.testbench.SpanElement; | ||
import com.vaadin.flow.testutil.ChromeBrowserTest; | ||
|
||
public class AddQueryParamIT extends ChromeBrowserTest { | ||
|
||
@Test | ||
public void validateReactInUse() { | ||
open(); | ||
|
||
waitForDevServer(); | ||
|
||
$(NativeButtonElement.class).id(AddQueryParamView.PARAM_BUTTON_ID) | ||
.click(); | ||
|
||
waitForElementPresent(By.id(AddQueryParamView.QUERY_ID)); | ||
|
||
Assert.assertEquals( | ||
$(DivElement.class).id(AddQueryParamView.QUERY_ID).getText(), | ||
driver.getCurrentUrl()); | ||
} | ||
|
||
} |