Browse Source

some more tests for ContainerViewController

Daniel Zlotin 7 years ago
parent
commit
2277a8f53f

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

77
 
77
 
78
 	public void applyNavigationOptions(final NavigationOptions options) {
78
 	public void applyNavigationOptions(final NavigationOptions options) {
79
 		navigationOptions.mergeWith(options);
79
 		navigationOptions.mergeWith(options);
80
+		applyNavigationOptions();
81
+	}
82
+
83
+	private void applyNavigationOptions() {
80
 		if (getParentStackController() != null) {
84
 		if (getParentStackController() != null) {
81
 			getParentStackController().setTitle(navigationOptions.title);
85
 			getParentStackController().setTitle(navigationOptions.title);
82
 		}
86
 		}

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

140
 		ensureViewIsCreated();
140
 		ensureViewIsCreated();
141
 		return topBar;
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 View File

27
 	@NonNull
27
 	@NonNull
28
 	protected abstract View createView();
28
 	protected abstract View createView();
29
 
29
 
30
+	public void ensureViewIsCreated() {
31
+		getView();
32
+	}
33
+
30
 	public boolean handleBack() {
34
 	public boolean handleBack() {
31
 		return false;
35
 		return false;
32
 	}
36
 	}

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

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 View File

185
 		uut.destroy();
185
 		uut.destroy();
186
 		assertThat(parent.getChildCount()).withFailMessage("expected not to have children").isZero();
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