Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Improving UX of Query parameters (#14034)
made it easier to use both query and url parameters shorthand to create URL parameters from single key-value pair Fixes #14013
- Loading branch information
Showing
5 changed files
with
256 additions
and
0 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
70 changes: 70 additions & 0 deletions
70
...est-root-context/src/main/java/com/vaadin/flow/uitest/ui/RouteAndQueryParametersView.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,70 @@ | ||
/* | ||
* Copyright 2000-2022 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.uitest.ui; | ||
|
||
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.html.Paragraph; | ||
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.RouteAndQueryParametersView", layout = ViewTestLayout.class) | ||
public class RouteAndQueryParametersView extends Div | ||
implements HasUrlParameter<Integer> { | ||
static final String REQUEST_PARAM_NAME = "testRequestParam"; | ||
|
||
private final Paragraph paramView; | ||
|
||
public RouteAndQueryParametersView() { | ||
paramView = new Paragraph("No input"); | ||
paramView.setId("paramView"); | ||
add(paramView); | ||
|
||
NativeButton nativeButton = new NativeButton("Navigate with both"); | ||
nativeButton.setId("both"); | ||
nativeButton.addClickListener(e -> { | ||
UI.getCurrent().navigate(RouteAndQueryParametersView.class, 5, | ||
QueryParameters.of("foo", "bar")); | ||
}); | ||
add(nativeButton); | ||
|
||
NativeButton withQueryParametersOnly = new NativeButton( | ||
"Navigate with qp"); | ||
withQueryParametersOnly.setId("qponly"); | ||
withQueryParametersOnly.addClickListener(e -> { | ||
UI.getCurrent().navigate(RouteAndQueryParametersView.class, | ||
QueryParameters.of("foo", "bar")); | ||
}); | ||
add(withQueryParametersOnly); | ||
|
||
} | ||
|
||
@Override | ||
public void setParameter(BeforeEvent event, | ||
@OptionalParameter Integer parameter) { | ||
String queryString = event.getLocation().getQueryParameters() | ||
.getQueryString(); | ||
paramView.setText("route parameter: " + parameter + ", query string:" | ||
+ queryString); | ||
|
||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
.../test-root-context/src/test/java/com/vaadin/flow/uitest/ui/RouteAndQueryParametersIT.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,44 @@ | ||
/* | ||
* Copyright 2000-2022 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.uitest.ui; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.openqa.selenium.By; | ||
|
||
import com.vaadin.flow.testutil.ChromeBrowserTest; | ||
|
||
public class RouteAndQueryParametersIT extends ChromeBrowserTest { | ||
|
||
@Test | ||
public void testNavigationWithBothRouteAndQueryParameters() { | ||
open(); | ||
|
||
Assert.assertFalse(getDriver().getPageSource().contains("foo=bar")); | ||
|
||
findElement(By.id("both")).click(); | ||
|
||
Assert.assertTrue(getDriver().getPageSource() | ||
.contains("route parameter: 5, query string:foo=bar")); | ||
|
||
findElement(By.id("qponly")).click(); | ||
|
||
Assert.assertTrue(getDriver().getPageSource() | ||
.contains("route parameter: null, query string:foo=bar")); | ||
|
||
} | ||
|
||
} |