Pārlūkot izejas kodu

fix android unittests

Daniel Zlotin 7 gadus atpakaļ
vecāks
revīzija
74f377fca7

+ 61
- 57
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ComponentViewController.java Parādīt failu

@@ -13,7 +13,7 @@ public class ComponentViewController extends ViewController implements Navigatio
13 13
     public interface ReactViewCreator {
14 14
 
15 15
         IReactView create(Activity activity, String componentId, String componentName);
16
-	}
16
+    }
17 17
 
18 18
     public interface IReactView {
19 19
 
@@ -23,75 +23,79 @@ public class ComponentViewController extends ViewController implements Navigatio
23 23
 
24 24
         void destroy();
25 25
 
26
-		void sendComponentStart();
26
+        void sendComponentStart();
27 27
 
28
-		void sendComponentStop();
28
+        void sendComponentStop();
29 29
 
30 30
         void sendOnNavigationButtonPressed(String buttonId);
31 31
     }
32 32
 
33
-	private final String componentName;
34
-
35
-	private final ReactViewCreator viewCreator;
36
-	private NavigationOptions options;
37
-	private ReactComponent component;
38
-
39
-	public ComponentViewController(final Activity activity,
40
-								   final String id,
41
-								   final String componentName,
42
-								   final ReactViewCreator viewCreator,
43
-								   final NavigationOptions initialNavigationOptions) {
44
-		super(activity, id);
45
-		this.componentName = componentName;
46
-		this.viewCreator = viewCreator;
47
-		this.options = initialNavigationOptions;
48
-	}
33
+    private final String componentName;
34
+
35
+    private final ReactViewCreator viewCreator;
36
+    private NavigationOptions options;
37
+    private ReactComponent component;
38
+
39
+    public ComponentViewController(final Activity activity,
40
+                                   final String id,
41
+                                   final String componentName,
42
+                                   final ReactViewCreator viewCreator,
43
+                                   final NavigationOptions initialNavigationOptions) {
44
+        super(activity, id);
45
+        this.componentName = componentName;
46
+        this.viewCreator = viewCreator;
47
+        this.options = initialNavigationOptions;
48
+    }
49 49
 
50 50
     @RestrictTo(RestrictTo.Scope.TESTS)
51 51
     TopBar getTopBar() {
52 52
         return component.getTopBar();
53 53
     }
54 54
 
55
-	@Override
56
-	public void destroy() {
57
-		super.destroy();
58
-		if (component != null) component.destroy();
59
-		component = null;
60
-	}
61
-
62
-	@Override
63
-	public void onViewAppeared() {
64
-		super.onViewAppeared();
65
-		ensureViewIsCreated();
66
-		component.applyOptions(options);
67
-		component.sendComponentStart();
68
-	}
69
-
70
-	@Override
71
-	public void onViewDisappear() {
72
-		super.onViewDisappear();
73
-		component.sendComponentStop();
74
-	}
75
-
76
-	@Override
77
-	protected boolean isViewShown() {
78
-		return super.isViewShown() && component.isReady();
79
-	}
80
-
81
-	@NonNull
82
-	@Override
83
-	protected View createView() {
84
-		component = (ReactComponent) viewCreator.create(getActivity(), getId(), componentName);
55
+    @Override
56
+    public void destroy() {
57
+        super.destroy();
58
+        if (component != null) component.destroy();
59
+        component = null;
60
+    }
61
+
62
+    @Override
63
+    public void onViewAppeared() {
64
+        super.onViewAppeared();
65
+        ensureViewIsCreated();
66
+        component.applyOptions(options);
67
+        component.sendComponentStart();
68
+    }
69
+
70
+    @Override
71
+    public void onViewDisappear() {
72
+        super.onViewDisappear();
73
+        component.sendComponentStop();
74
+    }
75
+
76
+    @Override
77
+    protected boolean isViewShown() {
78
+        return super.isViewShown() && component.isReady();
79
+    }
80
+
81
+    @NonNull
82
+    @Override
83
+    protected View createView() {
84
+        component = (ReactComponent) viewCreator.create(getActivity(), getId(), componentName);
85 85
         return component.asView();
86
-	}
86
+    }
87 87
 
