Search in sources :

Example 21 with Router

use of com.vaadin.flow.router.legacy.Router in project flow by vaadin.

the class RouterLinkTest method createReconfigureRouterLink_explicitRouter.

@Test
public void createReconfigureRouterLink_explicitRouter() {
    Router router = new Router();
    router.reconfigure(c -> c.setRoute("show/{bar}", TestView.class));
    RouterLink link = new RouterLink(router, "Show something", TestView.class, "something");
    link.setRoute(router, TestView.class, "other");
    Assert.assertEquals("show/other", link.getElement().getAttribute("href"));
    link.setRoute(router, TestView.class, "changed");
    Assert.assertEquals("show/changed", link.getElement().getAttribute("href"));
}
Also used : TestView(com.vaadin.flow.router.legacy.ViewRendererTest.TestView) Router(com.vaadin.flow.router.legacy.Router) Test(org.junit.Test)

Example 22 with Router

use of com.vaadin.flow.router.legacy.Router in project flow by vaadin.

the class RouterLinkTest method buildEmptyUrlWithRouter.

@Test
public void buildEmptyUrlWithRouter() {
    Router router = new Router();
    router.reconfigure(c -> c.setRoute("", TestView.class));
    String url = RouterLink.buildUrl(router, TestView.class);
    Assert.assertEquals("", url);
    RouterLink link = new RouterLink(router, "Home", TestView.class);
    Assert.assertEquals("", link.getHref());
}
Also used : TestView(com.vaadin.flow.router.legacy.ViewRendererTest.TestView) Router(com.vaadin.flow.router.legacy.Router) Test(org.junit.Test)

Example 23 with Router

use of com.vaadin.flow.router.legacy.Router in project flow by vaadin.

the class RouterLinkTest method testFailForWrongImplementation.

@Test
public void testFailForWrongImplementation() throws InvalidRouteConfigurationException {
    registry.setNavigationTargets(Stream.of(FaultySetup.class).collect(Collectors.toSet()));
    com.vaadin.flow.router.Router router = new com.vaadin.flow.router.Router(registry);
    VaadinService service = Mockito.mock(VaadinService.class);
    Mockito.when(service.getRouter()).thenReturn(router);
    CurrentInstance.set(VaadinService.class, service);
    expectedEx.expect(RuntimeException.class);
    expectedEx.expectMessage("Only navigation targets for old Router should implement 'View'. Remove 'implements View' from '" + FaultySetup.class.getName() + "'");
    RouterLink faulty = new RouterLink("Faulty", FaultySetup.class);
}
Also used : VaadinService(com.vaadin.flow.server.VaadinService) Router(com.vaadin.flow.router.legacy.Router) Test(org.junit.Test)

Example 24 with Router

use of com.vaadin.flow.router.legacy.Router in project flow by vaadin.

the class RouterLinkTest method buildUrlWithRouter_multipleRoutes.

@Test(expected = IllegalArgumentException.class)
public void buildUrlWithRouter_multipleRoutes() {
    Router router = new Router();
    router.reconfigure(c -> {
        c.setRoute("foo/{bar}", TestView.class);
        c.setRoute("another/route", TestView.class);
    });
    RouterLink.buildUrl(router, TestView.class, "asdf");
}
Also used : Router(com.vaadin.flow.router.legacy.Router) Test(org.junit.Test)

Example 25 with Router

use of com.vaadin.flow.router.legacy.Router in project flow by vaadin.

the class RouterLinkTest method buildUrlWithRouter_noRoutes.

@Test(expected = IllegalArgumentException.class)
public void buildUrlWithRouter_noRoutes() {
    Router router = new Router();
    RouterLink.buildUrl(router, TestView.class, "asdf");
}
Also used : Router(com.vaadin.flow.router.legacy.Router) Test(org.junit.Test)

Aggregations

Router (com.vaadin.flow.router.legacy.Router)44 Test (org.junit.Test)44 Location (com.vaadin.flow.router.Location)17 TestView (com.vaadin.flow.router.legacy.ViewRendererTest.TestView)16 UI (com.vaadin.flow.component.UI)15 NavigationEvent (com.vaadin.flow.router.NavigationEvent)8 DefaultErrorView (com.vaadin.flow.router.legacy.DefaultErrorView)7 VaadinRequest (com.vaadin.flow.server.VaadinRequest)7 HistoryStateChangeEvent (com.vaadin.flow.component.page.History.HistoryStateChangeEvent)6 ImmutableRouterConfiguration (com.vaadin.flow.router.legacy.ImmutableRouterConfiguration)6 RouterConfiguration (com.vaadin.flow.router.legacy.RouterConfiguration)6 ErrorView (com.vaadin.flow.router.legacy.ViewRendererTest.ErrorView)6 VaadinResponse (com.vaadin.flow.server.VaadinResponse)6 VaadinService (com.vaadin.flow.server.VaadinService)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 CurrentInstance (com.vaadin.flow.internal.CurrentInstance)5 NavigationHandler (com.vaadin.flow.router.NavigationHandler)5 NavigationTrigger (com.vaadin.flow.router.NavigationTrigger)5 RouterInterface (com.vaadin.flow.router.RouterInterface)5 Resolver (com.vaadin.flow.router.legacy.Resolver)5