Browse Source

root view creator

Daniel Zlotin 7 years ago
parent
commit
1e45775289

+ 4
- 25
lib/android/app/src/main/java/com/reactnativenavigation/controllers/CommandsHandler.java View File

@@ -1,15 +1,12 @@
1 1
 package com.reactnativenavigation.controllers;
2 2
 
3
-import android.os.Bundle;
4 3
 import android.view.View;
5 4
 
6
-import com.facebook.react.ReactRootView;
7 5
 import com.reactnativenavigation.NavigationActivity;
8
-import com.reactnativenavigation.NavigationApplication;
9 6
 import com.reactnativenavigation.layout.LayoutFactory;
10 7
 import com.reactnativenavigation.layout.LayoutNode;
11 8
 import com.reactnativenavigation.layout.StackLayout;
12
-import com.reactnativenavigation.layout.bottomtabs.BottomTabsCreator;
9
+import com.reactnativenavigation.react.NavigationReactRootViewCreator;
13 10
 
14 11
 import org.json.JSONObject;
15 12
 
@@ -18,34 +15,16 @@ public class CommandsHandler {
18 15
 	public void setRoot(final NavigationActivity activity, final JSONObject layoutTree) {
19 16
 		final LayoutNode layoutTreeRoot = LayoutNode.parse(layoutTree);
20 17
 		LayoutFactory factory =
21
-				new LayoutFactory(activity, new LayoutFactory.ReactRootViewCreator() {
22
-					@Override
23
-					public View create(String id, String name) {
24
-						ReactRootView rootView = new ReactRootView(activity);
25
-						Bundle opts = new Bundle();
26
-						opts.putString("id", id);
27
-						rootView.startReactApplication(NavigationApplication.instance.getReactNativeHost().getReactInstanceManager(), name, opts);
28
-						return rootView;
29
-					}
30
-				}, new BottomTabsCreator());
18
+				new LayoutFactory(activity, new NavigationReactRootViewCreator());
31 19
 
32 20
 		final View rootView = factory.create(layoutTreeRoot);
33 21
 		activity.setContentView(rootView);
34 22
 	}
35 23
 
36 24
 	public void push(final NavigationActivity activity, String onContainerId, JSONObject layoutTree) {
37
-		LayoutFactory factory =
38
-				new LayoutFactory(activity, new LayoutFactory.ReactRootViewCreator() {
39
-					@Override
40
-					public View create(String id, String name) {
41
-						ReactRootView rootView = new ReactRootView(activity);
42
-						Bundle opts = new Bundle();
43
-						opts.putString("id", id);
44
-						rootView.startReactApplication(NavigationApplication.instance.getReactNativeHost().getReactInstanceManager(), name, opts);
45
-						return rootView;
46
-					}
47
-				}, new BottomTabsCreator());
48 25
 		final LayoutNode layoutNode = LayoutNode.parse(layoutTree);
26
+		LayoutFactory factory =
27
+				new LayoutFactory(activity, new NavigationReactRootViewCreator());
49 28
 		final View rootView = factory.create(layoutNode);
50 29
 		((StackLayout) activity.getContentView()).push(rootView);
51 30
 	}

+ 5
- 9
lib/android/app/src/main/java/com/reactnativenavigation/layout/Container.java View File

@@ -1,20 +1,18 @@
1 1
 package com.reactnativenavigation.layout;
2 2
 
3
-import android.content.Context;
4
-import android.util.Log;
3
+import android.app.Activity;
5 4
 import android.widget.FrameLayout;
6 5
 
7 6
 import com.reactnativenavigation.NavigationApplication;
8 7
 import com.reactnativenavigation.react.NavigationEventEmitter;
9 8
 
10 9
 public class Container extends FrameLayout {
11
-	private static final String TAG = "Container";
12
-	private String id;
10
+	private final String id;
13 11
 
14
-	public Container(Context context, LayoutFactory.ReactRootViewCreator reactRootViewCreator, String id, String name) {
15
-		super(context);
12
+	public Container(Activity activity, LayoutFactory.ReactRootViewCreator reactRootViewCreator, String id, String name) {
13
+		super(activity);
16 14
 		this.id = id;
17
-		addView(reactRootViewCreator.create(id, name));
15
+		addView(reactRootViewCreator.create(activity, id, name));
18 16
 	}
19 17
 
20 18
 	public String getContainerId() {
@@ -23,7 +21,6 @@ public class Container extends FrameLayout {
23 21
 
24 22
 	//    @Override
25 23
 //    protected void onAttachedToWindow() {
26
-//        Log.d(TAG, "onAttachedToWindow: " + id);
27 24
 //        super.onAttachedToWindow();
28 25
 //        NavigationEventEmitter.emit(NavigationApplication.instance.getReactNativeHost().getReactInstanceManager().getCurrentReactContext())
29 26
 //                .containerStart(id);
@@ -31,7 +28,6 @@ public class Container extends FrameLayout {
31 28
 
32 29
 	@Override
33 30
 	protected void onDetachedFromWindow() {
34
-		Log.d(TAG, "onDetachedFromWindow: " + id);
35 31
 		super.onDetachedFromWindow();
36 32
 		NavigationEventEmitter.emit(NavigationApplication.instance.getReactNativeHost().getReactInstanceManager().getCurrentReactContext())
37 33
 				.containerStop(id);

+ 3
- 3
lib/android/app/src/main/java/com/reactnativenavigation/layout/LayoutFactory.java View File

@@ -15,17 +15,17 @@ import java.util.List;
15 15
 public class LayoutFactory {
16 16
 
17 17
 	public interface ReactRootViewCreator {
18
-		View create(String id, String name);
18
+		View create(Activity activity, String id, String name);
19 19
 	}
20 20
 
21 21
 	private final Activity activity;
22 22
 	private final ReactRootViewCreator reactRootViewCreator;
23 23
 	private final BottomTabsCreator bottomTabsCreator; // TODO: revisit this, may not be needed
24 24
 
25
-	public LayoutFactory(Activity activity, ReactRootViewCreator reactRootViewCreator, BottomTabsCreator bottomTabsCreator) {
25
+	public LayoutFactory(Activity activity, ReactRootViewCreator reactRootViewCreator) {
26 26
 		this.activity = activity;
27 27
 		this.reactRootViewCreator = reactRootViewCreator;
28
-		this.bottomTabsCreator = bottomTabsCreator;
28
+		this.bottomTabsCreator = new BottomTabsCreator();
29 29
 	}
30 30
 
31 31
 	public View create(LayoutNode node) {

+ 20
- 0
lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationReactRootViewCreator.java View File

@@ -0,0 +1,20 @@
1
+package com.reactnativenavigation.react;
2
+
3
+import android.app.Activity;
4
+import android.os.Bundle;
5
+import android.view.View;
6
+
7
+import com.facebook.react.ReactRootView;
8
+import com.reactnativenavigation.NavigationApplication;
9
+import com.reactnativenavigation.layout.LayoutFactory.ReactRootViewCreator;
10
+
11
+public class NavigationReactRootViewCreator implements ReactRootViewCreator {
12
+	@Override
13
+	public View create(Activity activity, final String id, final String name) {
14
+		ReactRootView rootView = new ReactRootView(activity);
15
+		Bundle opts = new Bundle();
16
+		opts.putString("id", id);
17
+		rootView.startReactApplication(NavigationApplication.instance.getReactNativeHost().getReactInstanceManager(), name, opts);
18
+		return rootView;
19
+	}
20
+}

+ 1
- 1
lib/android/app/src/test/java/com/reactnativenavigation/controllers/CommandsHandlerTest.java View File

@@ -13,7 +13,7 @@ import static org.assertj.core.api.Java6Assertions.assertThat;
13 13
 public class CommandsHandlerTest extends BaseTest {
14 14
 
15 15
 	@Test
16
-	public void setRootCreatesTheLayout_SetsOnActivity() throws Exception {
16
+	public void setRootCreatesTheLayout_SetContentView() throws Exception {
17 17
 		CommandsHandler uut = new CommandsHandler();
18 18
 		JSONObject json = new JSONObject("{" +
19 19
 				"id: containerId123," +

+ 315
- 338
lib/android/app/src/test/java/com/reactnativenavigation/layout/LayoutFactoryTest.java View File

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

+ 42
- 0
lib/android/app/src/test/java/com/reactnativenavigation/react/NavigationReactRootViewCreatorTest.java View File

@@ -0,0 +1,42 @@
1
+package com.reactnativenavigation.react;
2
+
3
+import android.app.Activity;
4
+import android.os.Bundle;
5
+import android.view.View;
6
+
7
+import com.facebook.react.ReactRootView;
8
+import com.reactnativenavigation.BaseTest;
9
+
10
+import org.assertj.core.api.Condition;
11
+import org.junit.Test;
12
+import org.robolectric.Robolectric;
13
+
14
+import java.lang.reflect.Method;
15
+
16
+import static org.assertj.core.api.Java6Assertions.assertThat;
17
+
18
+public class NavigationReactRootViewCreatorTest extends BaseTest {
19
+	@Test
20
+	public void createsReactRootView() throws Exception {
21
+		NavigationReactRootViewCreator uut = new NavigationReactRootViewCreator();
22
+		View result = uut.create(Robolectric.buildActivity(Activity.class).get(), "the container id", "the container name");
23
+		assertThat(result).isNotNull().isInstanceOf(ReactRootView.class);
24
+	}
25
+
26
+	@Test
27
+	public void startReactContainer() throws Exception {
28
+		NavigationReactRootViewCreator uut = new NavigationReactRootViewCreator();
29
+		ReactRootView result = (ReactRootView) uut.create(Robolectric.buildActivity(Activity.class).get(), "the container id", "the container name");
30
+		Method getJSModuleName = ReactRootView.class.getDeclaredMethod("getJSModuleName");
31
+		Method getLaunchOptions = ReactRootView.class.getDeclaredMethod("getLaunchOptions");
32
+		getJSModuleName.setAccessible(true);
33
+		getLaunchOptions.setAccessible(true);
34
+		assertThat(getJSModuleName.invoke(result)).isEqualTo("the container name");
35
+		assertThat(getLaunchOptions.invoke(result)).isNotNull().isInstanceOf(Bundle.class).has(new Condition<Object>() {
36
+			@Override
37
+			public boolean matches(final Object value) {
38
+				return ((Bundle) value).getString("id").equals("the container id");
39
+			}
40
+		});
41
+	}
42
+}