11package com .reactnativenavigation .views ;
22
3+ import android .graphics .Rect ;
34import android .view .MotionEvent ;
5+ import android .view .View ;
6+ import android .view .ViewGroup ;
47
8+ import com .facebook .react .views .debuggingoverlay .DebuggingOverlay ;
59import com .reactnativenavigation .BaseTest ;
610import com .reactnativenavigation .options .params .Bool ;
711import com .reactnativenavigation .react .ReactView ;
812import com .reactnativenavigation .views .component .ComponentLayout ;
913import com .reactnativenavigation .views .touch .OverlayTouchDelegate ;
1014
1115import org .junit .Test ;
16+ import org .mockito .stubbing .Answer ;
1217
1318import static org .assertj .core .api .Java6Assertions .assertThat ;
19+ import static org .mockito .ArgumentMatchers .any ;
20+ import static org .mockito .Mockito .doAnswer ;
1421import static org .mockito .Mockito .mock ;
1522import static org .mockito .Mockito .spy ;
1623import static org .mockito .Mockito .times ;
1724import static org .mockito .Mockito .verify ;
25+ import static org .mockito .Mockito .when ;
1826
1927public class OverlayTouchDelegateTest extends BaseTest {
2028 private OverlayTouchDelegate uut ;
@@ -23,16 +31,60 @@ public class OverlayTouchDelegateTest extends BaseTest {
2331 private final MotionEvent downEvent = MotionEvent .obtain (0 , 0 , MotionEvent .ACTION_DOWN , x , y , 0 );
2432 private final MotionEvent upEvent = MotionEvent .obtain (0 , 0 , MotionEvent .ACTION_UP , x , y , 0 );
2533 private ComponentLayout component ;
34+ private ReactView reactView ;
2635
2736 @ Override
2837 public void beforeEach () {
29- ReactView reactView = mock (ReactView .class );
38+ reactView = mock (ReactView .class );
3039 component = mock (ComponentLayout .class );
3140 uut = spy (new OverlayTouchDelegate (component , reactView ));
3241 }
3342
43+ private void mockHierarchyWithDebuggingOverlay () {
44+ // Mock the hierarchy: ReactView -> ReactSurfaceView -> ReactViewGroup(s)
45+ ViewGroup reactSurfaceView = mock (ViewGroup .class );
46+ ViewGroup debuggingOverlayContainer = mock (ViewGroup .class );
47+ ViewGroup contentViewGroup = mock (ViewGroup .class );
48+ DebuggingOverlay debuggingOverlay = mock (DebuggingOverlay .class );
49+
50+ // Set up ReactView -> ReactSurfaceView
51+ when (reactView .getChildAt (0 )).thenReturn (reactSurfaceView );
52+ when (reactView .getChildCount ()).thenReturn (1 );
53+
54+ // Set up ReactSurfaceView -> ReactViewGroup(s)
55+ // First child: ViewGroup with DebuggingOverlay (should be skipped)
56+ when (reactSurfaceView .getChildAt (0 )).thenReturn (debuggingOverlayContainer );
57+ when (reactSurfaceView .getChildAt (1 )).thenReturn (contentViewGroup );
58+ when (reactSurfaceView .getChildCount ()).thenReturn (2 );
59+
60+ // Set up debuggingOverlayContainer: has DebuggingOverlay as first child
61+ when (debuggingOverlayContainer .getChildAt (0 )).thenReturn (debuggingOverlay );
62+
63+ // Set up contentViewGroup: not a DebuggingOverlay, visible, and coordinates
64+ // inside
65+ when (contentViewGroup .getChildAt (0 )).thenReturn (null ); // Not a DebuggingOverlay
66+ when (contentViewGroup .getVisibility ()).thenReturn (View .VISIBLE ); // For isVisible extension
67+
68+ // Set up getHitRect for coordinatesInsideView to work
69+ Rect hitRect = new Rect (0 , 0 , 100 , 100 );
70+ doAnswer ((Answer <Void >) invocation -> {
71+ Rect rect = invocation .getArgument (0 );
72+ rect .set (hitRect );
73+ return null ;
74+ }).when (contentViewGroup ).getHitRect (any (Rect .class ));
75+
76+ // Also mock getHitRect for debuggingOverlayContainer (though it should be
77+ // skipped)
78+ doAnswer ((Answer <Void >) invocation -> {
79+ Rect rect = invocation .getArgument (0 );
80+ rect .set (new Rect (0 , 0 , 100 , 100 ));
81+ return null ;
82+ }).when (debuggingOverlayContainer ).getHitRect (any (Rect .class ));
83+ }
84+
3485 @ Test
3586 public void downEventIsHandled () {
87+ mockHierarchyWithDebuggingOverlay ();
3688 uut .setInterceptTouchOutside (new Bool (true ));
3789 uut .onInterceptTouchEvent (downEvent );
3890 verify (uut , times (1 )).handleDown (downEvent );
0 commit comments