use of com.vaadin.flow.router.RouterLink in project flow by vaadin.
the class DropTargetTest method testDropTarget_dropInSideSameUI_moveComponentToTargetInDropEvent.
@Test
public void testDropTarget_dropInSideSameUI_moveComponentToTargetInDropEvent() {
RouterLink source = new RouterLink();
TestComponent target = new TestComponent();
ui.add(source, target);
DragSource<RouterLink> dragSource = DragSource.create(source);
DropTarget<TestComponent> dropTarget = DropTarget.create(target);
DragStartEvent<RouterLink> startEvent = new DragStartEvent<RouterLink>(source, true);
ComponentUtil.fireEvent(source, startEvent);
Assert.assertEquals(source, ui.getActiveDragSourceComponent());
ComponentEventListener<DropEvent<TestComponent>> dropListener = event -> {
event.getDragSourceComponent().ifPresent(dragSourceComponent -> {
TestComponent component = event.getComponent();
Assert.assertEquals("Invalid drag source component", dragSourceComponent, source);
Assert.assertEquals("Invalid event source", component, target);
target.add(dragSourceComponent);
});
// ELSE will be failed by the checks outside the listener
};
target.addDropListener(dropListener);
DropEvent<TestComponent> dropEvent = new DropEvent<>(target, true, "all");
ComponentUtil.fireEvent(target, dropEvent);
Assert.assertEquals("Drag source component should have been moved", source.getParent().get(), target);
DragEndEvent<RouterLink> endEvent = new DragEndEvent<>(source, true, "move");
// should not throw for removing the active drag source
ComponentUtil.fireEvent(source, endEvent);
Assert.assertNull(ui.getActiveDragSourceComponent());
}
use of com.vaadin.flow.router.RouterLink in project flow by vaadin.
the class DropTargetTest method testDropTarget_dropListener_correctData.
@Test
public void testDropTarget_dropListener_correctData() {
RouterLink component = new RouterLink();
ui.add(component);
DropTarget<RouterLink> dropTarget = DropTarget.create(component);
AtomicReference<DropEvent<RouterLink>> eventCapture = new AtomicReference<>();
dropTarget.addDropListener(eventCapture::set);
DropEvent<RouterLink> dropEvent = new DropEvent<>(component, true, "all");
ComponentUtil.fireEvent(component, dropEvent);
DropEvent<RouterLink> actualEvent = eventCapture.get();
Assert.assertEquals(dropEvent, actualEvent);
Assert.assertTrue(actualEvent.isFromClient());
Assert.assertEquals(component, actualEvent.getComponent());
Assert.assertEquals(EffectAllowed.ALL, actualEvent.getEffectAllowed());
Assert.assertEquals(null, actualEvent.getDropEffect());
Assert.assertFalse(actualEvent.getDragData().isPresent());
dropTarget.setDropEffect(DropEffect.COPY);
dropEvent = new DropEvent<>(component, false, "copymove");
ComponentUtil.fireEvent(component, dropEvent);
actualEvent = eventCapture.get();
Assert.assertEquals(dropEvent, actualEvent);
Assert.assertFalse(actualEvent.isFromClient());
Assert.assertEquals(component, actualEvent.getComponent());
Assert.assertEquals(EffectAllowed.COPY_MOVE, actualEvent.getEffectAllowed());
Assert.assertEquals(DropEffect.COPY, actualEvent.getDropEffect());
Assert.assertFalse(actualEvent.getDragData().isPresent());
Assert.assertFalse(actualEvent.getDragSourceComponent().isPresent());
}
use of com.vaadin.flow.router.RouterLink in project flow by vaadin.
the class DropTargetTest method testDropTarget_staticBuilder_wrapsComponent.
@Test
public void testDropTarget_staticBuilder_wrapsComponent() {
RouterLink component = new RouterLink();
DropTarget<RouterLink> dropTarget = DropTarget.create(component);
Assert.assertTrue(component.getElement().getProperty(DndUtil.DROP_TARGET_ACTIVE_PROPERTY, false));
Assert.assertNull(dropTarget.getDropEffect());
DropTarget.configure(component, false);
Assert.assertFalse(component.getElement().getProperty(DndUtil.DROP_TARGET_ACTIVE_PROPERTY, false));
DropTarget.configure(component);
Assert.assertFalse(component.getElement().getProperty(DndUtil.DROP_TARGET_ACTIVE_PROPERTY, false));
DropTarget.configure(component, true);
Assert.assertTrue(component.getElement().getProperty(DndUtil.DROP_TARGET_ACTIVE_PROPERTY, false));
DropTarget.configure(component);
Assert.assertTrue(component.getElement().getProperty(DndUtil.DROP_TARGET_ACTIVE_PROPERTY, false));
}
use of com.vaadin.flow.router.RouterLink in project flow by vaadin.
the class DragSourceTest method testDragSource_notAttachedToUIAndCatchesDragEndEvent_doesNotThrow.
@Test
public void testDragSource_notAttachedToUIAndCatchesDragEndEvent_doesNotThrow() {
RouterLink component = new RouterLink();
ui.add(component);
DragSource<RouterLink> dragSource = DragSource.create(component);
DragStartEvent<RouterLink> startEvent = new DragStartEvent<RouterLink>(component, true);
ComponentUtil.fireEvent(component, startEvent);
Assert.assertEquals(component, ui.getActiveDragSourceComponent());
// the drop event could remove the component if in same UI
ui.remove(component);
DragEndEvent<RouterLink> endEvent = new DragEndEvent<>(component, true, "move");
// should not throw for removing the active drag source
ComponentUtil.fireEvent(component, endEvent);
Assert.assertNull(ui.getActiveDragSourceComponent());
}
use of com.vaadin.flow.router.RouterLink in project flow by vaadin.
the class DragSourceTest method testDragSource_notAttachedToUIAndCatchesDragStartEvent_throws.
@Test(expected = IllegalStateException.class)
public void testDragSource_notAttachedToUIAndCatchesDragStartEvent_throws() {
RouterLink component = new RouterLink();
DragSource<RouterLink> dragSource = DragSource.create(component);
DragStartEvent<RouterLink> startEvent = new DragStartEvent<RouterLink>(component, true);
ComponentUtil.fireEvent(component, startEvent);
}
Aggregations