|
@@ -1,6 +1,7 @@
|
1
|
1
|
package com.reactnativenavigation.viewcontrollers;
|
2
|
2
|
|
3
|
3
|
import android.app.Activity;
|
|
4
|
+import android.view.ViewGroup;
|
4
|
5
|
|
5
|
6
|
import com.reactnativenavigation.BaseTest;
|
6
|
7
|
import com.reactnativenavigation.mocks.SimpleViewController;
|
|
@@ -48,14 +49,14 @@ public class NavigatorTest extends BaseTest {
|
48
|
49
|
public void setRoot_AddsChildControllerView() throws Exception {
|
49
|
50
|
assertThat(uut.getView().getChildCount()).isZero();
|
50
|
51
|
uut.setRoot(child1);
|
51
|
|
- assertHasSingleChildViewOf(child1);
|
|
52
|
+ assertHasSingleChildViewOf(uut, child1);
|
52
|
53
|
}
|
53
|
54
|
|
54
|
55
|
@Test
|
55
|
56
|
public void setRoot_ReplacesExistingChildControllerViews() throws Exception {
|
56
|
57
|
uut.setRoot(child1);
|
57
|
58
|
uut.setRoot(child2);
|
58
|
|
- assertHasSingleChildViewOf(child2);
|
|
59
|
+ assertHasSingleChildViewOf(uut, child2);
|
59
|
60
|
}
|
60
|
61
|
|
61
|
62
|
@Test
|
|
@@ -64,8 +65,30 @@ public class NavigatorTest extends BaseTest {
|
64
|
65
|
assertThat(new Navigator(activity).getId()).isNotEqualTo(uut.getId());
|
65
|
66
|
}
|
66
|
67
|
|
67
|
|
- private void assertHasSingleChildViewOf(ViewController vc) {
|
68
|
|
- assertThat(uut.getView().getChildCount()).isEqualTo(1);
|
69
|
|
- assertThat(uut.getView().getChildAt(0)).isEqualTo(vc.getView()).isNotNull();
|
|
68
|
+ @Test
|
|
69
|
+ public void push() throws Exception {
|
|
70
|
+ StackController stackController = new StackController(activity, "stack1");
|
|
71
|
+ stackController.push(child1);
|
|
72
|
+ uut.setRoot(stackController);
|
|
73
|
+
|
|
74
|
+ assertHasSingleChildViewOf(uut, stackController);
|
|
75
|
+ assertHasSingleChildViewOf(stackController, child1);
|
|
76
|
+
|
|
77
|
+ uut.push(child1.getId(), child2);
|
|
78
|
+
|
|
79
|
+ assertHasSingleChildViewOf(uut, stackController);
|
|
80
|
+ assertHasSingleChildViewOf(stackController, child2);
|
|
81
|
+ }
|
|
82
|
+
|
|
83
|
+ @Test
|
|
84
|
+ public void push_InvalidPushWithoutAStack_DoesNothing() throws Exception {
|
|
85
|
+ uut.setRoot(child1);
|
|
86
|
+ uut.push(child1.getId(), child2);
|
|
87
|
+ assertHasSingleChildViewOf(uut, child1);
|
|
88
|
+ }
|
|
89
|
+
|
|
90
|
+ private void assertHasSingleChildViewOf(ViewController parent, ViewController child) {
|
|
91
|
+ assertThat(((ViewGroup) parent.getView()).getChildCount()).isEqualTo(1);
|
|
92
|
+ assertThat(((ViewGroup) parent.getView()).getChildAt(0)).isEqualTo(child.getView()).isNotNull();
|
70
|
93
|
}
|
71
|
94
|
}
|