Search in sources :

Example 6 with RouteBaseData

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

the class AbstractRouteRegistryTest method routeChangeListener_blockChangesAreGivenCorrectlyInEvent.

@Test
public void routeChangeListener_blockChangesAreGivenCorrectlyInEvent() {
    registry.setRoute("", MyRoute.class, Collections.emptyList());
    List<RouteBaseData> added = new ArrayList<>();
    List<RouteBaseData> removed = new ArrayList<>();
    registry.addRoutesChangeListener(event -> {
        added.clear();
        removed.clear();
        added.addAll(event.getAddedRoutes());
        removed.addAll(event.getRemovedRoutes());
    });
    registry.update(() -> {
        registry.removeRoute("");
        registry.setRoute("path", Secondary.class, Collections.emptyList());
        registry.setRoute("", MyRoute.class, Collections.singletonList(MainLayout.class));
    });
    Assert.assertFalse("", added.isEmpty());
    Assert.assertEquals("", 2, added.size());
    Assert.assertFalse("", removed.isEmpty());
    for (RouteBaseData data : added) {
        if (data.getUrl().equals("")) {
            Assert.assertEquals("MyRoute should have been added", MyRoute.class, data.getNavigationTarget());
            Assert.assertEquals("MyRoute should have been seen as a update as the parent layouts changed.", MainLayout.class, data.getParentLayout());
        } else {
            Assert.assertEquals("", Secondary.class, data.getNavigationTarget());
        }
    }
    Assert.assertEquals("MyRoute should have been both removed and added", MyRoute.class, removed.get(0).getNavigationTarget());
    Assert.assertEquals("Removed version should not have a parent layout", Collections.emptyList(), removed.get(0).getParentLayouts());
}
Also used : RouteBaseData(com.vaadin.flow.router.RouteBaseData) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

RouteBaseData (com.vaadin.flow.router.RouteBaseData)6 ArrayList (java.util.ArrayList)6 RouteData (com.vaadin.flow.router.RouteData)3 Test (org.junit.Test)3 Component (com.vaadin.flow.component.Component)2 RouteParameters (com.vaadin.flow.router.RouteParameters)2 RouterLayout (com.vaadin.flow.router.RouterLayout)2 RoutesChangedEvent (com.vaadin.flow.router.RoutesChangedEvent)2 RoutesChangedListener (com.vaadin.flow.router.RoutesChangedListener)2 Registration (com.vaadin.flow.shared.Registration)2 List (java.util.List)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 SerializableBiConsumer (com.vaadin.flow.function.SerializableBiConsumer)1 ReflectTools (com.vaadin.flow.internal.ReflectTools)1 HasErrorParameter (com.vaadin.flow.router.HasErrorParameter)1 NotFoundException (com.vaadin.flow.router.NotFoundException)1 RouteAliasData (com.vaadin.flow.router.RouteAliasData)1 AbstractRouteRegistry (com.vaadin.flow.router.internal.AbstractRouteRegistry)1