Search in sources :

Example 11 with RouterLink

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

the class JavaScriptBootstrapUITest method addRemoveComponent_serverSideRouting_addsDirectlyToUI.

@Test
public void addRemoveComponent_serverSideRouting_addsDirectlyToUI() {
    Mockito.when(mocks.getSession().getAttribute(SERVER_ROUTING)).thenReturn(Boolean.TRUE);
    assertEquals(0, ui.getElement().getChildCount());
    assertEquals(0, ui.getChildren().count());
    // use any server side route
    ui.navigate("product");
    assertEquals(1, ui.getElement().getChildCount());
    assertEquals(1, ui.getChildren().count());
    final RouterLink routerLink = new RouterLink();
    ui.add(routerLink);
    assertEquals(2, ui.getElement().getChildCount());
    assertEquals(2, ui.getChildren().count());
    ui.remove(routerLink);
    assertEquals(1, ui.getElement().getChildCount());
    assertEquals(1, ui.getChildren().count());
}
Also used : RouterLink(com.vaadin.flow.router.RouterLink) Test(org.junit.Test)

Example 12 with RouterLink

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

the class JavaScriptBootstrapUITest method addComponent_clientSideRouterAndNavigation_componentsRemain.

@Test
public void addComponent_clientSideRouterAndNavigation_componentsRemain() {
    final Element uiElement = ui.getElement();
    // trigger route via client
    ui.connectClient("foo", "bar", "/clean", "", null);
    final RouterLink routerLink = new RouterLink();
    ui.add(routerLink);
    assertEquals(2, ui.getChildren().count());
    assertEquals(1, ui.getElement().getChildCount());
    assertEquals(1, uiElement.getChildCount());
    ui.navigate("product");
    assertEquals(2, ui.getChildren().count());
    assertEquals(1, ui.getElement().getChildCount());
    assertEquals(1, uiElement.getChildCount());
}
Also used : RouterLink(com.vaadin.flow.router.RouterLink) Element(com.vaadin.flow.dom.Element) Test(org.junit.Test)

Example 13 with RouterLink

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

the class AbstractDnDUnitTest method testExtension_mobileDnDpolyfillScriptInjected.

@Test
public void testExtension_mobileDnDpolyfillScriptInjected() {
    ui.getInternals().dumpPendingJavaScriptInvocations();
    RouterLink component = new RouterLink();
    ui.add(component);
    runStaticCreateMethodForExtension(component);
    List<PendingJavaScriptInvocation> pendingJavaScriptInvocations = ui.getInternals().dumpPendingJavaScriptInvocations();
    Assert.assertEquals(1, pendingJavaScriptInvocations.size());
    PendingJavaScriptInvocation pendingJavaScriptInvocation = pendingJavaScriptInvocations.get(0);
    // the urls are switched to "" by the mocked service method
    String fake = String.format(DnDUtilHelper.MOBILE_DND_INJECT_SCRIPT, "", "");
    Assert.assertEquals(fake, pendingJavaScriptInvocation.getInvocation().getExpression());
}
Also used : RouterLink(com.vaadin.flow.router.RouterLink) PendingJavaScriptInvocation(com.vaadin.flow.component.internal.PendingJavaScriptInvocation) Test(org.junit.Test)

Example 14 with RouterLink

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

the class AbstractDnDUnitTest method testExtension_activated_usageStatisticsEntryAdded.

