|
@@ -0,0 +1,83 @@
|
|
1
|
+package com.reactnativenavigation.playground;
|
|
2
|
+
|
|
3
|
+import android.support.test.espresso.Espresso;
|
|
4
|
+import android.support.test.espresso.IdlingResource;
|
|
5
|
+import android.support.test.rule.ActivityTestRule;
|
|
6
|
+import android.support.test.runner.AndroidJUnit4;
|
|
7
|
+import android.support.test.uiautomator.UiDevice;
|
|
8
|
+import android.support.test.uiautomator.UiObjectNotFoundException;
|
|
9
|
+import android.support.test.uiautomator.UiSelector;
|
|
10
|
+
|
|
11
|
+import com.facebook.react.ReactNativeHost;
|
|
12
|
+import com.reactnativenavigation.controllers.NavigationActivity;
|
|
13
|
+
|
|
14
|
+import org.junit.FixMethodOrder;
|
|
15
|
+import org.junit.Rule;
|
|
16
|
+import org.junit.Test;
|
|
17
|
+import org.junit.runner.RunWith;
|
|
18
|
+import org.junit.runners.MethodSorters;
|
|
19
|
+
|
|
20
|
+import java.io.IOException;
|
|
21
|
+
|
|
22
|
+import static android.support.test.InstrumentationRegistry.getInstrumentation;
|
|
23
|
+import static android.support.test.espresso.Espresso.onView;
|
|
24
|
+import static android.support.test.espresso.assertion.ViewAssertions.matches;
|
|
25
|
+import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
|
|
26
|
+import static android.support.test.espresso.matcher.ViewMatchers.withText;
|
|
27
|
+
|
|
28
|
+@RunWith(AndroidJUnit4.class)
|
|
29
|
+@FixMethodOrder(value = MethodSorters.NAME_ASCENDING)
|
|
30
|
+public class ApplicationLifecycleTest {
|
|
31
|
+
|
|
32
|
+ @Rule
|
|
33
|
+ public ActivityTestRule<MainActivity> rule = new ActivityTestRule<>(MainActivity.class, false, false);
|
|
34
|
+
|
|
35
|
+ private void registerIdlingResource() {
|
|
36
|
+ Espresso.registerIdlingResources(new IdlingResource() {
|
|
37
|
+ @Override
|
|
38
|
+ public String getName() {
|
|
39
|
+ return "React Bridge";
|
|
40
|
+ }
|
|
41
|
+
|
|
42
|
+ @Override
|
|
43
|
+ public boolean isIdleNow() {
|
|
44
|
+ ReactNativeHost host = NavigationActivity.instance.getHost();
|
|
45
|
+ return host != null
|
|
46
|
+ && host.hasInstance()
|
|
47
|
+ && host.getReactInstanceManager().hasStartedCreatingInitialContext()
|
|
48
|
+ && host.getReactInstanceManager().getCurrentReactContext() != null;
|
|
49
|
+ }
|
|
50
|
+
|
|
51
|
+ @Override
|
|
52
|
+ public void registerIdleTransitionCallback(final ResourceCallback callback) {
|
|
53
|
+ new Thread(new Runnable() {
|
|
54
|
+ @Override
|
|
55
|
+ public void run() {
|
|
56
|
+ while (!isIdleNow()) {
|
|
57
|
+ try {
|
|
58
|
+ Thread.sleep(1000);
|
|
59
|
+ } catch (InterruptedException e) {
|
|
60
|
+ e.printStackTrace();
|
|
61
|
+ }
|
|
62
|
+ }
|
|
63
|
+ callback.onTransitionToIdle();
|
|
64
|
+ }
|
|
65
|
+ }).start();
|
|
66
|
+ }
|
|
67
|
+ });
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
+ @Test
|
|
71
|
+ public void startApp_LoadsBridge_ThenShowsWelcomeScreen() throws UiObjectNotFoundException, IOException {
|
|
72
|
+ rule.launchActivity(null);
|
|
73
|
+
|
|
74
|
+ UiDevice.getInstance(getInstrumentation()).findObject(new UiSelector().text("Playground")).click();
|
|
75
|
+ UiDevice.getInstance(getInstrumentation()).findObject(new UiSelector().text("Permit drawing over other apps")).click();
|
|
76
|
+ UiDevice.getInstance(getInstrumentation()).pressBack();
|
|
77
|
+ UiDevice.getInstance(getInstrumentation()).pressBack();
|
|
78
|
+
|
|
79
|
+ registerIdlingResource();
|
|
80
|
+
|
|
81
|
+ onView(withText("React Native Navigation!")).check(matches(isDisplayed()));
|
|
82
|
+ }
|
|
83
|
+}
|