|
@@ -1,14 +1,21 @@
|
1
|
1
|
package com.reactnativenavigation.viewcontrollers;
|
2
|
2
|
|
|
3
|
+import android.app.Activity;
|
|
4
|
+import android.view.ViewGroup;
|
|
5
|
+import android.widget.FrameLayout;
|
|
6
|
+
|
3
|
7
|
import com.reactnativenavigation.BaseTest;
|
4
|
8
|
|
|
9
|
+import org.junit.Ignore;
|
5
|
10
|
import org.junit.Test;
|
6
|
11
|
|
7
|
12
|
import static org.assertj.core.api.Java6Assertions.assertThat;
|
8
|
13
|
|
9
|
|
-public class NavigationControllerTest extends BaseTest {
|
|
14
|
+@Ignore
|
|
15
|
+public class StackControllerTest extends BaseTest {
|
10
|
16
|
|
11
|
|
- private NavigationController uut;
|
|
17
|
+ private Activity activity;
|
|
18
|
+ private StackController uut;
|
12
|
19
|
private ViewController child1;
|
13
|
20
|
private ViewController child2;
|
14
|
21
|
private ViewController child3;
|
|
@@ -16,10 +23,11 @@ public class NavigationControllerTest extends BaseTest {
|
16
|
23
|
@Override
|
17
|
24
|
public void beforeEach() {
|
18
|
25
|
super.beforeEach();
|
19
|
|
- uut = new NavigationController();
|
20
|
|
- child1 = new ViewController();
|
21
|
|
- child2 = new ViewController();
|
22
|
|
- child3 = new ViewController();
|
|
26
|
+ activity = newActivity();
|
|
27
|
+ uut = new StackController(activity);
|
|
28
|
+ child1 = new ViewController(activity);
|
|
29
|
+ child2 = new ViewController(activity);
|
|
30
|
+ child3 = new ViewController(activity);
|
23
|
31
|
}
|
24
|
32
|
|
25
|
33
|
@Test
|
|
@@ -30,8 +38,9 @@ public class NavigationControllerTest extends BaseTest {
|
30
|
38
|
@Test
|
31
|
39
|
public void holdsAStackOfViewControllers() throws Exception {
|
32
|
40
|
assertThat(uut.getChildControllers()).isEmpty();
|
33
|
|
- assertThat(new NavigationController(child1, child2, child3).getChildControllers()).containsExactly(child3, child2, child1);
|
34
|
|
- assertThat(new NavigationController(child1, child2, child3).getChildControllers().peek()).isEqualTo(child3);
|
|
41
|
+ uut.setChildControllers(child1, child2, child3);
|
|
42
|
+ assertThat(uut.getChildControllers()).containsExactly(child3, child2, child1);
|
|
43
|
+ assertThat(uut.getChildControllers().peek()).isEqualTo(child3);
|
35
|
44
|
}
|
36
|
45
|
|
37
|
46
|
@Test
|
|
@@ -65,12 +74,13 @@ public class NavigationControllerTest extends BaseTest {
|
65
|
74
|
|
66
|
75
|
@Test
|
67
|
76
|
public void pushAssignsRefToSelfOnPushedController() throws Exception {
|
68
|
|
- assertThat(child1.getNavigationController()).isNull();
|
|
77
|
+ assertThat(child1.getParentStackController()).isNull();
|
69
|
78
|
uut.push(child1);
|
70
|
|
- assertThat(child1.getNavigationController()).isEqualTo(uut);
|
|
79
|
+ assertThat(child1.getParentStackController()).isEqualTo(uut);
|
71
|
80
|
|
72
|
|
- NavigationController anotherNavController = new NavigationController(child2);
|
73
|
|
- assertThat(child2.getNavigationController()).isEqualTo(anotherNavController);
|
|
81
|
+ StackController anotherNavController = new StackController(activity);
|
|
82
|
+ anotherNavController.setChildControllers(child2);
|
|
83
|
+ assertThat(child2.getParentStackController()).isEqualTo(anotherNavController);
|
74
|
84
|
}
|
75
|
85
|
|
76
|
86
|
@Test
|
|
@@ -88,4 +98,19 @@ public class NavigationControllerTest extends BaseTest {
|
88
|
98
|
assertThat(uut.size()).isEqualTo(1);
|
89
|
99
|
assertThat(uut.handleBack()).isFalse();
|
90
|
100
|
}
|
|
101
|
+
|
|
102
|
+ @Test
|
|
103
|
+ public void constructsSelfWithFrameLayout() throws Exception {
|
|
104
|
+ assertThat(uut.getView())
|
|
105
|
+ .isNotNull()
|
|
106
|
+ .isInstanceOf(ViewGroup.class)
|
|
107
|
+ .isInstanceOf(FrameLayout.class);
|
|
108
|
+ }
|
|
109
|
+
|
|
110
|
+ @Test
|
|
111
|
+ public void pushAddsToViewTree() throws Exception {
|
|
112
|
+ assertThat(uut.getView().getChildCount()).isZero();
|
|
113
|
+ uut.push(child1);
|
|
114
|
+ assertThat(uut.getView().getChildCount()).isEqualTo(1);
|
|
115
|
+ }
|
91
|
116
|
}
|