Ver código fonte

some more tests for ContainerViewController

Daniel Zlotin 7 anos atrás
pai
commit
2277a8f53f

+ 4
- 0
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ContainerViewController.java Ver arquivo

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

+ 0
- 4
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/StackController.java Ver arquivo

@@ -140,8 +140,4 @@ public class StackController extends ParentController {
140 140
 		ensureViewIsCreated();
141 141
 		return topBar;
142 142
 	}
143
-
144
-	private void ensureViewIsCreated() {
145
-		getView();
146
-	}
147 143
 }

+ 4
- 0
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ViewController.java Ver arquivo

@@ -27,6 +27,10 @@ public abstract class ViewController implements ViewTreeObserver.OnGlobalLayoutL
27 27
 	@NonNull
28 28
 	protected abstract View createView();
29 29
 
30
+	public void ensureViewIsCreated() {
31
+		getView();
32
+	}
33
+
30 34
 	public boolean handleBack() {
31 35
 		return false;
32 36
 	}

+ 53
- 0
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ContainerViewControllerTest.java Ver arquivo

@@ -0,0 +1,53 @@
1
+package com.reactnativenavigation.viewcontrollers;
2
+
3
+import android.app.Activity;
4
+
5
+import com.reactnativenavigation.BaseTest;
6
+import com.reactnativenavigation.mocks.TestContainerView;
7
+import com.reactnativenavigation.parse.NavigationOptions;
8
+
9
+import org.junit.Test;
10
+
11
+import static org.assertj.core.api.Java6Assertions.assertThat;
12
+import static org.mockito.Mockito.spy;
13
+import static org.mockito.Mockito.times;
14
+import static org.mockito.Mockito.verify;
15
+
16
+public class ContainerViewControllerTest extends BaseTest {
17
+	private ContainerViewController uut;
18
+	private Activity activity;
19
+
20
+	@Override
21
+	public void beforeEach() {
22
+		super.beforeEach();
23
+		activity = newActivity();
24
+	}
25
+
26
+	@Test
27
+	public void createsViewFromContainerViewCreator() throws Exception {
28
+		final ContainerViewController.ContainerView view = new TestContainerView(activity);
29
+		uut = new ContainerViewController(newActivity(), "id1", "containerName", new ContainerViewController.ContainerViewCreator() {
30
+			@Override
31
+			public ContainerViewController.ContainerView create(final Activity activity1, final String containerId, final String containerName) {
32
+				return view;
33
+			}
34
+		}, new NavigationOptions());
35
+		assertThat(uut.getView()).isSameAs(view);
36
+	}
37
+
38
+	@Test
39
+	public void containerViewDestroyedOnDestory() throws Exception {
40
+		final ContainerViewController.ContainerView view = spy(new TestContainerView(activity));
41
+		uut = new ContainerViewController(newActivity(), "id1", "containerName", new ContainerViewController.ContainerViewCreator() {
42
+			@Override
43
+			public ContainerViewController.ContainerView create(final Activity activity1, final String containerId, final String containerName) {
44
+				return view;
45
+			}
46
+		}, new NavigationOptions());
47
+		uut.ensureViewIsCreated();
48
+
49
+		verify(view, times(0)).destroy();
50
+		uut.destroy();
51
+		verify(view, times(1)).destroy();
52
+	}
53
+}

+ 8
- 0
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ViewControllerTest.java Ver arquivo

@@ -185,5 +185,13 @@ public class ViewControllerTest extends BaseTest {
185 185
 		uut.destroy();
186 186
 		assertThat(parent.getChildCount()).withFailMessage("expected not to have children").isZero();
187 187
 	}
188
+
189
+	@Test
190
+	public void ensureViewIsCreated() throws Exception {
191
+		ViewController spy = spy(uut);
192
+		verify(spy, times(0)).getView();
193
+		spy.ensureViewIsCreated();
194
+		verify(spy, times(1)).getView();
195
+	}
188 196
 }
189 197