Browse Source

added another testcase

Daniel Zlotin 7 years ago
parent
commit
7b7b7a2d1b

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

@@ -24,123 +24,123 @@ import static org.assertj.core.api.Java6Assertions.assertThat;
24 24
 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
25 25
 public class ApplicationLifecycleTest {
26 26
 
27
-    private static final String PACKAGE_NAME = "com.reactnativenavigation.playground";
28
-    private static final long TIMEOUT = 3000;
29
-
30
-    @Before
31
-    public void beforeEach() throws Exception {
32
-        uiDevice().wakeUp();
33
-        uiDevice().setOrientationNatural();
34
-    }
35
-
36
-    @After
37
-    public void afterEach() throws Exception {
38
-        uiDevice().executeShellCommand("am force-stop " + PACKAGE_NAME);
39
-    }
40
-
41
-    @Test
42
-    public void _1_acceptsOverlayPermissions_ShowsWelcomeScreen() throws Exception {
43
-        launchTheApp();
44
-        assertMainShown();
45
-    }
46
-
47
-    @Test
48
-    public void _2_relaunchFromBackground() throws Exception {
49
-        launchTheApp();
50
-        assertMainShown();
51
-        push();
52
-        assertPushedScreenShown();
53
-
54
-        uiDevice().pressHome();
55
-        uiDevice().pressRecentApps();
56
-        elementByText("Playground").click();
57
-
58
-        assertPushedScreenShown();
59
-    }
60
-
61
-    @Test
62
-    public void _3_relaunchAfterClose() throws Exception {
63
-        launchTheApp();
64
-        push();
65
-        assertPushedScreenShown();
66
-
67
-        uiDevice().pressBack();
68
-
69
-        launchTheApp();
70
-        assertMainShown();
71
-    }
72
-
73
-    @Test
74
-    public void _4_deviceOrientationDoesNotDestroyActivity() throws Exception {
75
-        launchTheApp();
76
-        push();
77
-        assertPushedScreenShown();
78
-
79
-        uiDevice().setOrientationLeft();
80
-        Thread.sleep(100);
81
-
82
-        assertPushedScreenShown();
83
-    }
84
-
85
-    @Test
86
-    public void _5_relaunchAfterActivityKilledBySystem() throws Exception {
87
-        launchTheApp();
88
-        push();
89
-        assertPushedScreenShown();
90
-
91
-        uiDevice().pressHome();
92
-        uiDevice().waitForIdle();
93
-        uiDevice().executeShellCommand("am kill " + PACKAGE_NAME);
94
-
95
-        uiDevice().pressRecentApps();
96
-        elementByText("Playground").click();
97
-        assertMainShown();
98
-    }
99
-
100
-    private void push() throws UiObjectNotFoundException {
101
-        elementByText("PUSH").click();
102
-    }
103
-
104
-    private void assertMainShown() {
105
-        assertExists(By.text("React Native Navigation!"));
106
-    }
107
-
108
-    private void launchTheApp() throws Exception {
109
-        uiDevice().executeShellCommand("am start -n " + PACKAGE_NAME + "/.MainActivity");
110
-        uiDevice().waitForIdle();
111
-        acceptOverlayPermissionIfNeeded();
112
-        uiDevice().wait(Until.gone(By.textContains("Please wait")), 1000 * 60 * 3);
113
-    }
114
-
115
-    private void acceptOverlayPermissionIfNeeded() throws Exception {
116
-        if (elementByText("Draw over other apps").exists()) {
117
-            if (!elementByText("Playground").exists()) {
118
-                scrollToText("Playground");
119
-            }
120
-            elementByText("Playground").click();
121
-            elementByText("Permit drawing over other apps").click();
122
-            uiDevice().pressBack();
123
-            uiDevice().pressBack();
124
-        }
125
-    }
126
-
127
-    private UiDevice uiDevice() {
128
-        return UiDevice.getInstance(getInstrumentation());
129
-    }
130
-
131
-    private UiObject elementByText(String text) {
132
-        return uiDevice().findObject(new UiSelector().text(text));
133
-    }
134
-
135
-    private void scrollToText(String txt) throws Exception {
136
-        new UiScrollable(new UiSelector().scrollable(true)).scrollTextIntoView(txt);
137
-    }
138
-
139
-    private void assertExists(BySelector selector) {
140
-        assertThat(uiDevice().wait(Until.hasObject(selector), TIMEOUT)).isTrue();
141
-    }
142
-
143
-    private void assertPushedScreenShown() {
144
-        assertExists(By.text("Pushed Screen"));
145
-    }
27
+	private static final String PACKAGE_NAME = "com.reactnativenavigation.playground";
28
+	private static final long TIMEOUT = 3000;
29
+
30
+	@Before
31
+	public void beforeEach() throws Exception {
32
+		uiDevice().wakeUp();
33
+		uiDevice().setOrientationNatural();
34
+	}
35
+
36
+	@After
37
+	public void afterEach() throws Exception {
38
+		uiDevice().executeShellCommand("am force-stop " + PACKAGE_NAME);
39
+	}
40
+
41
+	@Test
42
+	public void _1_acceptsOverlayPermissions_ShowsWelcomeScreen() throws Exception {
43
+		launchTheApp();
44
+		assertMainShown();
45
+	}
46
+
47
+	@Test
48
+	public void _2_relaunchFromBackground() throws Exception {
49
+		launchTheApp();
50
+		assertMainShown();
51
+		push();
52
+		assertPushedScreenShown();
53
+
54
+		uiDevice().pressHome();
55
+		uiDevice().pressRecentApps();
56
+		elementByText("Playground").click();
57
+
58
+		assertPushedScreenShown();
59
+	}
60
+
61
+	@Test
62
+	public void _3_relaunchAfterClose() throws Exception {
63
+		launchTheApp();
64
+		push();
65
+		assertPushedScreenShown();
66
+
67
+		uiDevice().pressBack();
68
+
69
+		launchTheApp();
70
+		assertMainShown();
71
+	}
72
+
73
+	@Test
74
+	public void _4_deviceOrientationDoesNotDestroyActivity() throws Exception {
75
+		launchTheApp();
76
+		push();
77
+		assertPushedScreenShown();
78
+
79
+		uiDevice().setOrientationLeft();
80
+		Thread.sleep(100);
81
+
82
+		assertPushedScreenShown();
83
+	}
84
+
85
+	@Test
86
+	public void _5_relaunchAfterActivityKilledBySystem() throws Exception {
87
+		launchTheApp();
88
+		push();
89
+		assertPushedScreenShown();
90
+
91
+		uiDevice().pressHome();
92
+		uiDevice().waitForIdle();
93
+		uiDevice().executeShellCommand("am kill " + PACKAGE_NAME);
94
+
95
+		uiDevice().pressRecentApps();
96
+		elementByText("Playground").click();
97
+		assertMainShown();
98
+	}
99
+
100
+	private void push() throws UiObjectNotFoundException {
101
+		elementByText("PUSH").click();
102
+	}
103
+
104
+	private void assertMainShown() {
105
+		assertExists(By.text("React Native Navigation!"));
106
+	}
107
+
108
+	private void launchTheApp() throws Exception {
109
+		uiDevice().executeShellCommand("am start -n " + PACKAGE_NAME + "/.MainActivity");
110
+		uiDevice().waitForIdle();
111
+		acceptOverlayPermissionIfNeeded();
112
+		uiDevice().wait(Until.gone(By.textContains("Please wait")), 1000 * 60 * 3);
113
+	}
114
+
115
+	private void acceptOverlayPermissionIfNeeded() throws Exception {
116
+		if (elementByText("Draw over other apps").exists()) {
117
+			if (!elementByText("Playground").exists()) {
118
+				scrollToText("Playground");
119
+			}
120
+			elementByText("Playground").click();
121
+			elementByText("Permit drawing over other apps").click();
122
+			uiDevice().pressBack();
123
+			uiDevice().pressBack();
124
+		}
125
+	}
126
+
127
+	private UiDevice uiDevice() {
128
+		return UiDevice.getInstance(getInstrumentation());
129
+	}
130
+
131
+	private UiObject elementByText(String text) {
132
+		return uiDevice().findObject(new UiSelector().text(text));
133
+	}
134
+
135
+	private void scrollToText(String txt) throws Exception {
136
+		new UiScrollable(new UiSelector().scrollable(true)).scrollTextIntoView(txt);
137
+	}
138
+
139
+	private void assertExists(BySelector selector) {
140
+		assertThat(uiDevice().wait(Until.hasObject(selector), TIMEOUT)).isTrue();
141
+	}
142
+
143
+	private void assertPushedScreenShown() {
144
+		assertExists(By.text("Pushed Screen"));
145
+	}
146 146
 }

