|
@@ -1,6 +1,7 @@
|
1
|
1
|
package com.reactnativenavigation.viewcontrollers;
|
2
|
2
|
|
3
|
3
|
import android.app.Activity;
|
|
4
|
+import android.graphics.Typeface;
|
4
|
5
|
import android.support.v7.widget.Toolbar;
|
5
|
6
|
import android.view.MenuItem;
|
6
|
7
|
|
|
@@ -15,7 +16,7 @@ import com.reactnativenavigation.parse.params.Button;
|
15
|
16
|
import com.reactnativenavigation.parse.params.Color;
|
16
|
17
|
import com.reactnativenavigation.parse.params.NullText;
|
17
|
18
|
import com.reactnativenavigation.parse.params.Text;
|
18
|
|
-import com.reactnativenavigation.utils.DrawableTinter;
|
|
19
|
+import com.reactnativenavigation.utils.ButtonOptionsPresenter;
|
19
|
20
|
import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
|
20
|
21
|
import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
|
21
|
22
|
|
|
@@ -27,14 +28,13 @@ import static org.mockito.ArgumentMatchers.eq;
|
27
|
28
|
import static org.mockito.Mockito.spy;
|
28
|
29
|
import static org.mockito.Mockito.times;
|
29
|
30
|
import static org.mockito.Mockito.verify;
|
30
|
|
-import static org.mockito.Mockito.verifyZeroInteractions;
|
31
|
31
|
|
32
|
32
|
public class TopBarButtonControllerTest extends BaseTest {
|
33
|
33
|
|
34
|
34
|
private TopBarButtonController uut;
|
35
|
35
|
private StackController stackController;
|
36
|
36
|
private Button button;
|
37
|
|
- private DrawableTinter drawableTinter = spy(new DrawableTinter());
|
|
37
|
+ private ButtonOptionsPresenter optionsPresenter;
|
38
|
38
|
|
39
|
39
|
@Override
|
40
|
40
|
public void beforeEach() {
|
|
@@ -42,7 +42,6 @@ public class TopBarButtonControllerTest extends BaseTest {
|
42
|
42
|
final Activity activity = newActivity();
|
43
|
43
|
|
44
|
44
|
TopBarButtonCreatorMock buttonCreatorMock = new TopBarButtonCreatorMock();
|
45
|
|
- uut = new TopBarButtonController(activity, ImageLoaderMock.mock(), drawableTinter, button, buttonCreatorMock, (buttonId) -> {});
|
46
|
45
|
stackController = spy(new StackController(activity,
|
47
|
46
|
buttonCreatorMock,
|
48
|
47
|
new TitleBarReactViewCreatorMock(),
|
|
@@ -53,7 +52,12 @@ public class TopBarButtonControllerTest extends BaseTest {
|
53
|
52
|
);
|
54
|
53
|
stackController.getView().layout(0, 0, 1080, 1920);
|
55
|
54
|
stackController.getTopBar().layout(0, 0, 1080, 200);
|
56
|
|
- stackController.getTopBar().getTitleBar().layout(0, 0, 1080, 200);
|
|
55
|
+ getTitleBar().layout(0, 0, 1080, 200);
|
|
56
|
+
|
|
57
|
+ optionsPresenter = spy(new ButtonOptionsPresenter(getTitleBar(), button));
|
|
58
|
+ uut = new TopBarButtonController(activity, ImageLoaderMock.mock(), optionsPresenter, button, buttonCreatorMock, (buttonId) -> {});
|
|
59
|
+
|
|
60
|
+ stackController.ensureViewIsCreated();
|
57
|
61
|
}
|
58
|
62
|
|
59
|
63
|
@Test
|
|
@@ -66,45 +70,55 @@ public class TopBarButtonControllerTest extends BaseTest {
|
66
|
70
|
|
67
|
71
|
@Test
|
68
|
72
|
public void setIconColor_enabled() {
|
69
|
|
- stackController.ensureViewIsCreated();
|
70
|
|
-
|
71
|
73
|
setIconButton(true);
|
72
|
|
- Toolbar titleBar = stackController.getTopBar().getTitleBar();
|
73
|
|
- uut.addToMenu(titleBar, 0);
|
|
74
|
+ uut.addToMenu(getTitleBar(), 0);
|
74
|
75
|
|
75
|
|
- assertThat(titleBar.getMenu().size()).isOne();
|
76
|
|
- verify(drawableTinter, times(1)).tint(any(), eq(android.graphics.Color.RED));
|
|
76
|
+ assertThat(getTitleBar().getMenu().size()).isOne();
|
|
77
|
+ verify(optionsPresenter, times(1)).tint(any(), eq(android.graphics.Color.RED));
|
77
|
78
|
}
|
78
|
79
|
|
79
|
80
|
@Test
|
80
|
81
|
public void setIconColor_disabled() {
|
81
|
|
- stackController.ensureViewIsCreated();
|
82
|
|
-
|
83
|
82
|
setIconButton(false);
|
84
|
|
- uut.addToMenu(stackController.getTopBar().getTitleBar(), 0);
|
|
83
|
+ uut.addToMenu(getTitleBar(), 0);
|
85
|
84
|
|
86
|
|
- verify(drawableTinter, times(1)).tint(any(), eq(android.graphics.Color.LTGRAY));
|
|
85
|
+ verify(optionsPresenter, times(1)).tint(any(), eq(android.graphics.Color.LTGRAY));
|
87
|
86
|
}
|
88
|
87
|
|
89
|
88
|
@Test
|
90
|
89
|
public void setIconColor_disabledColor() {
|
91
|
|
- stackController.ensureViewIsCreated();
|
92
|
|
-
|
93
|
90
|
setIconButton(false);
|
94
|
91
|
button.disabledColor = new Color(android.graphics.Color.BLACK);
|
95
|
|
- uut.addToMenu(stackController.getTopBar().getTitleBar(), 0);
|
|
92
|
+ uut.addToMenu(getTitleBar(), 0);
|
96
|
93
|
|
97
|
|
- verify(drawableTinter, times(1)).tint(any(), eq(android.graphics.Color.BLACK));
|
|
94
|
+ verify(optionsPresenter, times(1)).tint(any(), eq(android.graphics.Color.BLACK));
|
98
|
95
|
}
|
99
|
96
|
|
100
|
97
|
@Test
|
101
|
98
|
public void disableIconTint() {
|
102
|
|
- stackController.ensureViewIsCreated();
|
103
|
|
-
|
104
|
99
|
setIconButton(false);
|
105
|
100
|
button.disableIconTint = new Bool(true);
|
106
|
|
- uut.addToMenu(stackController.getTopBar().getTitleBar(), 0);
|
107
|
|
- verifyZeroInteractions(drawableTinter);
|
|
101
|
+ uut.addToMenu(getTitleBar(), 0);
|
|
102
|
+ verify(optionsPresenter, times(0)).setTextColor();
|
|
103
|
+ }
|
|
104
|
+
|
|
105
|
+ @Test
|
|
106
|
+ public void fontFamily() {
|
|
107
|
+ setTextButton();
|
|
108
|
+ uut.addToMenu(getTitleBar(), 0);
|
|
109
|
+ verify(optionsPresenter, times(1)).setTypeFace(Typeface.MONOSPACE);
|
|
110
|
+ }
|
|
111
|
+
|
|
112
|
+ private Toolbar getTitleBar() {
|
|
113
|
+ return stackController.getTopBar().getTitleBar();
|
|
114
|
+ }
|
|
115
|
+
|
|
116
|
+ private void setTextButton() {
|
|
117
|
+ button.id = "btn1";
|
|
118
|
+ button.color = new Color(android.graphics.Color.RED);
|
|
119
|
+ button.title = new Text("Button");
|
|
120
|
+ button.fontFamily = Typeface.MONOSPACE;
|
|
121
|
+ button.showAsAction = MenuItem.SHOW_AS_ACTION_ALWAYS;
|
108
|
122
|
}
|
109
|
123
|
|
110
|
124
|
private void setIconButton(boolean enabled) {
|