瀏覽代碼

Add button text color unit test

Guy Carmeli 6 年之前
父節點
當前提交
c949b0f557

+ 2
- 2
lib/android/app/src/main/java/com/reactnativenavigation/utils/ButtonOptionsPresenter.java 查看文件

@@ -65,11 +65,11 @@ public class ButtonOptionsPresenter {
65 65
         });
66 66
     }
67 67
 
68
-    private void setDisabledColor(TextView btn, int color) {
68
+    public void setDisabledColor(TextView btn, int color) {
69 69
         btn.setTextColor(color);
70 70
     }
71 71
 
72
-    private void setEnabledColor(TextView btn) {
72
+    public void setEnabledColor(TextView btn) {
73 73
         btn.setTextColor(button.color.get());
74 74
     }
75 75
 

+ 4
- 0
lib/android/app/src/test/java/com/reactnativenavigation/BaseTest.java 查看文件

@@ -49,4 +49,8 @@ public abstract class BaseTest {
49 49
             controller.options.animations.push.enable = new Bool(false);
50 50
         }
51 51
     }
52
+
53
+    protected void dispatchPreDraw(View view) {
54
+        view.getViewTreeObserver().dispatchOnPreDraw();
55
+    }
52 56
 }

+ 2
- 2
lib/android/app/src/test/java/com/reactnativenavigation/utils/UiUtilsTest.java 查看文件

@@ -10,13 +10,13 @@ import static org.mockito.Mockito.*;
10 10
 
11 11
 public class UiUtilsTest extends BaseTest {
12 12
     @Test
13
-    public void runOnPreDrawOnce() throws Exception {
13
+    public void runOnPreDrawOnce() {
14 14
         View view = new View(newActivity());
15 15
         Runnable task = mock(Runnable.class);
16 16
         verifyZeroInteractions(task);
17 17
 
18 18
         UiUtils.runOnPreDrawOnce(view, task);
19
-        view.getViewTreeObserver().dispatchOnPreDraw();
19
+        dispatchPreDraw(view);
20 20
         verify(task, times(1)).run();
21 21
     }
22 22
 }

+ 38
- 3
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/TopBarButtonControllerTest.java 查看文件

@@ -25,6 +25,7 @@ import org.junit.Test;
25 25
 
26 26
 import static org.assertj.core.api.Java6Assertions.assertThat;
27 27
 import static org.mockito.ArgumentMatchers.any;
28
+import static org.mockito.ArgumentMatchers.anyInt;
28 29
 import static org.mockito.ArgumentMatchers.eq;
29 30
 import static org.mockito.Mockito.spy;
30 31
 import static org.mockito.Mockito.times;
@@ -100,7 +101,7 @@ public class TopBarButtonControllerTest extends BaseTest {
100 101
         setIconButton(false);
101 102
         button.disableIconTint = new Bool(true);
102 103
         uut.addToMenu(getTitleBar(), 0);
103
-        verify(optionsPresenter, times(0)).setTextColor();
104
+        verify(optionsPresenter, times(0)).tint(any(), anyInt());
104 105
     }
105 106
 
106 107
     @Test
@@ -116,19 +117,53 @@ public class TopBarButtonControllerTest extends BaseTest {
116 117
         uut.addToMenu(getTitleBar(), 0);
117 118
         verify(optionsPresenter, times(0)).setFontSize(getTitleBar().getMenu().getItem(0));
118 119
 
119
-        getTitleBar().getMenu().clear();
120
+        clearMenu();
120 121
         button.fontSize = new Number(10);
121 122
         uut.addToMenu(getTitleBar(), 0);
122 123
         verify(optionsPresenter, times(1)).setFontSize(getTitleBar().getMenu().getItem(0));
123 124
     }
124 125
 
126
+    @Test
127
+    public void textColor_enabled() {
128
+        setTextButton();
129
+        button.enabled = new Bool(false);
130
+        uut.addToMenu(getTitleBar(), 0);
131
+        dispatchPreDraw(getTitleBar());
132
+        verify(optionsPresenter, times(0)).setEnabledColor(any());
133
+
134
+        clearMenu();
135
+        button.enabled = new Bool(true);
136
+        button.color = new Color(android.graphics.Color.RED);
137
+        uut.addToMenu(getTitleBar(), 0);
138
+        dispatchPreDraw(getTitleBar());
139
+        verify(optionsPresenter, times(1)).setEnabledColor(any());
140
+    }
141
+
142
+    private void clearMenu() {
143
+        getTitleBar().getMenu().clear();
144
+    }
145
+
146
+    @Test
147
+    public void textColor_disabled() {
148
+        setTextButton();
149
+        button.enabled = new Bool(false);
150
+        uut.addToMenu(getTitleBar(), 0);
151
+        dispatchPreDraw(getTitleBar());
152
+        verify(optionsPresenter, times(1)).setDisabledColor(any(), eq(android.graphics.Color.LTGRAY));
153
+
154
+        clearMenu();
155
+        button.disabledColor = new Color(android.graphics.Color.BLACK);
156
+        uut.addToMenu(getTitleBar(), 0);
157
+        dispatchPreDraw(getTitleBar());
158
+        verify(optionsPresenter, times(1)).setDisabledColor(any(), eq(android.graphics.Color.BLACK));
159
+    }
160
+
125 161
     private Toolbar getTitleBar() {
126 162
         return stackController.getTopBar().getTitleBar();
127 163
     }
128 164
 
129 165
     private void setTextButton() {
130 166
         button.id = "btn1";
131
-        button.color = new Color(android.graphics.Color.RED);
132 167
         button.title = new Text("Button");
133 168
         button.fontFamily = Typeface.MONOSPACE;
134 169
         button.showAsAction = MenuItem.SHOW_AS_ACTION_ALWAYS;