Browse Source

some more tests android

Daniel Zlotin 7 years ago
parent
commit
ebb132ff09

+ 3
- 0
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ContainerViewController.java View File

@@ -77,6 +77,9 @@ public class ContainerViewController extends ViewController {
77 77
 
78 78
 	public void applyNavigationOptions(final NavigationOptions options) {
79 79
 		navigationOptions.mergeWith(options);
80
+		if (getParentStackController() != null) {
81
+			getParentStackController().setTitle(navigationOptions.title);
82
+		}
80 83
 	}
81 84
 
82 85
 	public NavigationOptions getNavigationOptions() {

+ 5
- 0
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/StackController.java View File

@@ -137,6 +137,11 @@ public class StackController extends ParentController {
137 137
 	}
138 138
 
139 139
 	public TopBar getTopBar() {
140
+		ensureViewIsCreated();
140 141
 		return topBar;
141 142
 	}
143
+
144
+	private void ensureViewIsCreated() {
145
+		getView();
146
+	}
142 147
 }

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/views/TopBar.java View File

@@ -18,6 +18,6 @@ public class TopBar extends AppBarLayout {
18 18
 	}
19 19
 
20 20
 	public String getTitle() {
21
-		return titleBar.getTitle().toString();
21
+		return titleBar.getTitle() != null ? titleBar.getTitle().toString() : "";
22 22
 	}
23 23
 }

+ 12
- 0
lib/android/app/src/test/java/com/reactnativenavigation/mocks/SimpleContainerViewController.java View File

@@ -0,0 +1,12 @@
1
+package com.reactnativenavigation.mocks;
2
+
3
+import android.app.Activity;
4
+
5
+import com.reactnativenavigation.parse.NavigationOptions;
6
+import com.reactnativenavigation.viewcontrollers.ContainerViewController;
7
+
8
+public class SimpleContainerViewController extends ContainerViewController {
9
+	public SimpleContainerViewController(final Activity activity, final String id) {
10
+		super(activity, id, "theContainerName", new TestContainerViewCreator(), new NavigationOptions());
11
+	}
12
+}

+ 18
- 4
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/NavigatorTest.java View File

@@ -4,8 +4,8 @@ import android.app.Activity;
4 4
 import android.support.annotation.NonNull;
5 5
 
6 6
 import com.reactnativenavigation.BaseTest;
7
+import com.reactnativenavigation.mocks.SimpleContainerViewController;
7 8
 import com.reactnativenavigation.mocks.SimpleViewController;
8
-import com.reactnativenavigation.mocks.TestContainerViewCreator;
9 9
 import com.reactnativenavigation.mocks.TestStackAnimator;
10 10
 import com.reactnativenavigation.parse.NavigationOptions;
11 11
 import com.reactnativenavigation.utils.CompatUtils;
@@ -191,7 +191,7 @@ public class NavigatorTest extends BaseTest {
191 191
 
192 192
 	@Test
193 193
 	public void setOptions_CallsApplyNavigationOptions() {
194
-		ContainerViewController containerVc = new ContainerViewController(activity, "theId", "theName", new TestContainerViewCreator(), new NavigationOptions());
194
+		ContainerViewController containerVc = new SimpleContainerViewController(activity, "theId");
195 195
 		uut.setRoot(containerVc);
196 196
 		assertThat(containerVc.getNavigationOptions().title).isEmpty();
197 197
 
@@ -204,8 +204,22 @@ public class NavigatorTest extends BaseTest {
204 204
 
205 205
 	@Test
206 206
 	public void setOptions_AffectsOnlyContainerViewControllers() {
207
-		uut.setRoot(child1);
208
-		uut.setOptions(child1.getId(), new NavigationOptions());
207
+		uut.setOptions("some unknown child id", new NavigationOptions());
208
+	}
209
+
210
+	@Test
211
+	public void setOptions_ActuallyAffectsTheTitleView() throws Exception {
212
+		ContainerViewController containerVc = new SimpleContainerViewController(activity, "theId");
213
+		StackController stackController = new StackController(activity, "stackId", new TestStackAnimator());
214
+		stackController.push(containerVc);
215
+		uut.setRoot(stackController);
216
+		assertThat(stackController.getTopBar().getTitle()).isEmpty();
217
+
218
+		NavigationOptions opts = new NavigationOptions();
219
+		opts.title = "the new title";
220
+		uut.setOptions("theId", opts);
221
+
222
+		assertThat(stackController.getTopBar().getTitle()).isEqualTo("the new title");
209 223
 	}
210 224
 
211 225
 	@NonNull

+ 18
- 0
lib/android/app/src/test/java/com/reactnativenavigation/views/TopBarTest.java View File

@@ -0,0 +1,18 @@
1
+package com.reactnativenavigation.views;
2
+
3
+import com.reactnativenavigation.BaseTest;
4
+
5
+import org.junit.Test;
6
+
7
+import static org.assertj.core.api.Java6Assertions.assertThat;
8
+
9
+public class TopBarTest extends BaseTest {
10
+	@Test
11
+	public void title() throws Exception {
12
+		TopBar topBar = new TopBar(newActivity());
13
+		assertThat(topBar.getTitle()).isEmpty();
14
+
15
+		topBar.setTitle("new title");
16
+		assertThat(topBar.getTitle()).isEqualTo("new title");
17
+	}
18
+}