Search in sources :

Example 1 with AfterNavigationHandler

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

the class VaadinRouteScopeTest method navigateTo.

private void navigateTo(UI ui, Component component) {
    AfterNavigationEvent event = Mockito.mock(AfterNavigationEvent.class);
    Mockito.when(event.getActiveChain()).thenReturn(Collections.singletonList(component));
    List<AfterNavigationHandler> navigationListeners = ui.getNavigationListeners(AfterNavigationHandler.class);
    navigationListeners.forEach(listener -> listener.afterNavigation(event));
}
Also used : AfterNavigationEvent(com.vaadin.flow.router.AfterNavigationEvent) AfterNavigationHandler(com.vaadin.flow.router.internal.AfterNavigationHandler)

Example 2 with AfterNavigationHandler

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

the class UITest method after_navigation_listener_priority_should_dictate_sort_order.

@Test
public void after_navigation_listener_priority_should_dictate_sort_order() throws InvalidRouteConfigurationException {
    UI ui = createTestUI();
    initUI(ui, "", null);
    ui.addAfterNavigationListener(new AfterNavigationListenerThird());
    ui.addAfterNavigationListener(new AfterNavigationListenerThird());
    ui.addAfterNavigationListener(new AfterNavigationListenerFirst());
    ui.addAfterNavigationListener(new AfterNavigationListenerSecond());
    final List<AfterNavigationHandler> AfterNavigationListeners = ui.getNavigationListeners(AfterNavigationHandler.class);
    assertEquals(4, AfterNavigationListeners.size());
    assertTrue(AfterNavigationListeners.get(0) instanceof AfterNavigationListenerFirst);
    assertTrue(AfterNavigationListeners.get(1) instanceof AfterNavigationListenerSecond);
    assertTrue(AfterNavigationListeners.get(2) instanceof AfterNavigationListenerThird);
    assertTrue(AfterNavigationListeners.get(3) instanceof AfterNavigationListenerThird);
}
Also used : MockUI(com.vaadin.tests.util.MockUI) AfterNavigationHandler(com.vaadin.flow.router.internal.AfterNavigationHandler) BootstrapHandlerTest(com.vaadin.flow.server.BootstrapHandlerTest) Test(org.junit.Test)

Aggregations

AfterNavigationHandler (com.vaadin.flow.router.internal.AfterNavigationHandler)2 AfterNavigationEvent (com.vaadin.flow.router.AfterNavigationEvent)1 BootstrapHandlerTest (com.vaadin.flow.server.BootstrapHandlerTest)1 MockUI (com.vaadin.tests.util.MockUI)1 Test (org.junit.Test)1