Bläddra i källkod

Fix Android unit tests after merging BottomTabs fix

BottomTabs are all mounted when created, selecting a tab only changes visibility
Guy Carmeli 6 år sedan
förälder
incheckning
a23db66243

+ 17
- 4
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/BottomTabsControllerTest.java Visa fil

@@ -2,6 +2,7 @@ package com.reactnativenavigation.viewcontrollers;
2 2
 
3 3
 import android.app.Activity;
4 4
 import android.support.annotation.NonNull;
5
+import android.view.View;
5 6
 import android.view.ViewGroup;
6 7
 import android.widget.RelativeLayout;
7 8
 
@@ -103,20 +104,32 @@ public class BottomTabsControllerTest extends BaseTest {
103 104
     }
104 105
 
105 106
     @Test
106
-    public void setTabs_AddAllViews() {
107
+    public void setTabs_allChildViewsAreAttachedToHierarchy() {
107 108
         uut.onViewAppeared();
108
-        assertThat(uut.getView().getChildCount()).isEqualTo(2);
109
-        assertThat(((ViewController) ((List) uut.getChildControllers()).get(0)).getView().getParent()).isNotNull();
109
+        assertThat(uut.getView().getChildCount()).isEqualTo(6);
110
+        for (ViewController child : uut.getChildControllers()) {
111
+            assertThat(child.getView().getParent()).isNotNull();
112
+        }
113
+    }
114
+
115
+    @Test
116
+    public void setTabs_firstChildIsVisibleOtherAreGone() {
117
+        uut.onViewAppeared();
118
+        for (int i = 0; i < uut.getChildControllers().size(); i++) {
119
+            assertThat(uut.getView().getChildAt(i).getVisibility()).isEqualTo(i == 0 ? View.VISIBLE : View.GONE);
120
+        }
110 121
     }
111 122
 
112 123
     @Test
113 124
     public void onTabSelected() {
114 125
         assertThat(uut.getSelectedIndex()).isZero();
126
+        assertThat(((ViewController) ((List) uut.getChildControllers()).get(0)).getView().getVisibility()).isEqualTo(View.VISIBLE);
115 127
 
116 128
         uut.onTabSelected(3, false);
117 129
 
118 130
         assertThat(uut.getSelectedIndex()).isEqualTo(3);
119
-        assertThat(((ViewController) ((List) uut.getChildControllers()).get(0)).getView().getParent()).isNull();
131
+        assertThat(((ViewController) ((List) uut.getChildControllers()).get(0)).getView().getVisibility()).isEqualTo(View.GONE);
132
+        assertThat(((ViewController) ((List) uut.getChildControllers()).get(3)).getView().getVisibility()).isEqualTo(View.VISIBLE);
120 133
         verify(eventEmitter, times(1)).emitBottomTabSelected(0, 3);
121 134
     }
122 135