|
| 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