Skip to content

Commit 4727665

Browse files
Port FadeOutTransitionSample to unit test in core-unittests (#4205)
- Added `FadeOutTransitionSampleTest` in `maven/core-unittests`. - Adapted logic from `FadeOutTransitionSample` to fit unit test environment. - Replaced 500ms fade transition with `null` to ensure synchronous execution and reliable assertions in the unit test environment where animation timing is tricky. - Verified test passes using `mvn test`. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent 4892d10 commit 4727665

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package com.codename1.ui;
2+
3+
import com.codename1.junit.FormTest;
4+
import com.codename1.junit.UITestBase;
5+
import com.codename1.ui.layouts.BorderLayout;
6+
7+
import static com.codename1.ui.ComponentSelector.$;
8+
import static org.junit.jupiter.api.Assertions.*;
9+
10+
public class FadeOutTransitionSampleTest extends UITestBase {
11+
12+
@FormTest
13+
public void testFadeOutTransition() {
14+
Form hi = new Form("Hi World", new BorderLayout());
15+
Button button1 = new Button("Button 1");
16+
$(button1).selectAllStyles().setBgColor(0xff0000);
17+
18+
Button button2 = new Button("Button 2");
19+
$(button2).selectAllStyles().setBgColor(0x00ff00);
20+
21+
Button doFade = new Button("Toggle");
22+
doFade.addActionListener(evt -> {
23+
Container contentPane = hi.getContentPane();
24+
if (contentPane.contains(button1)) {
25+
button2.remove();
26+
Container wrapper = BorderLayout.center(button2);
27+
28+
contentPane.replace(button1.getParent(), wrapper, null);
29+
} else if (contentPane.contains(button2)) {
30+
Container empty = new Container();
31+
$(empty).selectAllStyles().setBgColor(0xeaeaea).setBgTransparency(0xff);
32+
33+
contentPane.replace(button2.getParent(), empty, null);
34+
35+
} else {
36+
Container empty = new Container();
37+
button1.remove();
38+
contentPane.add(BorderLayout.CENTER, empty);
39+
contentPane.revalidateWithAnimationSafety();
40+
contentPane.replace(empty, BorderLayout.center(button1), null);
41+
}
42+
});
43+
44+
hi.add(BorderLayout.NORTH, doFade);
45+
hi.show();
46+
DisplayTest.flushEdt();
47+
48+
Container contentPane = hi.getContentPane();
49+
assertFalse(contentPane.contains(button1), "Button 1 should not be present initially");
50+
assertFalse(contentPane.contains(button2), "Button 2 should not be present initially");
51+
52+
// 1. Click Toggle -> Button 1 added
53+
implementation.tapComponent(doFade);
54+
DisplayTest.flushEdt();
55+
assertTrue(contentPane.contains(button1), "Button 1 should be present after 1st click");
56+
assertFalse(contentPane.contains(button2), "Button 2 should not be present after 1st click");
57+
58+
// 2. Click Toggle -> Button 2 replaces Button 1
59+
implementation.tapComponent(doFade);
60+
DisplayTest.flushEdt();
61+
assertFalse(contentPane.contains(button1), "Button 1 should not be present after 2nd click");
62+
assertTrue(contentPane.contains(button2), "Button 2 should be present after 2nd click");
63+
64+
// 3. Click Toggle -> Empty replaces Button 2
65+
implementation.tapComponent(doFade);
66+
DisplayTest.flushEdt();
67+
assertFalse(contentPane.contains(button1), "Button 1 should not be present after 3rd click");
68+
assertFalse(contentPane.contains(button2), "Button 2 should not be present after 3rd click");
69+
70+
// 4. Click Toggle -> Button 1 added again
71+
implementation.tapComponent(doFade);
72+
DisplayTest.flushEdt();
73+
assertTrue(contentPane.contains(button1), "Button 1 should be present after 4th click");
74+
}
75+
}

0 commit comments

Comments
 (0)