Skip to content

Commit 2b69931

Browse files
committed
Refactor SimpleViewController and SimpleView for improved mock behavior in tests
- Updated SimpleView to extend FrameLayout instead of ReactView, avoiding React surface rendering in tests. - Enhanced method implementations in SimpleView to return appropriate values and added no-op comments for clarity. - Cleaned up formatting in SimpleViewController for better readability. - Removed unnecessary blank lines in TestApplication and added a newline in index.js for consistency.
1 parent 3d9da1b commit 2b69931

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

android/src/androidTest/java/com/reactnativenavigation/TestApplication.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import com.reactnativenavigation.react.NavigationReactNativeHost
99

1010
class TestApplication : NavigationApplication() {
1111

12-
1312
override val reactNativeHost: ReactNativeHost
1413
get() = object : NavigationReactNativeHost(this) {
1514
override fun getJSMainModuleName(): String {

android/src/androidTest/java/com/reactnativenavigation/mocks/SimpleViewController.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
import android.app.Activity;
66
import android.content.Context;
77
import android.view.MotionEvent;
8+
import android.view.ViewGroup;
9+
import android.widget.FrameLayout;
810

911
import androidx.annotation.NonNull;
1012

1113
import com.reactnativenavigation.options.Options;
12-
import com.reactnativenavigation.react.ReactView;
1314
import com.reactnativenavigation.viewcontrollers.child.ChildController;
1415
import com.reactnativenavigation.viewcontrollers.child.ChildControllersRegistry;
1516
import com.reactnativenavigation.viewcontrollers.component.ComponentPresenterBase;
@@ -24,7 +25,8 @@ public SimpleViewController(Activity activity, ChildControllersRegistry childReg
2425
this(activity, childRegistry, id, new Presenter(activity, new Options()), options);
2526
}
2627

27-
public SimpleViewController(Activity activity, ChildControllersRegistry childRegistry, String id, Presenter presenter, Options options) {
28+
public SimpleViewController(Activity activity, ChildControllersRegistry childRegistry, String id,
29+
Presenter presenter, Options options) {
2830
super(activity, childRegistry, id, presenter, options);
2931
}
3032

@@ -40,7 +42,8 @@ public void sendOnNavigationButtonPressed(String buttonId) {
4042

4143
@Override
4244
public void destroy() {
43-
if (!isDestroyed()) performOnParentController(parent -> parent.onChildDestroyed(this));
45+
if (!isDestroyed())
46+
performOnParentController(parent -> parent.onChildDestroyed(this));
4447
super.destroy();
4548
}
4649

@@ -58,18 +61,24 @@ public int getTopInset() {
5861

5962
@Override
6063
public void applyBottomInset() {
61-
if (view != null) presenter.applyBottomInset(view, getBottomInset());
64+
if (view != null)
65+
presenter.applyBottomInset(view, getBottomInset());
6266
}
6367

6468
@Override
6569
public String getCurrentComponentName() {
6670
return null;
6771
}
6872

69-
public static class SimpleView extends ReactView implements ReactComponent {
73+
/**
74+
* A simple mock view that implements ReactComponent without actually using
75+
* React Native.
76+
* This avoids triggering React surface rendering in instrumented tests.
77+
*/
78+
public static class SimpleView extends FrameLayout implements ReactComponent {
7079

7180
public SimpleView(@NonNull Context context) {
72-
super(context, "compId", "compName");
81+
super(context);
7382
}
7483

7584
@Override
@@ -79,22 +88,22 @@ public boolean isRendered() {
7988

8089
@Override
8190
public boolean isReady() {
82-
return false;
91+
return true;
8392
}
8493

8594
@Override
86-
public ReactView asView() {
95+
public ViewGroup asView() {
8796
return this;
8897
}
8998

9099
@Override
91100
public void destroy() {
92-
101+
// No-op for mock
93102
}
94103

95104
@Override
96105
public void sendOnNavigationButtonPressed(String buttonId) {
97-
106+
// No-op for mock
98107
}
99108

100109
@Override
@@ -104,7 +113,7 @@ public ScrollEventListener getScrollEventListener() {
104113

105114
@Override
106115
public void dispatchTouchEventToJs(MotionEvent event) {
107-
116+
// No-op for mock
108117
}
109118
}
110119
}

android/src/androidTest/js/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
// This registers a no-op component to satisfy React Native's initialization
33
import { AppRegistry } from 'react-native';
44
AppRegistry.registerComponent('RNNTest', () => () => null);
5+

0 commit comments

Comments
 (0)