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());
}
Aggregations