+ 4
- 4
AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/EnvironmentTest.java View File

@@ -10,8 +10,8 @@ import static org.assertj.core.api.Java6Assertions.assertThat;
10 10
 
11 11
 @RunWith(AndroidJUnit4.class)
12 12
 public class EnvironmentTest {
13
-    @Test
14
-    public void instrumentationAndAssertJ() throws Exception {
15
-        assertThat(getInstrumentation().getTargetContext().getPackageName()).isEqualTo("com.reactnativenavigation.e2e.androide2e");
16
-    }
13
+	@Test
14
+	public void instrumentationAndAssertJ() throws Exception {
15
+		assertThat(getInstrumentation().getTargetContext().getPackageName()).isEqualTo("com.reactnativenavigation.e2e.androide2e");
16
+	}
17 17
 }

+ 15
- 0
playground/e2e/app.test.js View File

@@ -56,6 +56,21 @@ describe('app', () => {
56 56
     expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
57 57
     elementByLabel('Show Modal').tap();
58 58
     expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
59
+    elementByLabel('Dismiss Modal').tap();
60
+    expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
61
+    elementByLabel('Dismiss Modal').tap();
62
+    expect(elementByLabel('React Native Navigation!')).toBeVisible();
63
+  });
64
+
65
+  xit('dismiss modal by id', () => {
66
+    elementByLabel('Show Modal').tap();
67
+    expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
68
+    elementByLabel('Show Modal').tap();
69
+    expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
70
+    elementByLabel('Dismiss Previous Modal').tap();
71
+    expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
72
+    elementByLabel('Dismiss Modal').tap();
73
+    expect(elementByLabel('React Native Navigation!')).toBeVisible();
59 74
   });
