Skip to content

Commit 3c42afb

Browse files
authored
unit tests updated (#8274)
* unit tests updated * cursor github rule
1 parent d23146f commit 3c42afb

37 files changed

+100
-42
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
description: When the user asks for a GitHub description or PR description
3+
globs:
4+
alwaysApply: false
5+
---
6+
7+
When generating GitHub descriptions (PR descriptions, issue descriptions, commit descriptions), always use GitHub-flavored Markdown formatting: **bold** for emphasis, `backticks` for code/class/file references, bullet lists with `-`, and `##` headers where appropriate.

android/src/test/java/com/reactnativenavigation/BaseRobolectricTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import org.robolectric.annotation.Config
1515

1616

1717
@RunWith(RobolectricTestRunner::class)
18-
@Config(application = TestApplication::class)
18+
@Config(application = TestApplication::class, shadows = [ShadowSoLoader::class, ShadowReactView::class])
1919
abstract class BaseRobolectricTest {
2020

2121
val context: Context = RuntimeEnvironment.getApplication()

android/src/test/java/com/reactnativenavigation/BaseTest.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import com.reactnativenavigation.utils.SystemUiUtils
1919
import com.reactnativenavigation.utils.SystemUiUtils.getStatusBarHeight
2020
import com.reactnativenavigation.utils.SystemUiUtils.getStatusBarHeightDp
2121
import com.reactnativenavigation.utils.ViewUtils
22+
import com.reactnativenavigation.viewcontrollers.statusbar.StatusBarPresenter
2223
import com.reactnativenavigation.viewcontrollers.viewcontroller.ViewController
2324
import org.assertj.core.api.Java6Assertions
2425
import org.junit.After
@@ -37,7 +38,7 @@ import org.robolectric.shadows.ShadowLooper
3738
import java.util.Arrays
3839

3940
@RunWith(RobolectricTestRunner::class)
40-
@Config(sdk = [28], application = TestApplication::class)
41+
@Config(sdk = [28], application = TestApplication::class, shadows = [ShadowSoLoader::class, ShadowReactView::class])
4142
abstract class BaseTest {
4243
private val handler = Handler(Looper.getMainLooper())
4344
private val shadowMainLooper: ShadowLooper = Shadows.shadowOf(Looper.getMainLooper())
@@ -49,7 +50,6 @@ abstract class BaseTest {
4950
@Before
5051
open fun beforeEach() {
5152
mockReactNativeFeatureFlags = mockStatic(ReactNativeFeatureFlags::class.java)
52-
mockReactNativeFeatureFlags?.close()
5353

5454
NavigationApplication.instance = Mockito.mock(NavigationApplication::class.java)
5555
mockConfiguration = Mockito.mock(Configuration::class.java)
@@ -62,6 +62,7 @@ abstract class BaseTest {
6262
.thenReturn(0x00000)
6363

6464
RNNFeatureToggles.init()
65+
StatusBarPresenter.init(newActivity())
6566
}
6667

6768

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.reactnativenavigation;
2+
3+
import android.content.Context;
4+
import android.widget.FrameLayout;
5+
6+
import com.reactnativenavigation.react.ReactView;
7+
8+
import org.robolectric.annotation.Implementation;
9+
import org.robolectric.annotation.Implements;
10+
import org.robolectric.annotation.RealObject;
11+
import org.robolectric.shadow.api.Shadow;
12+
import org.robolectric.util.ReflectionHelpers;
13+
import org.robolectric.util.ReflectionHelpers.ClassParameter;
14+
15+
@Implements(ReactView.class)
16+
public class ShadowReactView extends org.robolectric.shadows.ShadowViewGroup {
17+
18+
@RealObject
19+
private ReactView realObject;
20+
21+
@Implementation
22+
protected void __constructor__(Context context, String componentId, String componentName) {
23+
Shadow.invokeConstructor(FrameLayout.class, realObject,
24+
ClassParameter.from(Context.class, context));
25+
ReflectionHelpers.setField(realObject, "componentId", componentId);
26+
ReflectionHelpers.setField(realObject, "componentName", componentName);
27+
}
28+
29+
@Implementation
30+
protected void onAttachedToWindow() {
31+
}
32+
33+
@Implementation
34+
public void start() {
35+
}
36+
37+
@Implementation
38+
public void destroy() {
39+
}
40+
41+
@Implementation
42+
public boolean isRendered() {
43+
return realObject.getChildCount() >= 1;
44+
}
45+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.reactnativenavigation;
2+
3+
import com.facebook.soloader.SoLoader;
4+
5+
import org.robolectric.annotation.Implementation;
6+
import org.robolectric.annotation.Implements;
7+
8+
@Implements(SoLoader.class)
9+
public class ShadowSoLoader {
10+
11+
@Implementation
12+
public static boolean loadLibrary(String shortName) {
13+
return true;
14+
}
15+
16+
@Implementation
17+
public static boolean loadLibrary(String shortName, int flags) {
18+
return true;
19+
}
20+
21+
@Implementation
22+
public static void loadLibraryOnNonAndroid(String shortName) {
23+
}
24+
25+
@Implementation
26+
public static void init(android.content.Context context, int flags) {
27+
}
28+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import com.facebook.react.ReactApplication
66
import com.facebook.react.ReactHost
77
import com.facebook.react.ReactNativeHost
88
import com.facebook.react.ReactPackage
9-
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
9+
import org.mockito.Mockito
1010

1111
class TestApplication : Application(), ReactApplication {
1212
override val reactNativeHost: ReactNativeHost = object : ReactNativeHost(this) {
@@ -25,5 +25,5 @@ class TestApplication : Application(), ReactApplication {
2525
}
2626

2727
override val reactHost: ReactHost
28-
get() = getDefaultReactHost(this, reactNativeHost)
28+
get() = Mockito.mock(ReactHost::class.java)
2929
}

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,17 @@
88

99
import androidx.annotation.NonNull;
1010

11-
import com.facebook.react.ReactInstanceManager;
11+
import android.view.ViewGroup;
12+
import android.widget.FrameLayout;
13+
1214
import com.reactnativenavigation.options.Options;
13-
import com.reactnativenavigation.react.ReactView;
1415
import com.reactnativenavigation.viewcontrollers.child.ChildController;
1516
import com.reactnativenavigation.viewcontrollers.child.ChildControllersRegistry;
1617
import com.reactnativenavigation.viewcontrollers.component.ComponentPresenterBase;
1718
import com.reactnativenavigation.viewcontrollers.viewcontroller.Presenter;
1819
import com.reactnativenavigation.viewcontrollers.viewcontroller.ScrollEventListener;
1920
import com.reactnativenavigation.views.component.ReactComponent;
2021

21-
import org.mockito.Mockito;
22-
2322
public class SimpleViewController extends ChildController<SimpleViewController.SimpleView> {
2423
private final ComponentPresenterBase presenter = new ComponentPresenterBase();
2524

@@ -69,10 +68,10 @@ public String getCurrentComponentName() {
6968
return null;
7069
}
7170

72-
public static class SimpleView extends ReactView implements ReactComponent {
71+
public static class SimpleView extends FrameLayout implements ReactComponent {
7372

7473
public SimpleView(@NonNull Context context) {
75-
super(context, "compId", "compName");
74+
super(context);
7675
}
7776

7877
@Override
@@ -86,13 +85,21 @@ public boolean isReady() {
8685
}
8786

8887
@Override
89-
public ReactView asView() {
88+
public ViewGroup asView() {
9089
return this;
9190
}
9291

9392
@Override
9493
public void destroy() {}
9594

95+
@Override
96+
protected void onAttachedToWindow() {
97+
super.onAttachedToWindow();
98+
start();
99+
}
100+
101+
public void start() {}
102+
96103
@Override
97104
public void sendOnNavigationButtonPressed(String buttonId) {}
98105

android/src/test/java/com/reactnativenavigation/presentation/PresenterTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.junit.Test;
2626
import org.mockito.Mockito;
2727

28-
@Ignore("New architecture - failed to fix")
2928
public class PresenterTest extends BaseTest {
3029
private Presenter uut;
3130
private Activity activity;

android/src/test/java/com/reactnativenavigation/utils/ButtonPresenterTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import static org.mockito.Mockito.spy;
4141
import static org.mockito.Mockito.verify;
4242

43-
@Ignore("New architecture - WIP")
4443
@LooperMode(LooperMode.Mode.PAUSED)
4544
public class ButtonPresenterTest extends BaseTest {
4645
private static final String BTN_TEXT = "button1";

android/src/test/java/com/reactnativenavigation/utils/LayoutFactoryTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import static org.mockito.Mockito.mock;
2121
import static org.mockito.Mockito.when;
2222

23-
@Ignore("New architecture - WIP")
2423
public class LayoutFactoryTest extends BaseTest {
2524
private LayoutFactory uut;
2625
private ReactHost reactHost;

0 commit comments

Comments
 (0)