Browse Source

android: fixed robolectric manifest troubles

Daniel Zlotin 7 years ago
parent
commit
8f7a7cd1c5

+ 1
- 0
AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/ApplicationLifecycleTest.java View File

@@ -89,6 +89,7 @@ public class ApplicationLifecycleTest {
89 89
         assertPushedScreenShown();
90 90
 
91 91
         uiDevice().pressHome();
92
+        uiDevice().waitForIdle();
92 93
         uiDevice().executeShellCommand("am kill " + PACKAGE_NAME);
93 94
 
94 95
         uiDevice().pressRecentApps();

+ 1
- 1
android/app/build.gradle View File

@@ -59,7 +59,7 @@ dependencies {
59 59
 
60 60
     // tests
61 61
     testCompile 'junit:junit:4.12'
62
-    testCompile 'org.robolectric:robolectric:3.2.2'
62
+    testCompile 'org.robolectric:robolectric:3.3'
63 63
     testCompile 'org.assertj:assertj-core:2.5.0'
64 64
     testCompile 'org.mockito:mockito-core:2.7.5'
65 65
 }

+ 0
- 2
android/app/src/main/java/com/reactnativenavigation/NavigationApplication.java View File

@@ -25,6 +25,4 @@ public abstract class NavigationApplication extends Application implements React
25 25
     }
26 26
 
27 27
     public abstract boolean isDebug();
28
-
29
-
30 28
 }

+ 5
- 0
android/app/src/test/AndroidManifest.xml View File

@@ -0,0 +1,5 @@
1
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+    package="com.reactnativenavigation">
3
+
4
+    <application android:theme="@style/Theme.AppCompat.Light"></application>
5
+</manifest>

+ 0
- 6
android/app/src/test/RoboManifest.xml View File

@@ -1,6 +0,0 @@
1
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
-          package="com.reactnativenavigation">
3
-    <application android:theme="@style/Theme.AppCompat.Light">
4
-        <activity android:name=".RoboActivity" android:theme="@style/Theme.AppCompat.Light"/>
5
-    </application>
6
-</manifest>

+ 10
- 0
android/app/src/test/java/com/reactnativenavigation/BaseTest.java View File

@@ -0,0 +1,10 @@
1
+package com.reactnativenavigation;
2
+
3
+import org.junit.runner.RunWith;
4
+import org.robolectric.RobolectricTestRunner;
5
+import org.robolectric.annotation.Config;
6
+
7
+@RunWith(RobolectricTestRunner.class)
8
+@Config(sdk = 25, constants = BuildConfig.class, manifest = "/../../../../../src/test/AndroidManifest.xml")
9
+public abstract class BaseTest {
10
+}

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

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

+ 9
- 4
android/app/src/test/java/com/reactnativenavigation/EnvironmentTest.java View File

@@ -6,13 +6,12 @@ import android.support.v7.app.AppCompatActivity;
6 6
 import com.facebook.react.common.ReactConstants;
7 7
 
8 8
 import org.junit.Test;
9
-import org.junit.runner.RunWith;
10
-import org.robolectric.RobolectricTestRunner;
9
+import org.robolectric.Robolectric;
10
+import org.robolectric.RuntimeEnvironment;
11 11
 
12 12
 import static org.assertj.core.api.Java6Assertions.assertThat;
13 13
 
14
-@RunWith(RobolectricTestRunner.class)
15
-public class EnvironmentTest {
14
+public class EnvironmentTest extends BaseTest {
16 15
     @Test
17 16
     public void assertJ() {
18 17
         assertThat(1 + 2).isEqualTo(3).isGreaterThan(2).isLessThan(4).isNotNegative().isPositive().isNotZero();
@@ -37,4 +36,10 @@ public class EnvironmentTest {
37 36
     public void androidR() {
38 37
         assertThat(R.string.app_name).isNotZero();
39 38
     }
39
+
40
+    @Test
41
+    public void ableToLoadApplication() throws Exception {
42
+        assertThat(RuntimeEnvironment.application).isNotNull();
43
+        assertThat(Robolectric.setupActivity(NavigationActivity.class)).isNotNull();
44
+    }
40 45
 }

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

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

+ 14
- 0
android/app/src/test/java/com/reactnativenavigation/NavigationActivityTest.java View File

@@ -0,0 +1,14 @@
1
+package com.reactnativenavigation;
2
+
3
+import org.junit.Test;
4
+import org.robolectric.Robolectric;
5
+
6
+import static org.assertj.core.api.Java6Assertions.assertThat;
7
+
8
+public class NavigationActivityTest extends BaseTest {
9
+    @Test
10
+    public void showsSplashView() throws Exception {
11
+        NavigationActivity activity = Robolectric.setupActivity(NavigationActivity.class);
12
+        assertThat(activity).isNotNull();
13
+    }
14
+}

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

@@ -1,27 +0,0 @@
1
-package com.reactnativenavigation;
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
-}

+ 0
- 2
android/app/src/test/resources/robolectric.properties View File

@@ -1,2 +0,0 @@
1
-manifest: src/main/AndroidManifest.xml
2
-sdk: 23

+ 13
- 3
android/prepare-robolectric.gradle View File

@@ -1,11 +1,21 @@
1
-def robolectricDependenciesFolder = new File(rootProject.buildDir, "robolectric-3.2.2-dependencies")
1
+def robolectricDependenciesFolder = new File(rootProject.buildDir, "robolectric-3.3-dependencies")
2 2
 
3 3
 configurations.create('robolectricRuntime')
4 4
 
5 5
 dependencies {
6 6
     testCompile "org.khronos:opengl-api:gl1.1-android-2.1_r1"
7
-    robolectricRuntime "org.robolectric:android-all:6.0.1_r3-robolectric-0"
8
-    robolectricRuntime "org.robolectric:shadows-core:3.2.2"
7
+
8
+    // robolectricRuntime "org.robolectric:android-all:6.0.1_r3-robolectric-0"
9
+    robolectricRuntime "org.robolectric:android-all:7.1.0_r7-robolectric-0"
10
+    robolectricRuntime "org.robolectric:shadows-core:3.3"
11
+    robolectricRuntime "org.robolectric:robolectric-utils:3.3"
12
+    robolectricRuntime "org.robolectric:robolectric-resources:3.3"
13
+    robolectricRuntime "org.robolectric:robolectric-processor:3.3"
14
+    robolectricRuntime "org.robolectric:robolectric-sandbox:3.3"
15
+    robolectricRuntime "org.robolectric:shadows-support-v4:3.3"
16
+    robolectricRuntime "org.robolectric:shadows-multidex:3.3"
17
+    robolectricRuntime "org.robolectric:shadows-play-services:3.3"
18
+    robolectricRuntime "org.robolectric:shadows-maps:3.3"
9 19
 }
10 20
 
11 21
 rootProject.task(type: Copy, overwrite: true, "downloadRobolectricDependencies") {