use of com.vaadin.flow.component.ComponentEventListener 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());
}
Aggregations