Browse Source

android: device orientation

Daniel Zlotin 8 years ago
parent
commit
3572f8543d

+ 47
- 11
AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/ApplicationLifecycleTest.java View File

@@ -1,9 +1,13 @@
1 1
 package com.reactnativenavigation.e2e.androide2e;
2 2
 
3 3
 import android.support.test.runner.AndroidJUnit4;
4
+import android.support.test.uiautomator.By;
5
+import android.support.test.uiautomator.BySelector;
4 6
 import android.support.test.uiautomator.UiDevice;
7
+import android.support.test.uiautomator.UiObject;
5 8
 import android.support.test.uiautomator.UiScrollable;
6 9
 import android.support.test.uiautomator.UiSelector;
10
+import android.support.test.uiautomator.Until;
7 11
 
8 12
 import org.junit.After;
9 13
 import org.junit.Before;
@@ -18,11 +22,11 @@ import static android.support.test.InstrumentationRegistry.getInstrumentation;
18 22
 import static org.assertj.core.api.Java6Assertions.assertThat;
19 23
 
20 24
 @RunWith(AndroidJUnit4.class)
21
-@FixMethodOrder(value = MethodSorters.NAME_ASCENDING)
25
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
22 26
 public class ApplicationLifecycleTest {
23 27
 
24 28
     private static final String PACKAGE_NAME = "com.reactnativenavigation.playground";
25
-    private static final int TIMEOUT = 2000;
29
+    private static final long TIMEOUT = 3000;
26 30
 
27 31
     @Before
28 32
     public void beforeEach() {
@@ -38,7 +42,6 @@ public class ApplicationLifecycleTest {
38 42
     public void _1_showSplash_AcceptsOverlayPermissions_ShowsWelcomeScreen() throws Exception {
39 43
         launchTheApp();
40 44
 //        assertThat(uiDevice().wait(Until.hasObject(By.desc("NavigationSplashView")), TIMEOUT)).isTrue();
41
-        acceptOverlayPermissionIfNeeded();
42 45
         assertMainShown();
43 46
     }
44 47
 
@@ -49,7 +52,7 @@ public class ApplicationLifecycleTest {
49 52
 
50 53
         uiDevice().pressHome();
51 54
         uiDevice().pressRecentApps();
52
-        uiDevice().findObject(new UiSelector().text("Playground")).click();
55
+        elementByText("Playground").click();
53 56
         assertMainShown();
54 57
     }
55 58
 
@@ -64,14 +67,31 @@ public class ApplicationLifecycleTest {
64 67
         assertMainShown();
65 68
     }
66 69
 
70
+    @Test
71
+    public void _4_deviceOrientationDoesNotDestroyActivity() throws Exception {
72
+        launchTheApp();
73
+        assertMainShown();
74
+
75
+        elementByText("PUSH").click();
76
+        assertExists(By.text("Pushed screen"));
77
+
78
+        uiDevice().setOrientationLeft();
79
+        Thread.sleep(100);
80
+
81
+        assertExists(By.text("Pushed screen"));
82
+    }
83
+
67 84
     private void assertMainShown() {
68
-        assertThat(uiDevice().findObject(new UiSelector().text("React Native Navigation!")).exists()).isTrue();
85
+        assertExists(By.text("React Native Navigation!"));
69 86
     }
70 87
 
71 88
     private void acceptOverlayPermissionIfNeeded() throws Exception {
72
-        if (uiDevice().findObject(new UiSelector().text("Draw over other apps")).exists()) {
73
-            uiDevice().findObject(new UiSelector().text("Playground")).click();
74
-            uiDevice().findObject(new UiSelector().text("Permit drawing over other apps")).click();
89
+        if (elementByText("Draw over other apps").exists()) {
90
+            if (!elementByText("Playground").exists()) {
91
+                scrollToText("Playground");
92
+            }
93
+            elementByText("Playground").click();
94
+            elementByText("Permit drawing over other apps").click();
75 95
             uiDevice().pressBack();
76 96
             uiDevice().pressBack();
77 97
         }
@@ -80,13 +100,29 @@ public class ApplicationLifecycleTest {
80 100
     private void launchTheApp() throws Exception {
81 101
         uiDevice().wakeUp();
82 102
         uiDevice().pressHome();
83
-        uiDevice().findObject(new UiSelector().description("Apps")).clickAndWaitForNewWindow();
84
-        new UiScrollable(new UiSelector().scrollable(true)).scrollTextIntoView("Playground");
85
-        uiDevice().findObject(new UiSelector().text("Playground")).clickAndWaitForNewWindow();
103
+        elementByDesc("Apps").clickAndWaitForNewWindow();
104
+        scrollToText("Playground");
105
+        elementByText("Playground").clickAndWaitForNewWindow();
106
+        acceptOverlayPermissionIfNeeded();
86 107
     }
87 108
 
88 109
     private UiDevice uiDevice() {
89 110
         return UiDevice.getInstance(getInstrumentation());
90 111
     }
91 112
 
113
+    private UiObject elementByText(String text) {
114
+        return uiDevice().findObject(new UiSelector().text(text));
115
+    }
116
+
117
+    private UiObject elementByDesc(String text) {
118
+        return uiDevice().findObject(new UiSelector().description(text));
119
+    }
120
+
121
+    private void scrollToText(String txt) throws Exception {
122
+        new UiScrollable(new UiSelector().scrollable(true)).scrollTextIntoView(txt);
123
+    }
124
+
125
+    private void assertExists(BySelector selector) {
126
+        assertThat(uiDevice().wait(Until.hasObject(selector), TIMEOUT)).isTrue();
127
+    }
92 128
 }

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/NavigationActivity.java View File

@@ -1,5 +1,6 @@
1 1
 package com.reactnativenavigation;
2 2
 
3
+import android.content.res.Configuration;
3 4
 import android.os.Bundle;
4 5
 import android.support.annotation.Nullable;
5 6
 import android.support.v7.app.AppCompatActivity;

+ 0
- 9
playground/android/app/src/androidTest/AndroidManifest.xml View File

@@ -1,9 +0,0 @@
1
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
-    xmlns:tools="http://schemas.android.com/tools"
3
-    package="com.reactnativenavigation.playground">
4
-
5
-    <uses-sdk
6
-        android:minSdkVersion="23"
7
-        tools:overrideLibrary="android.support.test.uiautomator.v18" />
8
-
9
-</manifest>

+ 2
- 0
playground/android/app/src/main/AndroidManifest.xml View File

@@ -11,6 +11,7 @@
11 11
         android:theme="@style/AppTheme">
12 12
         <activity
13 13
             android:name=".MainActivity"
14
+            android:configChanges="orientation|screenSize|keyboard|keyboardHidden"
14 15
             android:label="@string/app_name"
15 16
             android:launchMode="singleTask">
16 17
             <intent-filter>
@@ -18,5 +19,6 @@
18 19
                 <category android:name="android.intent.category.LAUNCHER" />
19 20
             </intent-filter>
20 21
         </activity>
22
+        <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
21 23
     </application>
22 24
 </manifest>