Browse Source

Add button text color unit test

Guy Carmeli 6 years ago
parent
commit
c949b0f557

+ 2
- 2
lib/android/app/src/main/java/com/reactnativenavigation/utils/ButtonOptionsPresenter.java View File

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

+ 4
- 0
lib/android/app/src/test/java/com/reactnativenavigation/BaseTest.java View File

49
             controller.options.animations.push.enable = new Bool(false);
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 View File

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

+ 38
- 3
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/TopBarButtonControllerTest.java View File

25
 
25
 
26
 import static org.assertj.core.api.Java6Assertions.assertThat;
26
 import static org.assertj.core.api.Java6Assertions.assertThat;
27
 import static org.mockito.ArgumentMatchers.any;
27
 import static org.mockito.ArgumentMatchers.any;
28
+import static org.mockito.ArgumentMatchers.anyInt;
28
 import static org.mockito.ArgumentMatchers.eq;
29
 import static org.mockito.ArgumentMatchers.eq;
29
 import static org.mockito.Mockito.spy;
30
 import static org.mockito.Mockito.spy;
30
 import static org.mockito.Mockito.times;
31
 import static org.mockito.Mockito.times;
100
         setIconButton(false);
101
         setIconButton(false);
101
         button.disableIconTint = new Bool(true);
102
         button.disableIconTint = new Bool(true);
102
         uut.addToMenu(getTitleBar(), 0);
103
         uut.addToMenu(getTitleBar(), 0);
103
-        verify(optionsPresenter, times(0)).setTextColor();
104
+        verify(optionsPresenter, times(0)).tint(any(), anyInt());
104
     }
105
     }
105
 
106
 
106
     @Test
107
     @Test
116
         uut.addToMenu(getTitleBar(), 0);
117
         uut.addToMenu(getTitleBar(), 0);
117
         verify(optionsPresenter, times(0)).setFontSize(getTitleBar().getMenu().getItem(0));
118
         verify(optionsPresenter, times(0)).setFontSize(getTitleBar().getMenu().getItem(0));
118
 
119
 
119
-        getTitleBar().getMenu().clear();
120
+        clearMenu();
120
         button.fontSize = new Number(10);
121
         button.fontSize = new Number(10);
121
         uut.addToMenu(getTitleBar(), 0);
122
         uut.addToMenu(getTitleBar(), 0);
122
         verify(optionsPresenter, times(1)).setFontSize(getTitleBar().getMenu().getItem(0));
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
     private Toolbar getTitleBar() {
161
     private Toolbar getTitleBar() {
126
         return stackController.getTopBar().getTitleBar();
162
         return stackController.getTopBar().getTitleBar();
127
     }
163
     }
128
 
164
 
129
     private void setTextButton() {
165
     private void setTextButton() {
130
         button.id = "btn1";
166
         button.id = "btn1";
131
-        button.color = new Color(android.graphics.Color.RED);
132
         button.title = new Text("Button");
167
         button.title = new Text("Button");
133
         button.fontFamily = Typeface.MONOSPACE;
168
         button.fontFamily = Typeface.MONOSPACE;
134
         button.showAsAction = MenuItem.SHOW_AS_ACTION_ALWAYS;
169
         button.showAsAction = MenuItem.SHOW_AS_ACTION_ALWAYS;