88
-	@Override
89
-	public void mergeNavigationOptions(NavigationOptions options) {
90
-		this.options.mergeWith(options);
88
+    @Override
89
+    public void mergeNavigationOptions(NavigationOptions options) {
90
+        this.options.mergeWith(options);
91 91
         component.applyOptions(options);
92
-	}
92
+    }
93
+
94
+    NavigationOptions getOptions() {
95
+        return options;
96
+    }
93 97
 
94
-	NavigationOptions getOptions() {
95
-		return options;
96
-	}
98
+    ReactComponent getComponent() {
99
+        return component;
100
+    }
97 101
 }

+ 12
- 16
lib/android/app/src/main/java/com/reactnativenavigation/views/ComponentLayout.java Parādīt failu

@@ -1,20 +1,16 @@
1 1
 package com.reactnativenavigation.views;
2 2
 
3
-import android.annotation.SuppressLint;
4
-import android.content.Context;
5
-import android.os.Build;
6
-import android.support.annotation.RestrictTo;
7
-import android.view.View;
8
-import android.view.ViewGroup;
9
-import android.widget.RelativeLayout;
10
-
11
-import com.facebook.react.uimanager.events.EventDispatcher;
12
-import com.reactnativenavigation.parse.NavigationOptions;
13
-import com.reactnativenavigation.presentation.OptionsPresenter;
14
-import com.reactnativenavigation.viewcontrollers.ComponentViewController.IReactView;
15
-
16
-import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
17
-import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
3
+import android.annotation.*;
4
+import android.content.*;
5
+import android.view.*;
6
+import android.widget.*;
7
+
8
+import com.facebook.react.uimanager.events.*;
9
+import com.reactnativenavigation.parse.*;
10
+import com.reactnativenavigation.presentation.*;
11
+import com.reactnativenavigation.viewcontrollers.ComponentViewController.*;
12
+
13
+import static android.view.ViewGroup.LayoutParams.*;
18 14
 
19 15
 @SuppressLint("ViewConstructor")
