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