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 .invocation .InvocationOnMock ;
17+ import org .mockito .stubbing .Answer ;
1218
1319import static org .assertj .core .api .Java6Assertions .assertThat ;
20+ import static org .mockito .ArgumentMatchers .any ;
21+ import static org .mockito .Mockito .doAnswer ;
1422import static org .mockito .Mockito .mock ;
1523import static org .mockito .Mockito .spy ;
1624import static org .mockito .Mockito .times ;
1725import static org .mockito .Mockito .verify ;
26+ import static org .mockito .Mockito .when ;
1827
1928public class OverlayTouchDelegateTest extends BaseTest {
2029 private OverlayTouchDelegate uut ;
@@ -23,14 +32,59 @@ public class OverlayTouchDelegateTest extends BaseTest {
2332 private final MotionEvent downEvent = MotionEvent .obtain (0 , 0 , MotionEvent .ACTION_DOWN , x , y , 0 );
2433 private final MotionEvent upEvent = MotionEvent .obtain (0 , 0 , MotionEvent .ACTION_UP , x , y , 0 );
2534 private ComponentLayout component ;
35+ private ReactView reactView ;
2636
2737 @ Override
2838 public void beforeEach () {
29- ReactView reactView = mock (ReactView .class );
30- component = mock (ComponentLayout .class );
39+ mockHierarchy ();
3140 uut = spy (new OverlayTouchDelegate (component , reactView ));
3241 }
3342
43+ private void mockHierarchy () {
44+ reactView = mock (ReactView .class );
45+ // Mock the hierarchy: ReactView -> ReactSurfaceView -> ReactViewGroup(s)
46+ ViewGroup reactSurfaceView = mock (ViewGroup .class );
47+ ViewGroup debuggingOverlayContainer = mock (ViewGroup .class );
48+ ViewGroup contentViewGroup = mock (ViewGroup .class );
49+ DebuggingOverlay debuggingOverlay = mock (DebuggingOverlay .class );
50+
51+ // Set up ReactView -> ReactSurfaceView
52+ when (reactView .getChildAt (0 )).thenReturn (reactSurfaceView );
53+ when (reactView .getChildCount ()).thenReturn (1 );
54+
55+ // Set up ReactSurfaceView -> ReactViewGroup(s)
56+ // First child: ViewGroup with DebuggingOverlay (should be skipped)
57+ when (reactSurfaceView .getChildAt (0 )).thenReturn (debuggingOverlayContainer );
58+ when (reactSurfaceView .getChildAt (1 )).thenReturn (contentViewGroup );
59+ when (reactSurfaceView .getChildCount ()).thenReturn (2 );
60+
61+ // Set up debuggingOverlayContainer: has DebuggingOverlay as first child
62+ when (debuggingOverlayContainer .getChildAt (0 )).thenReturn (debuggingOverlay );
63+
64+ // Set up contentViewGroup: not a DebuggingOverlay, visible, and coordinates
65+ // inside
66+ when (contentViewGroup .getChildAt (0 )).thenReturn (null ); // Not a DebuggingOverlay
67+ when (contentViewGroup .getVisibility ()).thenReturn (View .VISIBLE ); // For isVisible extension
68+
69+ // Set up getHitRect for coordinatesInsideView to work
70+ Rect hitRect = new Rect (0 , 0 , 100 , 100 );
71+ doAnswer ((Answer <Void >) invocation -> {
72+ Rect rect = invocation .getArgument (0 );
73+ rect .set (hitRect );
74+ return null ;
75+ }).when (contentViewGroup ).getHitRect (any (Rect .class ));
76+
77+ // Also mock getHitRect for debuggingOverlayContainer (though it should be
78+ // skipped)
79+ doAnswer ((Answer <Void >) invocation -> {
80+ Rect rect = invocation .getArgument (0 );
81+ rect .set (new Rect (0 , 0 , 100 , 100 ));
82+ return null ;
83+ }).when (debuggingOverlayContainer ).getHitRect (any (Rect .class ));
84+
85+ component = mock (ComponentLayout .class );
86+ }
87+
3488 @ Test
3589 public void downEventIsHandled () {
3690 uut .setInterceptTouchOutside (new Bool (true ));
0 commit comments