Search in sources :

Example 1 with RouterTestUI

use of com.vaadin.flow.router.legacy.RouterTest.RouterTestUI in project flow by vaadin.

the class RouterLinkTest method invalidRoute_attachedLink.

@Test(expected = IllegalArgumentException.class)
public void invalidRoute_attachedLink() {
    Router router = new Router();
    RouterTestUI ui = new RouterTestUI(router);
    router.reconfigure(c -> c.setRoute("show/{bar}", TestView.class));
    RouterLink link = new RouterLink();
    ui.add(link);
    link.setRoute(TestView.class);
}
Also used : RouterTestUI(com.vaadin.flow.router.legacy.RouterTest.RouterTestUI) TestView(com.vaadin.flow.router.legacy.ViewRendererTest.TestView) Router(com.vaadin.flow.router.legacy.Router) Test(org.junit.Test)

Example 2 with RouterTestUI

use of com.vaadin.flow.router.legacy.RouterTest.RouterTestUI in project flow by vaadin.

the class RouterLinkTest method setRoute_attachedLink.

@Test
public void setRoute_attachedLink() {
    RouterTestUI ui = new RouterTestUI(new Router());
    ui.getRouterInterface().get().reconfigure(c -> c.setRoute("show/{bar}", TestView.class));
    RouterLink link = new RouterLink();
    ui.add(link);
    link.setRoute(TestView.class, "foo");
    Assert.assertTrue(link.getElement().hasAttribute("href"));
    Assert.assertEquals("show/foo", link.getElement().getAttribute("href"));
}
Also used : RouterTestUI(com.vaadin.flow.router.legacy.RouterTest.RouterTestUI) TestView(com.vaadin.flow.router.legacy.ViewRendererTest.TestView) Router(com.vaadin.flow.router.legacy.Router) Test(org.junit.Test)

Example 3 with RouterTestUI

use of com.vaadin.flow.router.legacy.RouterTest.RouterTestUI in project flow by vaadin.

the class RouterLinkTest method createRouterLink_implicitCurrentVaadinServiceRouter.

@Test
public void createRouterLink_implicitCurrentVaadinServiceRouter() {
    // This method sets mock VaadinService instance which returns
    // Router from the UI.
    RouterTestUI ui = createUI();
    ui.getRouterInterface().get().reconfigure(c -> c.setRoute("show/{bar}", TestView.class));
    RouterLink link = new RouterLink("Show something", TestView.class, "something");
    Assert.assertEquals("Show something", link.getText());
    Assert.assertTrue(link.getElement().hasAttribute(ApplicationConstants.ROUTER_LINK_ATTRIBUTE));
    Assert.assertTrue(link.getElement().hasAttribute("href"));
    Assert.assertEquals("show/something", link.getElement().getAttribute("href"));
}
Also used : RouterTestUI(com.vaadin.flow.router.legacy.RouterTest.RouterTestUI) TestView(com.vaadin.flow.router.legacy.ViewRendererTest.TestView) Test(org.junit.Test)

Example 4 with RouterTestUI

use of com.vaadin.flow.router.legacy.RouterTest.RouterTestUI in project flow by vaadin.

the class RouterLinkTest method invalidRoute_implicitCurrentVaadinServiceRouter.

@Test(expected = IllegalArgumentException.class)
public void invalidRoute_implicitCurrentVaadinServiceRouter() {
    // This method sets mock VaadinService instance which returns
    // Router from the UI.
    RouterTestUI ui = createUI();
    ui.getRouterInterface().get().reconfigure(c -> c.setRoute("show/{bar}", TestView.class));
    new RouterLink("Show something", TestView.class);
}
Also used : RouterTestUI(com.vaadin.flow.router.legacy.RouterTest.RouterTestUI) TestView(com.vaadin.flow.router.legacy.ViewRendererTest.TestView) Test(org.junit.Test)

Example 5 with RouterTestUI

use of com.vaadin.flow.router.legacy.RouterTest.RouterTestUI 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)

Aggregations

RouterTestUI (com.vaadin.flow.router.legacy.RouterTest.RouterTestUI)8 TestView (com.vaadin.flow.router.legacy.ViewRendererTest.TestView)7 Test (org.junit.Test)6 Router (com.vaadin.flow.router.legacy.Router)3 UI (com.vaadin.flow.component.UI)1 Location (com.vaadin.flow.router.Location)1 NavigationEvent (com.vaadin.flow.router.NavigationEvent)1 LocationChangeEvent (com.vaadin.flow.router.legacy.LocationChangeEvent)1 AnotherParentView (com.vaadin.flow.router.legacy.ViewRendererTest.AnotherParentView)1 AnotherTestView (com.vaadin.flow.router.legacy.ViewRendererTest.AnotherTestView)1 ParentView (com.vaadin.flow.router.legacy.ViewRendererTest.ParentView)1 VaadinService (com.vaadin.flow.server.VaadinService)1 Before (org.junit.Before)1