use of com.vaadin.flow.router.legacy.Router in project flow by vaadin.
the class RouterTest method testChangeLocation.
@Test
public void testChangeLocation() {
UI ui = new RouterTestUI();
Router router = new Router();
TestResolver resolver = new TestResolver();
router.reconfigure(c -> c.setResolver(resolver));
VaadinRequest request = requestWithPathInfo(null);
router.initializeUI(ui, request);
Assert.assertEquals(Arrays.asList(""), resolver.resolvedLocation.get().getSegments());
resolver.resolvedLocation.set(null);
resolver.handledEvent.set(null);
ui.getPage().getHistory().getHistoryStateChangeHandler().onHistoryStateChange(new HistoryStateChangeEvent(ui.getPage().getHistory(), null, new Location("foo"), NavigationTrigger.HISTORY));
Assert.assertEquals(Arrays.asList("foo"), resolver.resolvedLocation.get().getSegments());
}
use of com.vaadin.flow.router.legacy.Router in project flow by vaadin.
the class RouterTest method testResolverError_noCurrentResponse.
@Test
public void testResolverError_noCurrentResponse() {
UI ui = new RouterTestUI();
Router router = new Router();
router.reconfigure(c -> c.setResolver(event -> Optional.empty()));
router.navigate(ui, new Location(""), NavigationTrigger.PROGRAMMATIC);
Assert.assertTrue(ui.getElement().getTextRecursively().contains("404"));
}
use of com.vaadin.flow.router.legacy.Router in project flow by vaadin.
the class RouterTest method testNavigateToEmptyLocation_triggersDefaultErrorView.
@Test
public void testNavigateToEmptyLocation_triggersDefaultErrorView() {
UI ui = new RouterTestUI();
Router router = new Router();
router.reconfigure(c -> {
});
router.navigate(ui, new Location(""), NavigationTrigger.PROGRAMMATIC);
Assert.assertEquals(new DefaultErrorView().getText(), ui.getElement().getTextRecursively());
}
use of com.vaadin.flow.router.legacy.Router in project flow by vaadin.
the class RouterLinkTest method reconfigureRouterLink_attachedLink.
@Test
public void reconfigureRouterLink_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, "other");
Assert.assertEquals("show/other", link.getElement().getAttribute("href"));
link.setRoute(router, TestView.class, "changed");
Assert.assertEquals("show/changed", link.getElement().getAttribute("href"));
}
use of com.vaadin.flow.router.legacy.Router in project flow by vaadin.
the class RouterLinkTest method createRouterLink_explicitRouter.
@Test
public void createRouterLink_explicitRouter() {
Router router = new Router();
router.reconfigure(c -> c.setRoute("show/{bar}", TestView.class));
RouterLink link = new RouterLink(router, "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"));
}
Aggregations