Search in sources :

Example 1 with RouterLink

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

the class ComponentEventBusTest method mappedDomEventWithComponentEventData_clientReportsSiblingComponentToEventSource_mapsComponents.

@Test
public void mappedDomEventWithComponentEventData_clientReportsSiblingComponentToEventSource_mapsComponents() {
    final MockUI ui = new MockUI();
    final TestComponent component = new TestComponent();
    final TestComponent child = new TestComponent();
    final RouterLink routerLink = new RouterLink();
    ui.add(component, child, routerLink);
    final EventTracker<MappedDomEventWithRouterLinkData> listener = new EventTracker<>();
    component.addListener(MappedDomEventWithRouterLinkData.class, listener);
    fireDomEvent(component, "dom-event", createStateNodeIdData("component", component.getElement().getNode().getId(), "router.link", routerLink.getElement().getNode().getId()));
    listener.assertEventCalled(component, true);
    Assert.assertEquals(routerLink, listener.getEvent().getRouterLink());
    Assert.assertEquals(component, listener.getEvent().getComponent());
}
Also used : MockUI(com.vaadin.tests.util.MockUI) RouterLink(com.vaadin.flow.router.RouterLink) TestComponent(com.vaadin.flow.component.ComponentTest.TestComponent) Test(org.junit.Test)

Example 2 with RouterLink

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

the class Layout method createRouterLink.

private RouterLink createRouterLink(String text, Class<? extends Component> clazz, String id) {
    RouterLink link = new RouterLink(text, clazz);
    link.getStyle().set("display", "block");
    link.setId(id);
    return link;
}
Also used : RouterLink(com.vaadin.flow.router.RouterLink)

Example 3 with RouterLink

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

the class ParentNoOwnerView method onAttach.

@Override
protected void onAttach(AttachEvent attachEvent) {
    if (attachEvent.isInitialAttach()) {
        RouterLink link = new RouterLink("child", ChildNoOwnerView.class);
        link.setId("to-child");
        add(link);
        Div div = new Div();
        div.setId("parent-info");
        div.getElement().getStyle().set("display", "block");
        div.setText(bean.getValue());
        add(div);
    }
}
Also used : Div(com.vaadin.flow.component.html.Div) RouterLink(com.vaadin.flow.router.RouterLink)

Example 4 with RouterLink

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

the class DragSourceTest method testDragSource_serverSideEvents_correctData.

@Test
public void testDragSource_serverSideEvents_correctData() {
    RouterLink component = new RouterLink();
    ui.add(component);
    DragSource<RouterLink> dragSource = DragSource.create(component);
    AtomicReference<DragStartEvent<RouterLink>> startEventCapture = new AtomicReference<>();
    AtomicReference<DragEndEvent<RouterLink>> endEventCapture = new AtomicReference<>();
    dragSource.addDragStartListener(startEventCapture::set);
    dragSource.addDragEndListener(endEventCapture::set);
    DragStartEvent<RouterLink> startEvent = new DragStartEvent<RouterLink>(component, true);
    ComponentUtil.fireEvent(component, startEvent);
    Assert.assertEquals(startEvent, startEventCapture.get());
    Assert.assertEquals(component, UI.getCurrent().getActiveDragSourceComponent());
    Assert.assertTrue(startEvent.isFromClient());
    DragEndEvent<RouterLink> endEvent = new DragEndEvent<RouterLink>(component, false, DropEffect.MOVE.name().toLowerCase());
    ComponentUtil.fireEvent(component, endEvent);
    DragEndEvent<RouterLink> endEvent2 = endEventCapture.get();
    Assert.assertEquals(endEvent, endEvent2);
    Assert.assertNull(UI.getCurrent().getActiveDragSourceComponent());
    Assert.assertEquals(DropEffect.MOVE, endEvent2.getDropEffect());
    Assert.assertTrue(endEvent2.isSuccessful());
    Assert.assertFalse(endEvent2.isFromClient());
    endEvent = new DragEndEvent<RouterLink>(component, true, "None");
    ComponentUtil.fireEvent(component, endEvent);
    endEvent2 = endEventCapture.get();
    Assert.assertEquals(endEvent, endEvent2);
    Assert.assertNull(UI.getCurrent().getActiveDragSourceComponent());
    Assert.assertEquals(DropEffect.NONE, endEvent2.getDropEffect());
    Assert.assertFalse(endEvent2.isSuccessful());
    Assert.assertTrue(endEvent2.isFromClient());
}
Also used : RouterLink(com.vaadin.flow.router.RouterLink) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 5 with RouterLink

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

the class DragSourceTest method testDragSource_staticBuilder_wrapsComponent.

@Test
public void testDragSource_staticBuilder_wrapsComponent() {
    RouterLink component = new RouterLink();
    DragSource<RouterLink> dragSource = DragSource.create(component);
    Assert.assertEquals("component element not set draggable", "true", component.getElement().getProperty("draggable"));
    Assert.assertEquals(component, dragSource.getDragSourceComponent());
    Assert.assertEquals(EffectAllowed.UNINITIALIZED, dragSource.getEffectAllowed());
    dragSource.setEffectAllowed(EffectAllowed.COPY_MOVE);
    Assert.assertEquals(component.getElement().getProperty(DndUtil.EFFECT_ALLOWED_ELEMENT_PROPERTY), EffectAllowed.COPY_MOVE.getClientPropertyValue());
    DragSource.configure(component, false);
    Assert.assertNull(component.getElement().getProperty("draggable"));
    DropTarget.configure(component);
    Assert.assertNull(component.getElement().getProperty("draggable"));
    DragSource.configure(component, true);
    Assert.assertEquals("component element not set draggable", "true", component.getElement().getProperty("draggable"));
    DropTarget.configure(component);
    Assert.assertEquals("component element not set draggable", "true", component.getElement().getProperty("draggable"));
}
Also used : RouterLink(com.vaadin.flow.router.RouterLink) 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