Browse Source

android: added back missing tests

Daniel Zlotin 7 years ago
parent
commit
e1841944d8

+ 135
- 0
android/app/src/test/java/com/reactnativenavigation/layout/BottomTabsContainerTest.java View File

@@ -0,0 +1,135 @@
1
+package com.reactnativenavigation.layout;
2
+
3
+import android.app.Activity;
4
+import android.view.View;
5
+
6
+import com.reactnativenavigation.BaseTest;
7
+import com.reactnativenavigation.layout.bottomtabs.BottomTabs;
8
+import com.reactnativenavigation.layout.bottomtabs.BottomTabsLayout;
9
+import com.reactnativenavigation.layout.bottomtabs.TooManyTabsException;
10
+
11
+import org.junit.Before;
12
+import org.junit.Test;
13
+import org.robolectric.Robolectric;
14
+
15
+import static org.assertj.core.api.Java6Assertions.assertThat;
16
+import static org.mockito.Mockito.mock;
17
+import static org.mockito.Mockito.verify;
18
+
19
+public class BottomTabsContainerTest extends BaseTest {
20
+
21
+    private static final String TAB_NAME = "myTab";
22
+    private static final String OTHER_TAB_NAME = "myOtherTab";
23
+
24
+    private BottomTabs bottomTabs;
25
+    private Activity activity;
26
+
27
+    @Before
28
+    public void setUp() throws Exception {
29
+        bottomTabs = mock(BottomTabs.class);
30
+        activity = Robolectric.buildActivity(Activity.class).get();
31
+    }
32
+
33
+    @Test
34
+    public void addsTabToBottomTabs() throws Exception {
35
+        ContainerStackLayout tabContent = new ContainerStackLayout(activity);
36
+
37
+        BottomTabsLayout bottomTabsContainer = createBottomTabsContainer();
38
+        bottomTabsContainer.addTabContent(TAB_NAME, tabContent);
39
+
40
+        verify(bottomTabs).add(TAB_NAME);
41
+    }
42
+
43
+    @Test
44
+    public void addsTabContentToLayout() throws Exception {
45
+        ContainerStackLayout stackLayout = new ContainerStackLayout(activity);
46
+
47
+        BottomTabsLayout bottomTabsContainer = createBottomTabsContainer();
48
+        bottomTabsContainer.addTabContent(TAB_NAME, stackLayout);
49
+
50
+        verify(bottomTabs).attach(bottomTabsContainer);
51
+        TestUtils.assertViewChildren(bottomTabsContainer, stackLayout);
52
+    }
53
+
54
+    @Test
55
+    public void addsTwoTabsContentToLayout() throws Exception {
56
+        View tabContent = new ContainerStackLayout(activity);
57
+        View otherTabContent = new ContainerStackLayout(activity);
58
+
59
+        BottomTabsLayout bottomTabsContainer = createBottomTabsContainer();
60
+        bottomTabsContainer.addTabContent(TAB_NAME, tabContent);
61
+        bottomTabsContainer.addTabContent(OTHER_TAB_NAME, otherTabContent);
62
+
63
+        TestUtils.assertViewChildren(bottomTabsContainer, tabContent, otherTabContent);
64
+    }
65
+
66
+    @Test(expected = TooManyTabsException.class)
67
+    public void throwsExceptionWhenMoreThenFiveTabs() throws Exception {
68
+        BottomTabsLayout bottomTabsContainer = createBottomTabsContainer();
69
+        for (int i = 0; i < 6; i++) {
70
+            ContainerStackLayout content = new ContainerStackLayout(activity);
71
+            bottomTabsContainer.addTabContent("#" + i, content);
72
+        }
73
+    }
74
+
75
+    @Test
76
+    public void addFiveTabs() throws Exception {
77
+        BottomTabsLayout bottomTabsContainer = createBottomTabsContainer();
78
+        for (int i = 0; i < 5; i++) {
79
+            ContainerStackLayout content = new ContainerStackLayout(activity);
80
+            bottomTabsContainer.addTabContent("#" + i, content);
81
+        }
82
+    }
83
+
84
+    @Test
85
+    public void onlyFirstTabShouldBeVisible() throws Exception {
86
+        ContainerStackLayout tabContent = new ContainerStackLayout(activity);
87
+        ContainerStackLayout otherTabContent = new ContainerStackLayout(activity);
88
+
89
+        BottomTabsLayout bottomTabsContainer = createBottomTabsContainer();
90
+        bottomTabsContainer.addTabContent(TAB_NAME, tabContent);
91
+        bottomTabsContainer.addTabContent(OTHER_TAB_NAME, otherTabContent);
92
+
93
+        assertThat(tabContent.getVisibility()).isEqualTo(View.VISIBLE);
94
+        assertThat(otherTabContent.getVisibility()).isEqualTo(View.GONE);
95
+    }
96
+
97
+    @Test
98
+    public void listensToTabsSwitchingEvents() throws Exception {
99
+        BottomTabsLayout bottomTabsContainer = createBottomTabsContainer();
100
+        verify(bottomTabs).setSelectionListener(bottomTabsContainer);
101
+    }
102
+
103
+    @Test
104
+    public void switchesBetweenFirstAndSecondTabs() throws Exception {
105
+        ContainerStackLayout tabContent = new ContainerStackLayout(activity);
106
+        ContainerStackLayout otherTabContent = new ContainerStackLayout(activity);
107
+
108
+        BottomTabsLayout bottomTabsContainer = createBottomTabsContainer();
109
+        bottomTabsContainer.addTabContent(TAB_NAME, tabContent);
110
+        bottomTabsContainer.addTabContent(OTHER_TAB_NAME, otherTabContent);
111
+        bottomTabsContainer.onTabSelected(1);
112
+
113
+        assertThat(tabContent.getVisibility()).isEqualTo(View.GONE);
114
+        assertThat(otherTabContent.getVisibility()).isEqualTo(View.VISIBLE);
115
+    }
116
+
117
+    @Test
118
+    public void switchesBetweenSecondAndFirstTabs() throws Exception {
119
+        ContainerStackLayout tabContent = new ContainerStackLayout(activity);
120
+        ContainerStackLayout otherTabContent = new ContainerStackLayout(activity);
121
+
122
+        BottomTabsLayout bottomTabsContainer = createBottomTabsContainer();
123
+        bottomTabsContainer.addTabContent(TAB_NAME, tabContent);
124
+        bottomTabsContainer.addTabContent(OTHER_TAB_NAME, otherTabContent);
125
+        bottomTabsContainer.onTabSelected(1);
126
+        bottomTabsContainer.onTabSelected(0);
127
+
128
+        assertThat(tabContent.getVisibility()).isEqualTo(View.VISIBLE);
129
+        assertThat(otherTabContent.getVisibility()).isEqualTo(View.GONE);
130
+    }
131
+
132
+    private BottomTabsLayout createBottomTabsContainer() {
133
+        return new BottomTabsLayout(activity, bottomTabs);
134
+    }
135
+}

