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