@Test
public void testExtension_activated_usageStatisticsEntryAdded() {
    runStaticCreateMethodForExtension(new RouterLink());
    Assert.assertTrue("No usage statistics for generic dnd reported", UsageStatistics.getEntries().anyMatch(entry -> entry.getName().contains("generic-dnd")));
}
Also used : VaadinSession(com.vaadin.flow.server.VaadinSession) DependencyList(com.vaadin.flow.component.internal.DependencyList) Properties(java.util.Properties) Component(com.vaadin.flow.component.Component) Collection(java.util.Collection) PendingJavaScriptInvocation(com.vaadin.flow.component.internal.PendingJavaScriptInvocation) VaadinServlet(com.vaadin.flow.server.VaadinServlet) Test(org.junit.Test) DnDUtilHelper(com.vaadin.flow.component.dnd.internal.DnDUtilHelper) Dependency(com.vaadin.flow.shared.ui.Dependency) Mockito(org.mockito.Mockito) List(java.util.List) VaadinContext(com.vaadin.flow.server.VaadinContext) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration) DefaultDeploymentConfiguration(com.vaadin.flow.server.DefaultDeploymentConfiguration) UsageStatistics(com.vaadin.flow.internal.UsageStatistics) VaadinService(com.vaadin.flow.server.VaadinService) RouterLink(com.vaadin.flow.router.RouterLink) Lookup(com.vaadin.flow.di.Lookup) Assert(org.junit.Assert) Collections(java.util.Collections) Before(org.junit.Before) RouterLink(com.vaadin.flow.router.RouterLink) Test(org.junit.Test)

Example 15 with RouterLink

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

the class DropTargetTest method testDragAndDrop_serverSideDragData.

@Test
public void testDragAndDrop_serverSideDragData() {
    RouterLink source = new RouterLink();
    ui.add(source);
    DragSource<RouterLink> dragSource = DragSource.create(source);
    RouterLink target = new RouterLink();
    ui.add(target);
    DropTarget<RouterLink> dropTarget = DropTarget.create(target);
    dragSource.setDragData("FOOBAR");
    AtomicReference<DropEvent<RouterLink>> eventCapture = new AtomicReference<>();
    dropTarget.addDropListener(eventCapture::set);
    ComponentUtil.fireEvent(source, new DragStartEvent<>(source, true));
    DropEvent<RouterLink> dropEvent = new DropEvent<>(target, true, "all");
    ComponentUtil.fireEvent(target, dropEvent);
    DropEvent<RouterLink> actualEvent = eventCapture.get();
    Assert.assertEquals(dropEvent, actualEvent);
    Assert.assertEquals("FOOBAR", actualEvent.getDragData().orElse(null));
    Assert.assertEquals(source, actualEvent.getDragSourceComponent().orElse(null));
    // not firing end event for this test but it should be fine as the drag
    // data and active source is overridden
    ComponentUtil.fireEvent(source, new DragStartEvent<>(source, true));
    dragSource.setDragData("another");
    ComponentUtil.fireEvent(target, dropEvent);
    actualEvent = eventCapture.get();
    Assert.assertEquals(dropEvent, actualEvent);
    Assert.assertEquals("another", actualEvent.getDragData().orElse(null));
    Assert.assertEquals(source, actualEvent.getDragSourceComponent().orElse(null));
}
Also used : RouterLink(com.vaadin.flow.router.RouterLink) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Aggregations

RouterLink (com.vaadin.flow.router.RouterLink)30 Test (org.junit.Test)23 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 TestComponent (com.vaadin.flow.component.ComponentTest.TestComponent)3 Element (com.vaadin.flow.dom.Element)3 MockUI (com.vaadin.tests.util.MockUI)3 Component (com.vaadin.flow.component.Component)2 Div (com.vaadin.flow.component.html.Div)2 DependencyList (com.vaadin.flow.component.internal.DependencyList)2 PendingJavaScriptInvocation (com.vaadin.flow.component.internal.PendingJavaScriptInvocation)2 Registration (com.vaadin.flow.shared.Registration)2 Dependency (com.vaadin.flow.shared.ui.Dependency)2 Assert (org.junit.Assert)2 Before (org.junit.Before)2 ComponentEventListener (com.vaadin.flow.component.ComponentEventListener)1 ComponentUtil (com.vaadin.flow.component.ComponentUtil)1 HasComponents (com.vaadin.flow.component.HasComponents)1 Tag (com.vaadin.flow.component.Tag)1 UI (com.vaadin.flow.component.UI)1 DnDUtilHelper (com.vaadin.flow.component.dnd.internal.DnDUtilHelper)1