+ 344
- 0
android/app/src/test/java/com/reactnativenavigation/layout/LayoutFactoryTest.java View File

@@ -0,0 +1,344 @@
1
+package com.reactnativenavigation.layout;
2
+
3
+import android.app.Activity;
4
+import android.support.v7.app.AppCompatActivity;
5
+import android.view.View;
6
+import android.view.ViewGroup;
7
+
8
+import com.reactnativenavigation.BaseTest;
9
+import com.reactnativenavigation.layout.bottomtabs.BottomTabs;
10
+import com.reactnativenavigation.layout.bottomtabs.BottomTabsCreator;
11
+import com.reactnativenavigation.layout.bottomtabs.BottomTabsLayout;
12
+
13
+import org.junit.Before;
14
+import org.junit.Test;
15
+import org.robolectric.Robolectric;
16
+
17
+import java.util.Arrays;
18
+import java.util.Collections;
19
+import java.util.HashMap;
20
+import java.util.List;
21
+
22
+import static org.assertj.core.api.Java6Assertions.assertThat;
23
+import static org.mockito.ArgumentMatchers.eq;
24
+import static org.mockito.Mockito.mock;
25
+import static org.mockito.Mockito.verify;
26
+import static org.mockito.Mockito.when;
27
+
28
+public class LayoutFactoryTest extends BaseTest {
29
+
30
+    private final static String NODE_ID = "myUniqueId";
31
+    private final static String REACT_ROOT_VIEW_KEY = "myName";
32
+
33
+    private final static String OTHER_NODE_ID = "anotherUniqueId";
34
+    private final static String OTHER_REACT_ROOT_VIEW_KEY = "anotherName";
35
+
36
+    private Activity activity;
37
+    private View mockView;
38
+    private View otherMockView;
39
+    private LayoutFactory.ReactRootViewCreator reactRootViewCreator;
40
+
41
+    @Before
42
+    public void setUp() {
43
+        activity = Robolectric.buildActivity(AppCompatActivity.class).get();
44
+        mockView = new View(activity);
45
+        otherMockView = new View(activity);
46
+        reactRootViewCreator = mock(LayoutFactory.ReactRootViewCreator.class);
47
+    }
48
+
49
+    @Test
50
+    public void returnsContainerThatHoldsTheRootView() throws Exception {
51
+        when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
52
+        final LayoutNode node = createContainerNode();
53
+
54
+        final ViewGroup result = (ViewGroup) createLayoutFactory().create(node);
55
+
56
+        assertThat(result).isInstanceOf(Container.class);
57
+        TestUtils.assertViewChildren(result, mockView);
58
+    }
59
+
60
+    @Test
61
+    public void returnsContainerStack() throws Exception {
62
+        when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
63
+        final LayoutNode containerNode = createContainerNode();
64
+        final LayoutNode stackNode = createContainerStackNode(containerNode);
65
+
66
+        final ViewGroup result = (ViewGroup) createLayoutFactory().create(stackNode);
67
+
68
+        assertThat(result).isInstanceOf(ContainerStackLayout.class);
69
+        ViewGroup container = (ViewGroup) TestUtils.assertViewChildrenCount(result, 1).get(0);
70
+        TestUtils.assertViewChildren(container, mockView);
71
+    }
72
+
73
+    @Test
74
+    public void returnsContainerStackWithMultipleViews() throws Exception {
75
+        final View mockView1 = mock(View.class);
76
+        final View mockView2 = mock(View.class);
77
+        when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView1);
78
+        when(reactRootViewCreator.create(eq(OTHER_NODE_ID), eq(OTHER_REACT_ROOT_VIEW_KEY))).thenReturn(mockView2);
79
+
80
+        final LayoutNode containerNode1 = createContainerNode(NODE_ID, REACT_ROOT_VIEW_KEY);
81
+        final LayoutNode containerNode2 = createContainerNode(OTHER_NODE_ID, OTHER_REACT_ROOT_VIEW_KEY);
82
+        final LayoutNode stackNode = createContainerStackNode(containerNode1, containerNode2);
83
+
84
+        final ViewGroup result = (ViewGroup) createLayoutFactory().create(stackNode);
85
+
86
+        assertThat(result).isInstanceOf(ContainerStackLayout.class);
87
+        List<View> containers = TestUtils.assertViewChildrenCount(result, 2);
88
+        ViewGroup container1 = (ViewGroup) containers.get(0);
89
+        ViewGroup container2 = (ViewGroup) containers.get(1);
90
+        TestUtils.assertViewChildren(container1, mockView1);
91
+        TestUtils.assertViewChildren(container2, mockView2);
92
+    }
93
+
94
+    @Test
95
+    public void returnsSideMenuRoot() throws Exception {
96
+        when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
97
+        final LayoutNode containerNode = createSideMenuContainerNode(Arrays.asList(createContainerNode()));
98
+        final ViewGroup result = (ViewGroup) createLayoutFactory().create(containerNode);
99
+        assertThat(result).isInstanceOf(SideMenuLayout.class);
100
+    }
101
+
102
+    @Test
103
+    public void hasContentContainer() throws Exception {
104
+        when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
105
+        LayoutNode contentContainer = createContainerNode();
106
+        final LayoutNode sideMenu = createSideMenuContainerNode(Arrays.asList(contentContainer));
107
+        final ViewGroup result = (ViewGroup) createLayoutFactory().create(sideMenu);
108
+        assertThat(result.getChildAt(0)).isInstanceOf(Container.class);
109
+    }
110
+
111
+    @Test
112
+    public void hasLeftMenu() throws Exception {
113
+        when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
114
+        LayoutNode sideMenuLeft = createSideMenuLeftNode();
115
+        final LayoutNode sideMenu = createSideMenuContainerNode(Arrays.asList(sideMenuLeft));
116
+        final ViewGroup result = (ViewGroup) createLayoutFactory().create(sideMenu);
117
+        assertThat(result.getChildAt(0)).isInstanceOf(Container.class);
118
+    }
119
+
120
+    @Test
121
+    public void hasRightMenu() throws Exception {
122
+        when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
123
+        LayoutNode sideMenuRight = createSideMenuRightNode();
124
+        final LayoutNode sideMenu = createSideMenuContainerNode(Arrays.asList(sideMenuRight));
125
+        final ViewGroup result = (ViewGroup) createLayoutFactory().create(sideMenu);
126
+        assertThat(result.getChildAt(0)).isInstanceOf(Container.class);
127
+    }
128
+
129
+    @Test
130
+    public void returnsSingleTabContent() throws Exception {
131
+        BottomTabs bottomTabsMock = mock(BottomTabs.class);
132
+        when(bottomTabsMock.size()).thenReturn(0);
133
+
134
+        when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
135
+        final LayoutNode containerNode = createContainerStackNode(createContainerNode());
136
+        final LayoutNode tabNode = createBottomTabNode(containerNode);
137
+
138
+        final View result = createLayoutFactory(bottomTabsMock).create(tabNode);
139
+
140
+        verify(bottomTabsMock).add("#0");
141
+
142
+        assertThat(result).isInstanceOf(BottomTabsLayout.class);
143
+        ViewGroup containerStack = (ViewGroup) TestUtils.assertViewChildrenCount((BottomTabsLayout) result, 1).get(0);
144
+        Container container = (Container) TestUtils.assertViewChildrenCount(containerStack, 1).get(0);
145
+        View view = TestUtils.assertViewChildrenCount(container, 1).get(0);
146
+        assertThat(view).isEqualTo(mockView);
147
+    }
148
+
149
+    @Test
150
+    public void returnsTwoTabContent() throws Exception {
151
+        BottomTabs bottomTabsMock = mock(BottomTabs.class);
152
+        when(bottomTabsMock.size()).thenReturn(0, 1);
153
+
154
+        when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
155
+        final LayoutNode firstTabRootNode = createContainerStackNode(createContainerNode(NODE_ID, REACT_ROOT_VIEW_KEY));
156
+
157
+        when(reactRootViewCreator.create(eq(OTHER_NODE_ID), eq(OTHER_REACT_ROOT_VIEW_KEY))).thenReturn(otherMockView);
158
+        final LayoutNode secondTabRootNode = createContainerStackNode(createContainerNode(OTHER_NODE_ID, OTHER_REACT_ROOT_VIEW_KEY));
159
+
160
+        final LayoutNode tabNode = createBottomTabNode(firstTabRootNode, secondTabRootNode);
161
+
162
+        final View result = createLayoutFactory(bottomTabsMock).create(tabNode);
163
+
164
+        assertThat(result).isInstanceOf(BottomTabsLayout.class);
165
+        verify(bottomTabsMock).add(eq("#0"));
166
+        verify(bottomTabsMock).add(eq("#1"));
167
+    }
168
+
169
+    @Test
170
+    public void pushScreenToFirstBottomTab() {
171
+        BottomTabs bottomTabsMock = mock(BottomTabs.class);
172
+        when(bottomTabsMock.size()).thenReturn(0, 1);
173
+
174
+        when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
175
+        final LayoutNode firstTabContainerStack = createContainerStackNode(createContainerNode(NODE_ID, REACT_ROOT_VIEW_KEY));
176
+
177
+        final LayoutNode tabNode = createBottomTabNode(firstTabContainerStack);
178
+        final BottomTabsLayout bottomTabsContainer = (BottomTabsLayout) createLayoutFactory(bottomTabsMock).create(tabNode);
179
+        verify(bottomTabsMock).add(eq("#0"));
180
+
181
+        View pushedReactView = new View(activity);
182
+        when(reactRootViewCreator.create(eq("pushedReactViewId"), eq("pushedReactViewKey"))).thenReturn(pushedReactView);
183
+        View view = createLayoutFactory().create(createContainerNode("pushedReactViewId", "pushedReactViewKey"));
184
+        bottomTabsContainer.push(view);
185
+
186
+        ViewGroup containerStack = (ViewGroup) TestUtils.assertViewChildrenCount(bottomTabsContainer, 1).get(0);
187
+        ViewGroup container = (ViewGroup) TestUtils.assertViewChildrenCount(containerStack, 1).get(0);
188
+        View result = TestUtils.assertViewChildrenCount(container, 1).get(0);
189
+        assertThat(result).isEqualTo(pushedReactView);
190
+    }
191
+
192
+    @Test
193
+    public void popScreenFromFirstBottomTab() {
194
+        BottomTabs bottomTabsMock = mock(BottomTabs.class);
195
+        when(bottomTabsMock.size()).thenReturn(0, 1);
196
+
197
+        when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
198
+        final LayoutNode firstTabContainerStack = createContainerStackNode(createContainerNode(NODE_ID, REACT_ROOT_VIEW_KEY));
199
+
200
+        final LayoutNode tabNode = createBottomTabNode(firstTabContainerStack);
201
+        final BottomTabsLayout bottomTabsContainer = (BottomTabsLayout) createLayoutFactory(bottomTabsMock).create(tabNode);
202
+        verify(bottomTabsMock).add(eq("#0"));
203
+
204
+        pushContainer(bottomTabsContainer, "pushedReactViewId", "pushedReactViewKey", new View(activity));
205
+
206
+        bottomTabsContainer.pop();
207
+
208
+        ViewGroup containerStack = (ViewGroup) TestUtils.assertViewChildrenCount(bottomTabsContainer, 1).get(0);
209
+        ViewGroup container = (ViewGroup) TestUtils.assertViewChildrenCount(containerStack, 1).get(0);
210
+        View result = TestUtils.assertViewChildrenCount(container, 1).get(0);
211
+        assertThat(result).isEqualTo(mockView);
212
+    }
213
+
214
+    @Test
215
+    public void pushScreenToScreenStackLayout() throws Exception {
216
+        when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
217
+        final LayoutNode container = createContainerNode();
218
+        final LayoutNode stackNode = createContainerStackNode(container);
219
+        final ContainerStackLayout containerStackLayout = (ContainerStackLayout) createLayoutFactory().create(stackNode);
220
+
221
+        when(reactRootViewCreator.create(eq(OTHER_NODE_ID), eq(OTHER_REACT_ROOT_VIEW_KEY))).thenReturn(otherMockView);
222
+        final LayoutNode pushedContainer = createContainerNode(OTHER_NODE_ID, OTHER_REACT_ROOT_VIEW_KEY);
223
+        containerStackLayout.push(createLayoutFactory().create(pushedContainer));
224
+
225
+        ViewGroup result = (ViewGroup) TestUtils.assertViewChildrenCount(containerStackLayout, 1).get(0);
226
+        assertThat(result.getChildAt(0)).isEqualTo(otherMockView);
227
+    }
228
+
229
+    @Test
230
+    public void pushTwoScreensToStackLayout() throws Exception {
231
+        when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
232
+        final LayoutNode container = createContainerNode();
233
+        final LayoutNode stackNode = createContainerStackNode(container);
234
+        final ContainerStackLayout containerStackLayout = (ContainerStackLayout) createLayoutFactory().create(stackNode);
235
+
236
+        View first = new View(activity);
237
+        pushContainer(containerStackLayout, OTHER_NODE_ID, OTHER_REACT_ROOT_VIEW_KEY, first);
238
+
239
+        View second = new View(activity);
240
+        pushContainer(containerStackLayout, "secondPushedScreenId", "secondPushedScreenKey", second);
241
+
242
+        ViewGroup result = (ViewGroup) TestUtils.assertViewChildrenCount(containerStackLayout, 1).get(0);
243
+        assertThat(result.getChildAt(0)).isEqualTo(second);
244
+    }
245
+
246
+    @Test
247
+    public void popTwoScreensFromStackLayout() throws Exception {
248
+        when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
249
+        final LayoutNode container = createContainerNode();
250
+        final LayoutNode stackNode = createContainerStackNode(container);
251
+        final ContainerStackLayout containerStackLayout = (ContainerStackLayout) createLayoutFactory().create(stackNode);
252
+
253
+        pushContainer(containerStackLayout, OTHER_NODE_ID, OTHER_REACT_ROOT_VIEW_KEY, new View(activity));
254
+        pushContainer(containerStackLayout, "secondPushedScreenId", "secondPushedScreenKey", new View(activity));
255
+
256
+        containerStackLayout.pop();
257
+        containerStackLayout.pop();
258
+
259
+        ViewGroup result = (ViewGroup) TestUtils.assertViewChildrenCount(containerStackLayout, 1).get(0);
260
+        assertThat(result.getChildAt(0)).isEqualTo(mockView);
261
+    }
262
+
263
+    private void pushContainer(ContainerStackLayout containerStackLayout, String screenId, String reactRootViewKey, View rootView) {
264
+        when(reactRootViewCreator.create(eq(screenId), eq(reactRootViewKey))).thenReturn(rootView);
265
+        View pushedContainer = createLayoutFactory().create(createContainerNode(screenId, reactRootViewKey));
266
+        containerStackLayout.push(pushedContainer);
267
+    }
268
+
269
+    private void pushContainer(BottomTabsLayout containerStackLayout, String screenId, String reactRootViewKey, View rootView) {
270
+        when(reactRootViewCreator.create(eq(screenId), eq(reactRootViewKey))).thenReturn(rootView);
271
+        View pushedContainer = createLayoutFactory().create(createContainerNode(screenId, reactRootViewKey));
272
+        containerStackLayout.push(pushedContainer);
273
+    }
274
+
275
+    @Test
276
+    public void popScreenFromScreenStackLayout() {
277
+        when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
278
+        final LayoutNode container = createContainerNode();
279
+        final LayoutNode stackNode = createContainerStackNode(container);
280
+        final ContainerStackLayout containerStackLayout = (ContainerStackLayout) createLayoutFactory().create(stackNode);
281
+
282
+        when(reactRootViewCreator.create(eq(OTHER_NODE_ID), eq(OTHER_REACT_ROOT_VIEW_KEY))).thenReturn(otherMockView);
283
+        final LayoutNode pushedContainer = createContainerNode(OTHER_NODE_ID, OTHER_REACT_ROOT_VIEW_KEY);
284
+        containerStackLayout.push(createLayoutFactory().create(pushedContainer));
285
+
286
+        containerStackLayout.pop();
287
+        ViewGroup result = (ViewGroup) TestUtils.assertViewChildrenCount(containerStackLayout, 1).get(0);
288
+        assertThat(result.getChildAt(0)).isEqualTo(mockView);
289
+    }
290
+
291
+    @Test(expected = IllegalArgumentException.class)
292
+    public void throwsExceptionForUnknownType() throws Exception {
293
+        when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
294
+        final LayoutNode node = new LayoutNode(NODE_ID, "***unknownType***", Collections.<String, Object>emptyMap());
295
+
296
+        createLayoutFactory().create(node);
297
+    }
298
+
299
+    private LayoutFactory createLayoutFactory() {
300
+        return createLayoutFactory(null);
301
+    }
302
+
303
+    private LayoutFactory createLayoutFactory(BottomTabs bottomTabs) {
304
+        BottomTabsCreator bottomTabsCreator = null;
305
+        if (bottomTabs != null) {
306
+            bottomTabsCreator = mock(BottomTabsCreator.class);
307
+            when(bottomTabsCreator.create()).thenReturn(bottomTabs);
308
+        }
309
+
310
+        return new LayoutFactory(activity, reactRootViewCreator, bottomTabsCreator);
311
+    }
312
+
313
+    private LayoutNode createContainerNode() {
314
+        return createContainerNode(NODE_ID, REACT_ROOT_VIEW_KEY);
315
+    }
316
+
317
+    private LayoutNode createSideMenuLeftNode() {
318
+        List<LayoutNode> children = Arrays.asList(createContainerNode());
319
+        return new LayoutNode("SideMenuLeft", children);
320
+    }
321
+
322
+    private LayoutNode createSideMenuRightNode() {
323
+        List<LayoutNode> children = Arrays.asList(createContainerNode());
324
+        return new LayoutNode("SideMenuRight", children);
325
+    }
326
+
327
+    private LayoutNode createContainerNode(final String id, final String name) {
328
+        return new LayoutNode(id, "Container", new HashMap<String, Object>() {{
329
+            put("name", name);
330
+        }});
331
+    }
332
+
333
+    private LayoutNode createSideMenuContainerNode(List<LayoutNode> children) {
334
+        return new LayoutNode("SideMenuRoot", children);
335
+    }
336
+
337
+    private LayoutNode createContainerStackNode(LayoutNode... children) {
338
+        return new LayoutNode("ContainerStack", Arrays.asList(children));
339
+    }
340
+
341
+    private LayoutNode createBottomTabNode(LayoutNode... children) {
342
+        return new LayoutNode("BottomTabs", Arrays.asList(children));
343
+    }
344
+}

+ 27
- 0
android/app/src/test/java/com/reactnativenavigation/layout/TestUtils.java View File

@@ -0,0 +1,27 @@
1
+package com.reactnativenavigation.layout;
2
+
3
+import android.view.View;
4
+import android.view.ViewGroup;
5
+
6
+import java.util.ArrayList;
7
+import java.util.Arrays;
8
+import java.util.List;
9
+
10
+import static org.assertj.core.api.Java6Assertions.assertThat;
11
+
12
+public class TestUtils {
13
+    public static List<View> assertViewChildrenCount(ViewGroup view, int count) {
14
+        assertThat(view.getChildCount()).isEqualTo(count);
15
+
16
+        final List<View> children = new ArrayList<>(count);
17
+        for (int i = 0; i < count; i++) {
18
+            children.add(view.getChildAt(i));
19
+        }
20
+        return children;
21
+    }
22
+
23
+    public static void assertViewChildren(ViewGroup view, View... children) {
24
+        final List<View> childViews = assertViewChildrenCount(view, children.length);
25
+        assertThat(childViews).isEqualTo(Arrays.asList(children));
26
+    }
27
+}