20 16
 public class ComponentLayout extends RelativeLayout implements ReactComponent {
@@ -25,7 +21,7 @@ public class ComponentLayout extends RelativeLayout implements ReactComponent {
25 21
 
26 22
 	public ComponentLayout(Context context, IReactView reactView, EventDispatcher eventDispatcher) {
27 23
 		super(context);
28
-		this.topBar = new TopBar(context, this);
24
+		this.topBar = new TopBar(context, this, eventDispatcher);
29 25
 		this.reactView = reactView;
30 26
         optionsPresenter = new OptionsPresenter(this);
31 27
         initViews();

+ 6
- 5
lib/android/app/src/main/java/com/reactnativenavigation/views/ComponentViewCreator.java Parādīt failu

@@ -1,10 +1,11 @@
1 1
 package com.reactnativenavigation.views;
2 2
 
3
-import android.app.Activity;
3
+import android.app.*;
4 4
 
5
-import com.facebook.react.ReactInstanceManager;
6
-import com.reactnativenavigation.react.ReactComponentViewCreator;
7
-import com.reactnativenavigation.viewcontrollers.ComponentViewController;
5
+import com.facebook.react.*;
6
+import com.facebook.react.uimanager.*;
7
+import com.reactnativenavigation.react.*;
8
+import com.reactnativenavigation.viewcontrollers.*;
8 9
 
9 10
 public class ComponentViewCreator implements ComponentViewController.ReactViewCreator {
10 11
 
@@ -17,6 +18,6 @@ public class ComponentViewCreator implements ComponentViewController.ReactViewCr
17 18
 	@Override
18 19
 	public ComponentViewController.IReactView create(Activity activity, String componentId, String componentName) {
19 20
         ComponentViewController.IReactView reactView = new ReactComponentViewCreator(instanceManager).create(activity, componentId, componentName);
20
-        return new ComponentLayout(activity, reactView);
21
+        return new ComponentLayout(activity, reactView, instanceManager.getCurrentReactContext().getNativeModule(UIManagerModule.class).getEventDispatcher());
21 22
 	}
22 23
 }

+ 28
- 31
lib/android/app/src/main/java/com/reactnativenavigation/views/TopBar.java Parādīt failu

@@ -1,43 +1,40 @@
1 1
 package com.reactnativenavigation.views;
2 2
 
3
-import android.annotation.SuppressLint;
4
-import android.content.Context;
5
-import android.graphics.Typeface;
6
-import android.support.annotation.ColorInt;
7
-import android.support.annotation.Nullable;
8
-import android.support.design.widget.AppBarLayout;
3
+import android.annotation.*;
4
+import android.content.*;
5
+import android.graphics.*;
6
+import android.support.annotation.*;
7
+import android.support.design.widget.*;
9 8
 import android.support.v7.widget.Toolbar;
10
-import android.util.Log;
11
-import android.view.Menu;
12
-import android.view.View;
13
-import android.view.ViewGroup;
14
-import android.widget.TextView;
15
-
16
-import com.facebook.react.uimanager.events.EventDispatcher;
17
-import com.reactnativenavigation.anim.TopBarAnimator;
18
-import com.reactnativenavigation.anim.TopBarCollapseBehavior;
9
+import android.util.*;
10
+import android.view.*;
11
+import android.widget.*;
12
+
13
+import com.facebook.react.uimanager.events.*;
14
+import com.reactnativenavigation.anim.*;
19 15
 import com.reactnativenavigation.parse.Button;
20 16
 import com.reactnativenavigation.parse.Color;
21
-import com.reactnativenavigation.parse.NavigationOptions;
17
+import com.reactnativenavigation.parse.*;
22 18
 import com.reactnativenavigation.parse.Number;
23
-import com.reactnativenavigation.viewcontrollers.toptabs.TopTabsViewPager;
24
-import com.reactnativenavigation.parse.Color;
19
+import com.reactnativenavigation.viewcontrollers.toptabs.*;
25 20
 
26
-import java.util.ArrayList;
21
+import java.util.*;
27 22
 
28 23
 @SuppressLint("ViewConstructor")
29 24
 public class TopBar extends AppBarLayout {
30
-	private final Toolbar titleBar;
25
+    private final Toolbar titleBar;
26
+    private final TopBarCollapseBehavior collapsingBehavior;
27
+    private final TopBarAnimator animator;
31 28
     private Component component;
32 29
     private TopTabs topTabs;
33 30
 
34
-    public TopBar(final Context context, Component component) {
31
+    public TopBar(final Context context, Component component, EventDispatcher eventDispatcher) {
35 32
         super(context);
36 33
         collapsingBehavior = new TopBarCollapseBehavior(eventDispatcher, this);
37 34
         this.component = component;
38 35
         titleBar = new Toolbar(context);
39 36
         topTabs = new TopTabs(getContext());
40
-        animator = new TopBarAnimator(this, component != null ? component.getContentView() : null);
37
+        this.animator = new TopBarAnimator(this, component != null ? component.getContentView() : null);
41 38
         addView(titleBar);
42 39
     }
43 40
 
@@ -121,10 +118,10 @@ public class TopBar extends AppBarLayout {
121 118
         setLeftButton(leftButton);
122 119
     }
123 120
 
124
-	private void setLeftButton(final Button button) {
125
-		TitleBarButton leftBarButton = new TitleBarButton(component, this.titleBar, button);
126
-		leftBarButton.applyNavigationIcon(getContext());
127
-	}
121
+    private void setLeftButton(final Button button) {
122
+        TitleBarButton leftBarButton = new TitleBarButton(component, this.titleBar, button);
123
+        leftBarButton.applyNavigationIcon(getContext());
124
+    }
128 125
 
129 126
     private void setRightButtons(ArrayList<Button> rightButtons) {
130 127
         if (rightButtons == null || rightButtons.size() == 0) {
@@ -134,11 +131,11 @@ public class TopBar extends AppBarLayout {
134 131
         Menu menu = getTitleBar().getMenu();
135 132
         menu.clear();
136 133
 
137
-		for (int i = 0; i < rightButtons.size(); i++){
138
-	   		Button button = rightButtons.get(i);
139
-			TitleBarButton titleBarButton = new TitleBarButton(component, this.titleBar, button);
140
-			titleBarButton.addToMenu(getContext(), menu);
141
-       }
134
+        for (int i = 0; i < rightButtons.size(); i++) {
135
+            Button button = rightButtons.get(i);
136
+            TitleBarButton titleBarButton = new TitleBarButton(component, this.titleBar, button);
137
+            titleBarButton.addToMenu(getContext(), menu);
138
+        }
142 139
     }
143 140
 
144 141
     public Toolbar getTitleBar() {

+ 14
- 18
lib/android/app/src/main/java/com/reactnativenavigation/views/TopTabsLayout.java Parādīt failu

@@ -1,22 +1,18 @@
1 1
 package com.reactnativenavigation.views;
2 2
 
3
-import android.annotation.SuppressLint;
4
-import android.content.Context;
5
-import android.support.annotation.RestrictTo;
6
-import android.support.v4.view.ViewPager;
7
-import android.view.View;
8
-import android.view.ViewGroup;
9
-import android.widget.LinearLayout;
10
-import android.widget.RelativeLayout;
11
-
12
-import com.reactnativenavigation.parse.NavigationOptions;
13
-import com.reactnativenavigation.presentation.OptionsPresenter;
14
-import com.reactnativenavigation.utils.Task;
15
-import com.reactnativenavigation.viewcontrollers.toptabs.TopTabController;
16
-import com.reactnativenavigation.viewcontrollers.toptabs.TopTabsAdapter;
17
-import com.reactnativenavigation.viewcontrollers.toptabs.TopTabsViewPager;
18
-
19
-import java.util.List;
3
+import android.annotation.*;
4
+import android.content.*;
5
+import android.support.annotation.*;
6
+import android.support.v4.view.*;
7
+import android.view.*;
8
+import android.widget.*;
9
+
10
+import com.reactnativenavigation.parse.*;
11
+import com.reactnativenavigation.presentation.*;
12
+import com.reactnativenavigation.utils.*;
13
+import com.reactnativenavigation.viewcontrollers.toptabs.*;
14
+
15
+import java.util.*;
20 16
 
21 17
 @SuppressLint("ViewConstructor")
22 18
 public class TopTabsLayout extends RelativeLayout implements Component {
@@ -29,7 +25,7 @@ public class TopTabsLayout extends RelativeLayout implements Component {
29 25
     public TopTabsLayout(Context context, List<TopTabController> tabs, TopTabsAdapter adapter) {
30 26
         super(context);
31 27
         this.tabs = tabs;
32
-        topBar = new TopBar(context, this);
28
+        topBar = new TopBar(context, this, null);
33 29
         topBar.setId(View.generateViewId());
34 30
         viewPager = new TopTabsViewPager(context, tabs, adapter);
35 31
         optionsPresenter = new OptionsPresenter(this);

+ 1
- 1
lib/android/app/src/test/java/com/reactnativenavigation/mocks/TestComponentLayout.java Parādīt failu

@@ -18,7 +18,7 @@ public class TestComponentLayout extends RelativeLayout implements ReactComponen
18 18
 
19 19
     public TestComponentLayout(final Context context) {
20 20
 		super(context);
21
-        topBar = new TopBar(context, this);
21
+        topBar = new TopBar(context, this, null);
22 22
         contentView = new View(context);
23 23
         addView(topBar);
24 24
         addView(contentView);

+ 1
- 1
lib/android/app/src/test/java/com/reactnativenavigation/mocks/TestComponentView.java Parādīt failu

@@ -13,7 +13,7 @@ public class TestComponentView extends View implements ReactComponent {
13 13
 
14 14
 	public TestComponentView(final Context context) {
15 15
 		super(context);
16
-		topBar = new TopBar(context, this);
16
+		topBar = new TopBar(context, this, null);
17 17
 
18 18
 	}
19 19
 

+ 1
- 1
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/OptionsApplyingTest.java Parādīt failu

@@ -140,7 +140,7 @@ public class OptionsApplyingTest extends BaseTest {
140 140
 
141 141
     @Test
142 142
     public void appliesDrawUnder() throws Exception {
143
-        assertThat(uut.getNavigationOptions()).isSameAs(initialNavigationOptions);
143
+        assertThat(uut.getOptions()).isSameAs(initialNavigationOptions);
144 144
         initialNavigationOptions.topBarOptions.title = "the title";
145 145
         initialNavigationOptions.topBarOptions.drawBehind = NavigationOptions.BooleanOptions.False;
146 146
         uut.onViewAppeared();

+ 1
- 1
lib/android/app/src/test/java/com/reactnativenavigation/views/TopBarTest.java Parādīt failu

@@ -9,7 +9,7 @@ import static org.assertj.core.api.Java6Assertions.assertThat;
9 9
 public class TopBarTest extends BaseTest {
10 10
 	@Test
11 11
 	public void title() throws Exception {
12
-		TopBar topBar = new TopBar(newActivity());
12
+		TopBar topBar = new TopBar(newActivity(), null, null);
13 13
 		assertThat(topBar.getTitle()).isEmpty();
14 14
 
15 15
 		topBar.setTitle("new title");