60 75
 });
61 76
 

+ 8
- 1
playground/src/containers/ModalScreen.js View File

@@ -13,6 +13,7 @@ class ModalScreen extends Component {
13 13
     super(props);
14 14
     this.onClickShowModal = this.onClickShowModal.bind(this);
15 15
     this.onClickDismissModal = this.onClickDismissModal.bind(this);
16
+    this.onClickDismissPreviousModal = this.onClickDismissPreviousModal.bind(this);
16 17
   }
17 18
   render() {
18 19
     return (
@@ -21,6 +22,7 @@ class ModalScreen extends Component {
21 22
         <Text style={styles.footer}>{`Modal Stack Position: ${this.getModalPosition()}`}</Text>
22 23
         <Button title="Show Modal" onPress={this.onClickShowModal} />
23 24
         <Button title="Dismiss Modal" onPress={this.onClickDismissModal} />
25
+        {this.props.previousModalId ? (<Button title="Dismiss Previous Modal" onPress={this.onClickDismissPreviousModal} />) : undefined}
24 26
         <Text style={styles.footer}>{`this.props.id = ${this.props.id}`}</Text>
25 27
       </View>
26 28
     );
@@ -30,7 +32,8 @@ class ModalScreen extends Component {
30 32
     Navigation.showModal({
31 33
       name: 'navigation.playground.ModalScreen',
32 34
       passProps: {
33
-        modalPosition: this.getModalPosition() + 1
35
+        modalPosition: this.getModalPosition() + 1,
36
+        previousModalId: this.props.id
34 37
       }
35 38
     });
36 39
   }
@@ -39,6 +42,10 @@ class ModalScreen extends Component {
39 42
     Navigation.dismissModal(this.props.id);
40 43
   }
41 44
 
45
+  onClickDismissPreviousModal() {
46
+    Navigation.dismissModal(this.props.previousModalId);
47
+  }
48
+
42 49
   getModalPosition() {
43 50
     return (this.props.modalPosition || 1);
44 51
   }