Search in sources :

Example 1 with Location

use of com.vaadin.flow.router.Location in project flow by vaadin.

the class ViewRendererTest method routeParametersInEvent.

@Test
public void routeParametersInEvent() {
    router.reconfigure(c -> c.setRoute("foo/{name}/*", TestView.class));
    router.navigate(ui, new Location("foo/bar/baz/"), NavigationTrigger.PROGRAMMATIC);
    TestView testView = (TestView) ui.getInternals().getActiveViewChain().get(0);
    Assert.assertEquals("bar", testView.namePlaceholderValue);
    Assert.assertEquals("baz/", testView.wildcardValue);
}
Also used : Location(com.vaadin.flow.router.Location) Test(org.junit.Test)

Example 2 with Location

use of com.vaadin.flow.router.Location in project flow by vaadin.

the class LocationChangeEventTest method setup.

@Before
public void setup() {
    UI ui = new RouterTestUI();
    event = new LocationChangeEvent(ui.getRouterInterface().get(), ui, NavigationTrigger.PROGRAMMATIC, new Location(""), Arrays.asList(new AnotherTestView(), new AnotherParentView()), Collections.emptyMap());
    event.getSource().reconfigure(c -> c.setParentView(TestView.class, ParentView.class));
    navigationEvent = new NavigationEvent(event.getSource(), event.getLocation(), event.getUI(), event.getTrigger());
}
Also used : NavigationEvent(com.vaadin.flow.router.NavigationEvent) AnotherParentView(com.vaadin.flow.router.legacy.ViewRendererTest.AnotherParentView) ParentView(com.vaadin.flow.router.legacy.ViewRendererTest.ParentView) RouterTestUI(com.vaadin.flow.router.legacy.RouterTest.RouterTestUI) RouterTestUI(com.vaadin.flow.router.legacy.RouterTest.RouterTestUI) UI(com.vaadin.flow.component.UI) AnotherParentView(com.vaadin.flow.router.legacy.ViewRendererTest.AnotherParentView) LocationChangeEvent(com.vaadin.flow.router.legacy.LocationChangeEvent) AnotherTestView(com.vaadin.flow.router.legacy.ViewRendererTest.AnotherTestView) AnotherTestView(com.vaadin.flow.router.legacy.ViewRendererTest.AnotherTestView) TestView(com.vaadin.flow.router.legacy.ViewRendererTest.TestView) Location(com.vaadin.flow.router.Location) Before(org.junit.Before)

Example 3 with Location

use of com.vaadin.flow.router.Location in project flow by vaadin.

the class LocationTest method subLocation.

@Test
public void subLocation() {
    Location location = new Location(Arrays.asList("one", "two", "three"));
    assertEquals("one", location.getFirstSegment());
    Optional<Location> subLocation = location.getSubLocation();
    assertEquals(Arrays.asList("two", "three"), subLocation.get().getSegments());
    assertEquals("two/three", subLocation.get().getPath());
}
Also used : Location(com.vaadin.flow.router.Location) Test(org.junit.Test)

Example 4 with Location

use of com.vaadin.flow.router.Location in project flow by vaadin.

the class LocationTest method locationWithParamWithAndWithoutValue.

@Test
public void locationWithParamWithAndWithoutValue() {
    Location location = new Location("foo?param&param=bar");
    Assert.assertEquals("param&param=bar", location.getQueryParameters().getQueryString());
    location = new Location("foo?param=bar&param");
    Assert.assertEquals("param=bar&param", location.getQueryParameters().getQueryString());
}
Also used : Location(com.vaadin.flow.router.Location) Test(org.junit.Test)

Example 5 with Location

use of com.vaadin.flow.router.Location in project flow by vaadin.

the class LocationTest method locationWithParametersPath_withTrailingSlash.

@Test
public void locationWithParametersPath_withTrailingSlash() {
    String initialPath = "foo/bar/";
    QueryParameters queryParams = getQueryParameters();
    Location location = new Location(initialPath, queryParams);
    String pathWithParameters = location.getPathWithQueryParameters();
    assertEquals(initialPath + '?' + queryParams.getQueryString(), pathWithParameters);
}
Also used : QueryParameters(com.vaadin.flow.router.QueryParameters) Location(com.vaadin.flow.router.Location) Test(org.junit.Test)

Aggregations

Location (com.vaadin.flow.router.Location)51 Test (org.junit.Test)40 UI (com.vaadin.flow.component.UI)15 Router (com.vaadin.flow.router.legacy.Router)15 NavigationEvent (com.vaadin.flow.router.NavigationEvent)10 NavigationHandler (com.vaadin.flow.router.NavigationHandler)8 RouterConfiguration (com.vaadin.flow.router.legacy.RouterConfiguration)7 HistoryStateChangeEvent (com.vaadin.flow.component.page.History.HistoryStateChangeEvent)6 TestView (com.vaadin.flow.router.legacy.ViewRendererTest.TestView)6 NavigationTrigger (com.vaadin.flow.router.NavigationTrigger)5 QueryParameters (com.vaadin.flow.router.QueryParameters)5 DefaultErrorView (com.vaadin.flow.router.legacy.DefaultErrorView)5 VaadinRequest (com.vaadin.flow.server.VaadinRequest)5 VaadinResponse (com.vaadin.flow.server.VaadinResponse)5 Optional (java.util.Optional)4 CurrentInstance (com.vaadin.flow.internal.CurrentInstance)3 RouterInterface (com.vaadin.flow.router.RouterInterface)3 ImmutableRouterConfiguration (com.vaadin.flow.router.legacy.ImmutableRouterConfiguration)3 Resolver (com.vaadin.flow.router.legacy.Resolver)3 RouteSegmentVisitor (com.vaadin.flow.router.legacy.RouteLocation.RouteSegmentVisitor)3