Quellcode durchsuchen

commandsHandler test

Daniel Zlotin vor 7 Jahren
Ursprung
Commit
c9a489a0f1

+ 3
- 9
lib/android/app/src/main/java/com/reactnativenavigation/controllers/CommandsHandler.java Datei anzeigen

@@ -7,16 +7,16 @@ import com.facebook.react.ReactRootView;
7 7
 import com.reactnativenavigation.NavigationActivity;
8 8
 import com.reactnativenavigation.NavigationApplication;
9 9
 import com.reactnativenavigation.layout.LayoutFactory;
10
+import com.reactnativenavigation.layout.LayoutNode;
10 11
 import com.reactnativenavigation.layout.StackLayout;
11 12
 import com.reactnativenavigation.layout.bottomtabs.BottomTabsCreator;
12
-import com.reactnativenavigation.layout.parse.LayoutNode;
13
-import com.reactnativenavigation.utils.UiThread;
14 13
 
15 14
 import org.json.JSONObject;
16 15
 
17 16
 public class CommandsHandler {
18 17
 
19 18
 	public void setRoot(final NavigationActivity activity, final JSONObject layoutTree) {
19
+		final LayoutNode layoutTreeRoot = LayoutNode.parse(layoutTree);
20 20
 		LayoutFactory factory =
21 21
 				new LayoutFactory(activity, new LayoutFactory.ReactRootViewCreator() {
22 22
 					@Override
@@ -29,7 +29,6 @@ public class CommandsHandler {
29 29
 					}
30 30
 				}, new BottomTabsCreator());
31 31
 
32
-		final LayoutNode layoutTreeRoot = LayoutNode.parse(layoutTree);
33 32
 		final View rootView = factory.create(layoutTreeRoot);
34 33
 		activity.setContentView(rootView);
35 34
 	}
@@ -52,11 +51,6 @@ public class CommandsHandler {
52 51
 	}
53 52
 
54 53
 	public void pop(final NavigationActivity activity, String onContainerId) {
55
-		UiThread.post(new Runnable() {
56
-			@Override
57
-			public void run() {
58
-				((StackLayout) activity.getContentView()).pop();
59
-			}
60
-		});
54
+		((StackLayout) activity.getContentView()).pop();
61 55
 	}
62 56
 }

+ 4
- 1
lib/android/app/src/main/java/com/reactnativenavigation/layout/Container.java Datei anzeigen

@@ -15,10 +15,13 @@ public class Container extends FrameLayout {
15 15
 		super(context);
16 16
 		this.id = id;
17 17
 		addView(reactRootViewCreator.create(id, name));
18
+	}
18 19
 
20
+	public String getContainerId() {
21
+		return id;
19 22
 	}
20 23
 
21
-//    @Override
24
+	//    @Override
22 25
 //    protected void onAttachedToWindow() {
23 26
 //        Log.d(TAG, "onAttachedToWindow: " + id);
24 27
 //        super.onAttachedToWindow();

+ 0
- 1
lib/android/app/src/main/java/com/reactnativenavigation/layout/LayoutFactory.java Datei anzeigen

@@ -8,7 +8,6 @@ import android.view.ViewGroup.LayoutParams;
8 8
 
9 9
 import com.reactnativenavigation.layout.bottomtabs.BottomTabsCreator;
10 10
 import com.reactnativenavigation.layout.bottomtabs.BottomTabsLayout;
11
-import com.reactnativenavigation.layout.parse.LayoutNode;
12 11
 import com.reactnativenavigation.utils.CompatUtils;
13 12
 
14 13
 import java.util.List;

lib/android/app/src/main/java/com/reactnativenavigation/layout/parse/LayoutNode.java → lib/android/app/src/main/java/com/reactnativenavigation/layout/LayoutNode.java Datei anzeigen

@@ -1,4 +1,4 @@
1
-package com.reactnativenavigation.layout.parse;
1
+package com.reactnativenavigation.layout;
2 2
 
3 3
 import android.support.annotation.NonNull;
4 4
 

+ 8
- 0
lib/android/app/src/test/java/com/reactnativenavigation/BaseTest.java Datei anzeigen

@@ -1,5 +1,8 @@
1 1
 package com.reactnativenavigation;
2 2
 
3
+import com.facebook.react.uimanager.DisplayMetricsHolder;
4
+
5
+import org.junit.Before;
3 6
 import org.junit.runner.RunWith;
4 7
 import org.robolectric.RobolectricTestRunner;
5 8
 import org.robolectric.annotation.Config;
@@ -7,4 +10,9 @@ import org.robolectric.annotation.Config;
7 10
 @RunWith(RobolectricTestRunner.class)
8 11
 @Config(sdk = 25, constants = BuildConfig.class, manifest = "/../../../../../src/test/AndroidManifest.xml")
9 12
 public abstract class BaseTest {
13
+
14
+	@Before
15
+	public void beforeEach() {
16
+		DisplayMetricsHolder.initDisplayMetrics(NavigationApplication.instance);
17
+	}
10 18
 }

+ 28
- 0
lib/android/app/src/test/java/com/reactnativenavigation/controllers/CommandsHandlerTest.java Datei anzeigen

@@ -0,0 +1,28 @@
1
+package com.reactnativenavigation.controllers;
2
+
3
+import com.reactnativenavigation.BaseTest;
4
+import com.reactnativenavigation.NavigationActivity;
5
+import com.reactnativenavigation.layout.Container;
6
+
7
+import org.json.JSONObject;
8
+import org.junit.Test;
9
+import org.robolectric.Robolectric;
10
+
11
+import static org.assertj.core.api.Java6Assertions.assertThat;
12
+
13
+public class CommandsHandlerTest extends BaseTest {
14
+
15
+	@Test
16
+	public void setRootCreatesTheLayout_SetsOnActivity() throws Exception {
17
+		CommandsHandler uut = new CommandsHandler();
18
+		JSONObject json = new JSONObject("{" +
19
+				"id: containerId123," +
20
+				"type: Container" +
21
+				"}");
22
+		NavigationActivity activity = Robolectric.setupActivity(NavigationActivity.class);
23
+		uut.setRoot(activity, json);
24
+
25
+		assertThat(activity.getContentView()).isInstanceOf(Container.class);
26
+		assertThat(((Container) activity.getContentView()).getContainerId()).isEqualTo("containerId123");
27
+	}
28
+}

+ 0
- 1
lib/android/app/src/test/java/com/reactnativenavigation/layout/LayoutFactoryTest.java Datei anzeigen

@@ -9,7 +9,6 @@ import com.reactnativenavigation.BaseTest;
9 9
 import com.reactnativenavigation.layout.bottomtabs.BottomTabs;
10 10
 import com.reactnativenavigation.layout.bottomtabs.BottomTabsCreator;
11 11
 import com.reactnativenavigation.layout.bottomtabs.BottomTabsLayout;
12
-import com.reactnativenavigation.layout.parse.LayoutNode;
13 12
 
14 13
 import org.json.JSONException;
15 14
 import org.json.JSONObject;

lib/android/app/src/test/java/com/reactnativenavigation/layout/parse/LayoutNodeTest.java → lib/android/app/src/test/java/com/reactnativenavigation/layout/LayoutNodeTest.java Datei anzeigen

@@ -1,6 +1,7 @@
1
-package com.reactnativenavigation.layout.parse;
1
+package com.reactnativenavigation.layout;
2 2
 
3 3
 import com.reactnativenavigation.BaseTest;
4
+import com.reactnativenavigation.layout.LayoutNode;
4 5
 
5 6
 import org.json.JSONObject;
6 7
 import org.junit.Test;