Skip to content

Commit 9ddcd0d

Browse files
authored
Add regression test for draggable lead component drag finished (#4198)
1 parent 32bb869 commit 9ddcd0d

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.codename1.ui;
2+
3+
import com.codename1.junit.FormTest;
4+
import com.codename1.junit.UITestBase;
5+
import com.codename1.ui.Container;
6+
import com.codename1.ui.Display;
7+
import com.codename1.ui.Form;
8+
import com.codename1.ui.Label;
9+
import com.codename1.ui.geom.Dimension;
10+
import com.codename1.ui.layouts.BoxLayout;
11+
12+
import static org.junit.jupiter.api.Assertions.assertTrue;
13+
14+
/**
15+
* Regression test for drag and drop interactions when a container sets a lead component
16+
* that is also draggable. This mimics the behaviour from the DnDRegression3048 sample and
17+
* ensures drag events propagate through the full stack using {@link Form#pointerPressed(int, int)}
18+
* and related APIs.
19+
*/
20+
class DnDRegression3048Test extends UITestBase {
21+
22+
@FormTest
23+
void dragFinishedFiresWhenDraggingLeadComponent() {
24+
implementation.setBuiltinSoundsEnabled(false);
25+
Form form = Display.getInstance().getCurrent();
26+
27+
Container container = new Container(BoxLayout.y());
28+
Label imageLabel = new Label("icon");
29+
imageLabel.setPreferredSize(new Dimension(48, 48));
30+
imageLabel.setDraggable(true);
31+
32+
container.putClientProperty("isTest", Boolean.TRUE);
33+
container.setLeadComponent(imageLabel);
34+
container.setDraggable(true);
35+
36+
container.add(imageLabel);
37+
container.add(new Label("Another label in the container"));
38+
form.add(container);
39+
form.revalidate();
40+
41+
final int[] pointerDraggedCount = {0};
42+
final int[] dragFinishedCount = {0};
43+
final int[] leadDragFinishedCount = {0};
44+
45+
imageLabel.addPointerDraggedListener(evt -> pointerDraggedCount[0]++);
46+
container.addDragFinishedListener(evt -> dragFinishedCount[0]++);
47+
imageLabel.addDragFinishedListener(evt -> leadDragFinishedCount[0]++);
48+
49+
int startX = imageLabel.getAbsoluteX() + 10;
50+
int startY = imageLabel.getAbsoluteY() + 10;
51+
int endX = startX + 30;
52+
int endY = startY + 30;
53+
54+
form.pointerPressed(startX, startY);
55+
form.pointerDragged(endX, endY);
56+
form.pointerDragged(endX + 10, endY + 10);
57+
form.pointerReleased(endX, endY);
58+
59+
assertTrue(pointerDraggedCount[0] > 0, "Lead component should receive drag events");
60+
assertTrue(dragFinishedCount[0] > 0 || leadDragFinishedCount[0] > 0,
61+
"Drag finished events should fire on the container or its lead component");
62+
}
63+
}
64+

0 commit comments

Comments
 (0)