|
@@ -1,6 +1,7 @@
|
1
|
1
|
package com.reactnativenavigation.viewcontrollers;
|
2
|
2
|
|
3
|
3
|
import android.app.Activity;
|
|
4
|
+import android.content.Context;
|
4
|
5
|
import android.graphics.Color;
|
5
|
6
|
import android.graphics.drawable.ColorDrawable;
|
6
|
7
|
import android.view.View;
|
|
@@ -20,10 +21,11 @@ import com.reactnativenavigation.parse.params.Bool;
|
20
|
21
|
import com.reactnativenavigation.parse.params.Fraction;
|
21
|
22
|
import com.reactnativenavigation.parse.params.Text;
|
22
|
23
|
import com.reactnativenavigation.utils.CommandListenerAdapter;
|
23
|
|
-import com.reactnativenavigation.utils.ViewUtils;
|
24
|
24
|
import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
|
25
|
25
|
import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
|
26
|
|
-import com.reactnativenavigation.views.topbar.TopBarBackgroundView;
|
|
26
|
+import com.reactnativenavigation.views.StackLayout;
|
|
27
|
+import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
|
|
28
|
+import com.reactnativenavigation.views.topbar.TopBar;
|
27
|
29
|
|
28
|
30
|
import org.json.JSONObject;
|
29
|
31
|
import org.junit.Test;
|
|
@@ -31,7 +33,10 @@ import org.junit.Test;
|
31
|
33
|
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
32
|
34
|
import static android.widget.RelativeLayout.BELOW;
|
33
|
35
|
import static org.assertj.core.api.Java6Assertions.assertThat;
|
|
36
|
+import static org.mockito.ArgumentMatchers.any;
|
34
|
37
|
import static org.mockito.Mockito.spy;
|
|
38
|
+import static org.mockito.Mockito.times;
|
|
39
|
+import static org.mockito.Mockito.verify;
|
35
|
40
|
|
36
|
41
|
public class OptionsApplyingTest extends BaseTest {
|
37
|
42
|
private Activity activity;
|
|
@@ -39,6 +44,8 @@ public class OptionsApplyingTest extends BaseTest {
|
39
|
44
|
private ComponentViewController uut;
|
40
|
45
|
private IReactView view;
|
41
|
46
|
private Options initialNavigationOptions;
|
|
47
|
+ private TopBarController topBarController;
|
|
48
|
+ private TopBar topBar;
|
42
|
49
|
|
43
|
50
|
@Override
|
44
|
51
|
public void beforeEach() {
|
|
@@ -54,11 +61,18 @@ public class OptionsApplyingTest extends BaseTest {
|
54
|
61
|
(activity1, componentId, componentName) -> view,
|
55
|
62
|
initialNavigationOptions
|
56
|
63
|
);
|
|
64
|
+ topBarController = new TopBarController() {
|
|
65
|
+ @Override
|
|
66
|
+ protected TopBar createTopBar(Context context, ReactViewCreator buttonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewController topBarBackgroundViewController, TopBarButtonController.OnClickListener topBarButtonClickListener, StackLayout stackLayout) {
|
|
67
|
+ topBar = spy(super.createTopBar(context, buttonCreator, titleBarReactViewCreator, topBarBackgroundViewController, topBarButtonClickListener, stackLayout));
|
|
68
|
+ return topBar;
|
|
69
|
+ }
|
|
70
|
+ };
|
57
|
71
|
stackController = new StackControllerBuilder(activity)
|
58
|
72
|
.setTopBarButtonCreator(new TopBarButtonCreatorMock())
|
59
|
73
|
.setTitleBarReactViewCreator(new TitleBarReactViewCreatorMock())
|
60
|
74
|
.setTopBarBackgroundViewController(new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()))
|
61
|
|
- .setTopBarController(new TopBarController())
|
|
75
|
+ .setTopBarController(topBarController)
|
62
|
76
|
.setId("stack")
|
63
|
77
|
.setInitialOptions(new Options())
|
64
|
78
|
.createStackController();
|
|
@@ -128,7 +142,7 @@ public class OptionsApplyingTest extends BaseTest {
|
128
|
142
|
opts.topBar.background.color = new com.reactnativenavigation.parse.params.Color(Color.RED);
|
129
|
143
|
uut.mergeOptions(opts);
|
130
|
144
|
|
131
|
|
- assertThat(((ColorDrawable) stackController.getTopBar().getTitleBar().getBackground()).getColor()).isEqualTo(Color.RED);
|
|
145
|
+ assertThat(((ColorDrawable) stackController.getTopBar().getBackground()).getColor()).isEqualTo(Color.RED);
|
132
|
146
|
}
|
133
|
147
|
|
134
|
148
|
@Test
|
|
@@ -205,6 +219,7 @@ public class OptionsApplyingTest extends BaseTest {
|
205
|
219
|
|
206
|
220
|
@Test
|
207
|
221
|
public void appliesTopBarComponent() throws Exception {
|
|
222
|
+ disablePushAnimation(uut);
|
208
|
223
|
JSONObject json = new JSONObject();
|
209
|
224
|
json.put("component", new JSONObject().put("name","someComponent").put("componentId", "id"));
|
210
|
225
|
uut.options.topBar.background = TopBarBackgroundOptions.parse(json);
|
|
@@ -212,8 +227,7 @@ public class OptionsApplyingTest extends BaseTest {
|
212
|
227
|
stackController.push(uut, new CommandListenerAdapter());
|
213
|
228
|
uut.onViewAppeared();
|
214
|
229
|
|
215
|
|
- assertThat(((ColorDrawable) stackController.getTopBar().getTitleBar().getBackground()).getColor()).isEqualTo(Color.TRANSPARENT);
|
216
|
|
- assertThat(ViewUtils.findChildrenByClassRecursive(stackController.getTopBar(), TopBarBackgroundView.class)).isNotNull();
|
|
230
|
+ verify(topBar, times(1)).setBackgroundComponent(any());
|
217
|
231
|
}
|
218
|
232
|
|
219
|
233
|
@Test
|