Search in sources :

Example 1 with NavigationStateRenderer

use of com.vaadin.flow.router.internal.NavigationStateRenderer in project flow by vaadin.

the class NavigationStateRendererTest method getRouterLayoutForSingle.

@Test
public void getRouterLayoutForSingle() throws Exception {
    NavigationStateRenderer childRenderer = new NavigationStateRenderer(navigationStateFromTarget(RouteParentLayout.class));
    List<Class<? extends RouterLayout>> routerLayoutTypes = childRenderer.getRouterLayoutTypes(RouteParentLayout.class);
    Assert.assertEquals("Found layout even though RouteParentLayout doesn't have any parents.", 0, routerLayoutTypes.size());
}
Also used : RouterLayout(com.vaadin.flow.router.RouterLayout) NavigationStateRenderer(com.vaadin.flow.router.internal.NavigationStateRenderer) Test(org.junit.Test)

Example 2 with NavigationStateRenderer

use of com.vaadin.flow.router.internal.NavigationStateRenderer in project flow by vaadin.

the class LocationChangeEvent method rerouteTo.

/**
 * Reroutes the navigation to show the given component instead of the
 * component that is currently about to be displayed.
 *
 * @param rerouteTargetState
 *            the target navigation state of the rerouting, not {@code null}
 */
public void rerouteTo(NavigationState rerouteTargetState) {
    Objects.requireNonNull(rerouteTargetState, "rerouteTargetState cannot be null");
    rerouteTo(new NavigationStateRenderer(rerouteTargetState));
}
Also used : NavigationStateRenderer(com.vaadin.flow.router.internal.NavigationStateRenderer)

Example 3 with NavigationStateRenderer

use of com.vaadin.flow.router.internal.NavigationStateRenderer in project flow by vaadin.

the class NavigationStateRendererTest method getRouterLayoutForMulipleLayers.

@Test
public void getRouterLayoutForMulipleLayers() throws Exception {
    NavigationStateRenderer childRenderer = new NavigationStateRenderer(navigationStateFromTarget(ChildConfiguration.class));
    List<Class<? extends RouterLayout>> routerLayoutTypes = childRenderer.getRouterLayoutTypes(ChildConfiguration.class);
    Assert.assertEquals("Not all expected layouts were found", 2, routerLayoutTypes.size());
    Assert.assertEquals("Wrong class found as first in array", MiddleLayout.class, routerLayoutTypes.get(0));
    Assert.assertEquals("Wrong class found as second in array", RouteParentLayout.class, routerLayoutTypes.get(1));
}
Also used : RouterLayout(com.vaadin.flow.router.RouterLayout) NavigationStateRenderer(com.vaadin.flow.router.internal.NavigationStateRenderer) Test(org.junit.Test)

Example 4 with NavigationStateRenderer

use of com.vaadin.flow.router.internal.NavigationStateRenderer in project flow by vaadin.

the class NavigationStateRendererTest method instantiatorUse.

@Test
public void instantiatorUse() throws ServiceException {
    MockVaadinServletService service = new MockVaadinServletService();
    service.init(new MockInstantiator() {

        @Override
        public <T extends HasElement> T createRouteTarget(Class<T> routeTargetType, NavigationEvent event) {
            Assert.assertEquals(Component.class, routeTargetType);
            return (T) new Text("foo");
        }
    });
    MockUI ui = new MockUI(new MockVaadinSession(service));
    NavigationEvent event = new NavigationEvent(new Router(new TestRouteRegistry()), new Location(""), ui, NavigationTrigger.PAGE_LOAD);
    NavigationStateRenderer renderer = new NavigationStateRenderer(navigationStateFromTarget(ChildConfiguration.class));
    Component routeTarget = renderer.getRouteTarget(Component.class, event);
    Assert.assertEquals(Text.class, routeTarget.getClass());
    UI.setCurrent(null);
}
Also used : NavigationEvent(com.vaadin.flow.router.NavigationEvent) MockVaadinServletService(com.vaadin.flow.server.MockVaadinServletService) Router(com.vaadin.flow.router.Router) Text(com.vaadin.flow.component.Text) TestRouteRegistry(com.vaadin.flow.router.TestRouteRegistry) MockUI(com.vaadin.tests.util.MockUI) MockVaadinSession(com.vaadin.flow.server.MockVaadinSession) MockInstantiator(com.vaadin.flow.server.MockInstantiator) Component(com.vaadin.flow.component.Component) Location(com.vaadin.flow.router.Location) NavigationStateRenderer(com.vaadin.flow.router.internal.NavigationStateRenderer) Test(org.junit.Test)

Example 5 with NavigationStateRenderer

use of com.vaadin.flow.router.internal.NavigationStateRenderer in project flow by vaadin.

the class NavigationStateRendererTest method getRouterLayoutForSingleParent.

@Test
public void getRouterLayoutForSingleParent() throws Exception {
    NavigationStateRenderer childRenderer = new NavigationStateRenderer(navigationStateFromTarget(SingleView.class));
    List<Class<? extends RouterLayout>> routerLayoutTypes = childRenderer.getRouterLayoutTypes(SingleView.class);
    Assert.assertEquals("Not all expected layouts were found", 1, routerLayoutTypes.size());
    Assert.assertEquals("Wrong class found", RouteParentLayout.class, routerLayoutTypes.get(0));
}
Also used : RouterLayout(com.vaadin.flow.router.RouterLayout) NavigationStateRenderer(com.vaadin.flow.router.internal.NavigationStateRenderer) Test(org.junit.Test)

Aggregations

NavigationStateRenderer (com.vaadin.flow.router.internal.NavigationStateRenderer)7 Test (org.junit.Test)4 RouterLayout (com.vaadin.flow.router.RouterLayout)3 Component (com.vaadin.flow.component.Component)1 Text (com.vaadin.flow.component.Text)1 Location (com.vaadin.flow.router.Location)1 NavigationEvent (com.vaadin.flow.router.NavigationEvent)1 Router (com.vaadin.flow.router.Router)1 TestRouteRegistry (com.vaadin.flow.router.TestRouteRegistry)1 InternalRedirectHandler (com.vaadin.flow.router.internal.InternalRedirectHandler)1 ResolveRequest (com.vaadin.flow.router.internal.ResolveRequest)1 MockInstantiator (com.vaadin.flow.server.MockInstantiator)1 MockVaadinServletService (com.vaadin.flow.server.MockVaadinServletService)1 MockVaadinSession (com.vaadin.flow.server.MockVaadinSession)1 MockUI (com.vaadin.tests.util.MockUI)1