|
@@ -6,12 +6,13 @@ import android.view.View;
|
6
|
6
|
import android.view.ViewGroup;
|
7
|
7
|
|
8
|
8
|
import com.reactnativenavigation.layout.Container;
|
9
|
|
-import com.reactnativenavigation.layout.ContainerStack;
|
|
9
|
+import com.reactnativenavigation.layout.ContainerStackLayout;
|
10
|
10
|
import com.reactnativenavigation.layout.LayoutFactory;
|
11
|
11
|
import com.reactnativenavigation.layout.LayoutNode;
|
|
12
|
+import com.reactnativenavigation.layout.SideMenuLayout;
|
12
|
13
|
import com.reactnativenavigation.layout.bottomtabs.BottomTabs;
|
13
|
|
-import com.reactnativenavigation.layout.bottomtabs.BottomTabsContainer;
|
14
|
14
|
import com.reactnativenavigation.layout.bottomtabs.BottomTabsCreator;
|
|
15
|
+import com.reactnativenavigation.layout.bottomtabs.BottomTabsLayout;
|
15
|
16
|
|
16
|
17
|
import org.junit.Before;
|
17
|
18
|
import org.junit.Test;
|
|
@@ -33,28 +34,28 @@ import static org.mockito.Mockito.when;
|
33
|
34
|
@RunWith(RobolectricTestRunner.class)
|
34
|
35
|
public class LayoutFactoryTest {
|
35
|
36
|
|
36
|
|
- private final static String VIEW_ID = "myUniqueId";
|
37
|
|
- private final static String VIEW_NAME = "myName";
|
|
37
|
+ private final static String NODE_ID = "myUniqueId";
|
|
38
|
+ private final static String REACT_ROOT_VIEW_KEY = "myName";
|
38
|
39
|
|
39
|
|
- private final static String OTHER_VIEW_ID = "anotherUniqueId";
|
40
|
|
- private final static String OTHER_VIEW_NAME = "anotherName";
|
|
40
|
+ private final static String OTHER_NODE_ID = "anotherUniqueId";
|
|
41
|
+ private final static String OTHER_REACT_ROOT_VIEW_KEY = "anotherName";
|
41
|
42
|
|
42
|
43
|
private Activity activity;
|
43
|
44
|
private View mockView;
|
44
|
45
|
private View otherMockView;
|
45
|
|
- private LayoutFactory.RootViewCreator rootViewCreator;
|
|
46
|
+ private LayoutFactory.ReactRootViewCreator reactRootViewCreator;
|
46
|
47
|
|
47
|
48
|
@Before
|
48
|
49
|
public void setUp() {
|
49
|
50
|
activity = Robolectric.buildActivity(AppCompatActivity.class).get();
|
50
|
51
|
mockView = new View(activity);
|
51
|
52
|
otherMockView = new View(activity);
|
52
|
|
- rootViewCreator = mock(LayoutFactory.RootViewCreator.class);
|
|
53
|
+ reactRootViewCreator = mock(LayoutFactory.ReactRootViewCreator.class);
|
53
|
54
|
}
|
54
|
55
|
|
55
|
56
|
@Test
|
56
|
57
|
public void returnsContainerThatHoldsTheRootView() throws Exception {
|
57
|
|
- when(rootViewCreator.createRootView(eq(VIEW_ID), eq(VIEW_NAME))).thenReturn(mockView);
|
|
58
|
+ when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
58
|
59
|
final LayoutNode node = createContainerNode();
|
59
|
60
|
|
60
|
61
|
final ViewGroup result = (ViewGroup) createLayoutFactory().create(node);
|
|
@@ -65,13 +66,13 @@ public class LayoutFactoryTest {
|
65
|
66
|
|
66
|
67
|
@Test
|
67
|
68
|
public void returnsContainerStack() throws Exception {
|
68
|
|
- when(rootViewCreator.createRootView(eq(VIEW_ID), eq(VIEW_NAME))).thenReturn(mockView);
|
|
69
|
+ when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
69
|
70
|
final LayoutNode containerNode = createContainerNode();
|
70
|
71
|
final LayoutNode stackNode = createContainerStackNode(containerNode);
|
71
|
72
|
|
72
|
73
|
final ViewGroup result = (ViewGroup) createLayoutFactory().create(stackNode);
|
73
|
74
|
|
74
|
|
- assertThat(result).isInstanceOf(ContainerStack.class);
|
|
75
|
+ assertThat(result).isInstanceOf(ContainerStackLayout.class);
|
75
|
76
|
ViewGroup container = (ViewGroup) TestUtils.assertViewChildrenCount(result, 1).get(0);
|
76
|
77
|
TestUtils.assertViewChildren(container, mockView);
|
77
|
78
|
}
|
|
@@ -80,16 +81,16 @@ public class LayoutFactoryTest {
|
80
|
81
|
public void returnsContainerStackWithMultipleViews() throws Exception {
|
81
|
82
|
final View mockView1 = mock(View.class);
|
82
|
83
|
final View mockView2 = mock(View.class);
|
83
|
|
- when(rootViewCreator.createRootView(eq(VIEW_ID), eq(VIEW_NAME))).thenReturn(mockView1);
|
84
|
|
- when(rootViewCreator.createRootView(eq(OTHER_VIEW_ID), eq(OTHER_VIEW_NAME))).thenReturn(mockView2);
|
|
84
|
+ when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView1);
|
|
85
|
+ when(reactRootViewCreator.create(eq(OTHER_NODE_ID), eq(OTHER_REACT_ROOT_VIEW_KEY))).thenReturn(mockView2);
|
85
|
86
|
|
86
|
|
- final LayoutNode containerNode1 = createContainerNode(VIEW_ID, VIEW_NAME);
|
87
|
|
- final LayoutNode containerNode2 = createContainerNode(OTHER_VIEW_ID, OTHER_VIEW_NAME);
|
|
87
|
+ final LayoutNode containerNode1 = createContainerNode(NODE_ID, REACT_ROOT_VIEW_KEY);
|
|
88
|
+ final LayoutNode containerNode2 = createContainerNode(OTHER_NODE_ID, OTHER_REACT_ROOT_VIEW_KEY);
|
88
|
89
|
final LayoutNode stackNode = createContainerStackNode(containerNode1, containerNode2);
|
89
|
90
|
|
90
|
91
|
final ViewGroup result = (ViewGroup) createLayoutFactory().create(stackNode);
|
91
|
92
|
|
92
|
|
- assertThat(result).isInstanceOf(ContainerStack.class);
|
|
93
|
+ assertThat(result).isInstanceOf(ContainerStackLayout.class);
|
93
|
94
|
List<View> containers = TestUtils.assertViewChildrenCount(result, 2);
|
94
|
95
|
ViewGroup container1 = (ViewGroup) containers.get(0);
|
95
|
96
|
ViewGroup container2 = (ViewGroup) containers.get(1);
|
|
@@ -97,21 +98,47 @@ public class LayoutFactoryTest {
|
97
|
98
|
TestUtils.assertViewChildren(container2, mockView2);
|
98
|
99
|
}
|
99
|
100
|
|
|
101
|
+ @Test
|
|
102
|
+ public void returnsSideMenuRoot() throws Exception {
|
|
103
|
+ when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
|
104
|
+ final LayoutNode containerNode = createSideMenuContainerNode(Arrays.asList(createContainerNode()));
|
|
105
|
+ final ViewGroup result = (ViewGroup) createLayoutFactory().create(containerNode);
|
|
106
|
+ assertThat(result).isInstanceOf(SideMenuLayout.class);
|
|
107
|
+ }
|
|
108
|
+
|
|
109
|
+ @Test
|
|
110
|
+ public void hasContentContainer() throws Exception {
|
|
111
|
+ when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
|
112
|
+ LayoutNode contentContainer = createContainerNode();
|
|
113
|
+ final LayoutNode sideMenu = createSideMenuContainerNode(Arrays.asList(contentContainer));
|
|
114
|
+ final ViewGroup result = (ViewGroup) createLayoutFactory().create(sideMenu);
|
|
115
|
+ assertThat(result.getChildAt(0)).isInstanceOf(Container.class);
|
|
116
|
+ }
|
|
117
|
+
|
|
118
|
+ @Test
|
|
119
|
+ public void hasLeftMenu() throws Exception {
|
|
120
|
+ when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
|
121
|
+ LayoutNode sideMenuLeft = createSideMenuLeftNode();
|
|
122
|
+ final LayoutNode sideMenu = createSideMenuContainerNode(Arrays.asList(sideMenuLeft));
|
|
123
|
+ final ViewGroup result = (ViewGroup) createLayoutFactory().create(sideMenu);
|
|
124
|
+ assertThat(result.getChildAt(0)).isInstanceOf(Container.class);
|
|
125
|
+ }
|
|
126
|
+
|
100
|
127
|
@Test
|
101
|
128
|
public void returnsSingleTabContent() throws Exception {
|
102
|
129
|
BottomTabs bottomTabsMock = mock(BottomTabs.class);
|
103
|
130
|
when(bottomTabsMock.size()).thenReturn(0);
|
104
|
131
|
|
105
|
|
- when(rootViewCreator.createRootView(eq(VIEW_ID), eq(VIEW_NAME))).thenReturn(mockView);
|
|
132
|
+ when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
106
|
133
|
final LayoutNode containerNode = createContainerNode();
|
107
|
|
- final LayoutNode tabNode = createTabNode(containerNode);
|
|
134
|
+ final LayoutNode tabNode = createBottomTabNode(containerNode);
|
108
|
135
|
|
109
|
136
|
final View result = createLayoutFactory(bottomTabsMock).create(tabNode);
|
110
|
137
|
|
111
|
138
|
verify(bottomTabsMock).add("#0");
|
112
|
139
|
|
113
|
|
- assertThat(result).isInstanceOf(BottomTabsContainer.class);
|
114
|
|
- Container container = (Container) TestUtils.assertViewChildrenCount((BottomTabsContainer) result, 1).get(0);
|
|
140
|
+ assertThat(result).isInstanceOf(BottomTabsLayout.class);
|
|
141
|
+ Container container = (Container) TestUtils.assertViewChildrenCount((BottomTabsLayout) result, 1).get(0);
|
115
|
142
|
View view = TestUtils.assertViewChildrenCount(container, 1).get(0);
|
116
|
143
|
assertThat(view).isEqualTo(mockView);
|
117
|
144
|
}
|
|
@@ -121,17 +148,17 @@ public class LayoutFactoryTest {
|
121
|
148
|
BottomTabs bottomTabsMock = mock(BottomTabs.class);
|
122
|
149
|
when(bottomTabsMock.size()).thenReturn(0, 1);
|
123
|
150
|
|
124
|
|
- when(rootViewCreator.createRootView(eq(VIEW_ID), eq(VIEW_NAME))).thenReturn(mockView);
|
125
|
|
- final LayoutNode firstTabRootNode = createContainerNode(VIEW_ID, VIEW_NAME);
|
|
151
|
+ when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
|
152
|
+ final LayoutNode firstTabRootNode = createContainerNode(NODE_ID, REACT_ROOT_VIEW_KEY);
|
126
|
153
|
|
127
|
|
- when(rootViewCreator.createRootView(eq(OTHER_VIEW_ID), eq(OTHER_VIEW_NAME))).thenReturn(otherMockView);
|
128
|
|
- final LayoutNode secondTabRootNode = createContainerStackNode(createContainerNode(OTHER_VIEW_ID, OTHER_VIEW_NAME));
|
|
154
|
+ when(reactRootViewCreator.create(eq(OTHER_NODE_ID), eq(OTHER_REACT_ROOT_VIEW_KEY))).thenReturn(otherMockView);
|
|
155
|
+ final LayoutNode secondTabRootNode = createContainerStackNode(createContainerNode(OTHER_NODE_ID, OTHER_REACT_ROOT_VIEW_KEY));
|
129
|
156
|
|
130
|
|
- final LayoutNode tabNode = createTabNode(firstTabRootNode, secondTabRootNode);
|
|
157
|
+ final LayoutNode tabNode = createBottomTabNode(firstTabRootNode, secondTabRootNode);
|
131
|
158
|
|
132
|
159
|
final View result = createLayoutFactory(bottomTabsMock).create(tabNode);
|
133
|
160
|
|
134
|
|
- assertThat(result).isInstanceOf(BottomTabsContainer.class);
|
|
161
|
+ assertThat(result).isInstanceOf(BottomTabsLayout.class);
|
135
|
162
|
verify(bottomTabsMock).add(eq("#0"));
|
136
|
163
|
verify(bottomTabsMock).add(eq("#1"));
|
137
|
164
|
}
|
|
@@ -139,8 +166,8 @@ public class LayoutFactoryTest {
|
139
|
166
|
|
140
|
167
|
@Test(expected = IllegalArgumentException.class)
|
141
|
168
|
public void throwsExceptionForUnknownType() throws Exception {
|
142
|
|
- when(rootViewCreator.createRootView(eq(VIEW_ID), eq(VIEW_NAME))).thenReturn(mockView);
|
143
|
|
- final LayoutNode node = new LayoutNode(VIEW_ID, "***unknownType***", Collections.<String, Object>emptyMap());
|
|
169
|
+ when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
|
|
170
|
+ final LayoutNode node = new LayoutNode(NODE_ID, "***unknownType***", Collections.<String, Object>emptyMap());
|
144
|
171
|
|
145
|
172
|
createLayoutFactory().create(node);
|
146
|
173
|
}
|
|
@@ -156,28 +183,31 @@ public class LayoutFactoryTest {
|
156
|
183
|
when(bottomTabsCreator.create()).thenReturn(bottomTabs);
|
157
|
184
|
}
|
158
|
185
|
|
159
|
|
- return new LayoutFactory(activity, rootViewCreator, bottomTabsCreator);
|
|
186
|
+ return new LayoutFactory(activity, reactRootViewCreator, bottomTabsCreator);
|
160
|
187
|
}
|
161
|
188
|
|
162
|
189
|
private LayoutNode createContainerNode() {
|
163
|
|
- return createContainerNode(VIEW_ID, VIEW_NAME);
|
|
190
|
+ return createContainerNode(NODE_ID, REACT_ROOT_VIEW_KEY);
|
|
191
|
+ }
|
|
192
|
+
|
|
193
|
+ private LayoutNode createSideMenuLeftNode() {
|
|
194
|
+ List<LayoutNode> children = Arrays.asList(createContainerNode());
|
|
195
|
+ return new LayoutNode("SideMenuLeft", children);
|
164
|
196
|
}
|
165
|
197
|
|
166
|
198
|
private LayoutNode createContainerNode(final String id, final String name) {
|
167
|
199
|
return new LayoutNode(id, "Container", new HashMap<String, Object>() {{ put("name", name); }});
|
168
|
200
|
}
|
169
|
201
|
|
|
202
|
+ private LayoutNode createSideMenuContainerNode(List<LayoutNode> children) {
|
|
203
|
+ return new LayoutNode("SideMenuRoot", children);
|
|
204
|
+ }
|
|
205
|
+
|
170
|
206
|
private LayoutNode createContainerStackNode(LayoutNode... children) {
|
171
|
|
- LayoutNode node = new LayoutNode();
|
172
|
|
- node.type = "ContainerStack";
|
173
|
|
- node.children = Arrays.asList(children);
|
174
|
|
- return node;
|
|
207
|
+ return new LayoutNode("ContainerStack", Arrays.asList(children));
|
175
|
208
|
}
|
176
|
209
|
|
177
|
|
- private LayoutNode createTabNode(LayoutNode... children) {
|
178
|
|
- LayoutNode node = new LayoutNode();
|
179
|
|
- node.type = "BottomTabs";
|
180
|
|
- node.children = Arrays.asList(children);
|
181
|
|
- return node;
|
|
210
|
+ private LayoutNode createBottomTabNode(LayoutNode... children) {
|
|
211
|
+ return new LayoutNode("BottomTabs", Arrays.asList(children));
|
182
|
212
|
}
|
183
|
213
|
}
|