|
@@ -1,13 +1,17 @@
|
1
|
1
|
package com.reactnativenavigation;
|
2
|
2
|
|
3
|
3
|
import android.app.Activity;
|
|
4
|
+import android.support.v7.app.AppCompatActivity;
|
4
|
5
|
import android.view.View;
|
5
|
6
|
import android.view.ViewGroup;
|
6
|
7
|
|
|
8
|
+import com.reactnativenavigation.layout.bottomtabs.BottomTabs;
|
|
9
|
+import com.reactnativenavigation.layout.bottomtabs.BottomTabsContainer;
|
7
|
10
|
import com.reactnativenavigation.layout.Container;
|
8
|
11
|
import com.reactnativenavigation.layout.ContainerStack;
|
9
|
12
|
import com.reactnativenavigation.layout.LayoutFactory;
|
10
|
13
|
import com.reactnativenavigation.layout.LayoutNode;
|
|
14
|
+import com.reactnativenavigation.layout.bottomtabs.BottomTabsCreator;
|
11
|
15
|
|
12
|
16
|
import org.junit.Before;
|
13
|
17
|
import org.junit.Test;
|
|
@@ -26,7 +30,6 @@ import static org.mockito.ArgumentMatchers.eq;
|
26
|
30
|
import static org.mockito.Mockito.mock;
|
27
|
31
|
import static org.mockito.Mockito.when;
|
28
|
32
|
|
29
|
|
-
|
30
|
33
|
@RunWith(RobolectricTestRunner.class)
|
31
|
34
|
public class LayoutFactoryTest {
|
32
|
35
|
|
|
@@ -36,17 +39,19 @@ public class LayoutFactoryTest {
|
36
|
39
|
private final static String OTHER_VIEW_ID = "anotherUniqueId";
|
37
|
40
|
private final static String OTHER_VIEW_NAME = "anotherName";
|
38
|
41
|
|
|
42
|
+ private Activity activity;
|
39
|
43
|
private View mockView;
|
40
|
44
|
private LayoutFactory.RootViewCreator rootViewCreator;
|
41
|
45
|
|
42
|
46
|
@Before
|
43
|
47
|
public void setUp() {
|
44
|
|
- mockView = new View(Robolectric.setupActivity(Activity.class));
|
|
48
|
+ activity = Robolectric.buildActivity(AppCompatActivity.class).get();
|
|
49
|
+ mockView = new View(activity);
|
45
|
50
|
rootViewCreator = mock(LayoutFactory.RootViewCreator.class);
|
46
|
51
|
}
|
47
|
52
|
|
48
|
53
|
@Test
|
49
|
|
- public void returnsContainerThatHoldsTheRootView() {
|
|
54
|
+ public void returnsContainerThatHoldsTheRootView() throws Exception {
|
50
|
55
|
when(rootViewCreator.createRootView(eq(VIEW_ID), eq(VIEW_NAME))).thenReturn(mockView);
|
51
|
56
|
final LayoutNode node = createContainerNode();
|
52
|
57
|
|
|
@@ -57,12 +62,12 @@ public class LayoutFactoryTest {
|
57
|
62
|
}
|
58
|
63
|
|
59
|
64
|
@Test
|
60
|
|
- public void returnsContainerStack() {
|
|
65
|
+ public void returnsContainerStack() throws Exception {
|
61
|
66
|
when(rootViewCreator.createRootView(eq(VIEW_ID), eq(VIEW_NAME))).thenReturn(mockView);
|
62
|
|
- final LayoutNode node = createContainerNode();
|
63
|
|
- final LayoutNode outerNode = getContainerStackNode(node);
|
|
67
|
+ final LayoutNode containerNode = createContainerNode();
|
|
68
|
+ final LayoutNode stackNode = getContainerStackNode(containerNode);
|
64
|
69
|
|
65
|
|
- final ViewGroup result = (ViewGroup) createLayoutFactory().create(outerNode);
|
|
70
|
+ final ViewGroup result = (ViewGroup) createLayoutFactory().create(stackNode);
|
66
|
71
|
|
67
|
72
|
assertThat(result).isInstanceOf(ContainerStack.class);
|
68
|
73
|
ViewGroup container = (ViewGroup) assertViewChildrenCount(result, 1).get(0);
|
|
@@ -70,17 +75,17 @@ public class LayoutFactoryTest {
|
70
|
75
|
}
|
71
|
76
|
|
72
|
77
|
@Test
|
73
|
|
- public void returnsContainerStackWithMultipleViews() {
|
|
78
|
+ public void returnsContainerStackWithMultipleViews() throws Exception {
|
74
|
79
|
final View mockView1 = mock(View.class);
|
75
|
80
|
final View mockView2 = mock(View.class);
|
76
|
81
|
when(rootViewCreator.createRootView(eq(VIEW_ID), eq(VIEW_NAME))).thenReturn(mockView1);
|
77
|
82
|
when(rootViewCreator.createRootView(eq(OTHER_VIEW_ID), eq(OTHER_VIEW_NAME))).thenReturn(mockView2);
|
78
|
83
|
|
79
|
|
- final LayoutNode node1 = createContainerNode(VIEW_ID, VIEW_NAME);
|
80
|
|
- final LayoutNode node2 = createContainerNode(OTHER_VIEW_ID, OTHER_VIEW_NAME);
|
81
|
|
- final LayoutNode outerNode = getContainerStackNode(Arrays.asList(node1, node2));
|
|
84
|
+ final LayoutNode containerNode1 = createContainerNode(VIEW_ID, VIEW_NAME);
|
|
85
|
+ final LayoutNode containerNode2 = createContainerNode(OTHER_VIEW_ID, OTHER_VIEW_NAME);
|
|
86
|
+ final LayoutNode stackNode = getContainerStackNode(Arrays.asList(containerNode1, containerNode2));
|
82
|
87
|
|
83
|
|
- final ViewGroup result = (ViewGroup) createLayoutFactory().create(outerNode);
|
|
88
|
+ final ViewGroup result = (ViewGroup) createLayoutFactory().create(stackNode);
|
84
|
89
|
|
85
|
90
|
assertThat(result).isInstanceOf(ContainerStack.class);
|
86
|
91
|
List<View> containers = assertViewChildrenCount(result, 2);
|
|
@@ -90,8 +95,22 @@ public class LayoutFactoryTest {
|
90
|
95
|
assertViewChildren(container2, mockView2);
|
91
|
96
|
}
|
92
|
97
|
|
|
98
|
+ @Test
|
|
99
|
+ public void returnsSingleTabContent() throws Exception {
|
|
100
|
+ when(rootViewCreator.createRootView(eq(VIEW_ID), eq(VIEW_NAME))).thenReturn(mockView);
|
|
101
|
+ final LayoutNode containerNode = createContainerNode();
|
|
102
|
+ final LayoutNode tabNode = createTabNode(containerNode);
|
|
103
|
+
|
|
104
|
+ final View result = createLayoutFactory().create(tabNode);
|
|
105
|
+
|
|
106
|
+ assertThat(result).isInstanceOf(BottomTabsContainer.class);
|
|
107
|
+ View containerView = assertViewChildrenCount((BottomTabsContainer) result, 1).get(0);
|
|
108
|
+ assertThat(containerView).isInstanceOf(Container.class);
|
|
109
|
+ assertViewChildren((Container) containerView, mockView);
|
|
110
|
+ }
|
|
111
|
+
|
93
|
112
|
@Test(expected = IllegalArgumentException.class)
|
94
|
|
- public void throwsExceptionForUnknownType() {
|
|
113
|
+ public void throwsExceptionForUnknownType() throws Exception {
|
95
|
114
|
when(rootViewCreator.createRootView(eq(VIEW_ID), eq(VIEW_NAME))).thenReturn(mockView);
|
96
|
115
|
final LayoutNode node = new LayoutNode(VIEW_ID, "***unknownType***", Collections.<String, Object>emptyMap());
|
97
|
116
|
|
|
@@ -99,7 +118,10 @@ public class LayoutFactoryTest {
|
99
|
118
|
}
|
100
|
119
|
|
101
|
120
|
private LayoutFactory createLayoutFactory() {
|
102
|
|
- return new LayoutFactory(Robolectric.buildActivity(Activity.class).get(), rootViewCreator);
|
|
121
|
+ BottomTabs bottomTabs = mock(BottomTabs.class);
|
|
122
|
+ BottomTabsCreator bottomTabsCreator = mock(BottomTabsCreator.class);
|
|
123
|
+ when(bottomTabsCreator.create()).thenReturn(bottomTabs);
|
|
124
|
+ return new LayoutFactory(activity, rootViewCreator, bottomTabsCreator);
|
103
|
125
|
}
|
104
|
126
|
|
105
|
127
|
private LayoutNode createContainerNode() {
|
|
@@ -115,10 +137,17 @@ public class LayoutFactoryTest {
|
115
|
137
|
}
|
116
|
138
|
|
117
|
139
|
private LayoutNode getContainerStackNode(List<LayoutNode> children) {
|
118
|
|
- LayoutNode outerNode = new LayoutNode();
|
119
|
|
- outerNode.type = "ContainerStack";
|
120
|
|
- outerNode.children = children;
|
121
|
|
- return outerNode;
|
|
140
|
+ LayoutNode node = new LayoutNode();
|
|
141
|
+ node.type = "ContainerStack";
|
|
142
|
+ node.children = children;
|
|
143
|
+ return node;
|
|
144
|
+ }
|
|
145
|
+
|
|
146
|
+ private LayoutNode createTabNode(LayoutNode children) {
|
|
147
|
+ LayoutNode node = new LayoutNode();
|
|
148
|
+ node.type = "BottomTabs";
|
|
149
|
+ node.children = Arrays.asList(children);
|
|
150
|
+ return node;
|
122
|
151
|
}
|
123
|
152
|
|
124
|
153
|
private List<View> assertViewChildrenCount(ViewGroup view, int count) {
|