|
6 | 6 |
|
7 | 7 | import com.facebook.react.bridge.Arguments;
|
8 | 8 | import com.facebook.react.bridge.Callback;
|
| 9 | +import com.facebook.react.bridge.JavaOnlyMap; |
| 10 | +import com.facebook.react.bridge.ReadableMapKeySetIterator; |
| 11 | +import com.facebook.react.bridge.ReadableType; |
| 12 | +import com.facebook.react.bridge.WritableMap; |
9 | 13 | import com.facebook.react.bridge.WritableNativeArray;
|
| 14 | +import com.facebook.react.bridge.WritableNativeMap; |
10 | 15 | import com.instabug.bug.BugReporting;
|
11 | 16 | import com.instabug.chat.Replies;
|
12 | 17 | import com.instabug.library.Feature;
|
13 | 18 | import com.instabug.reactlibrary.utils.InstabugUtil;
|
| 19 | +import com.instabug.reactlibrary.utils.MapUtil; |
14 | 20 | import com.instabug.survey.Surveys;
|
15 | 21 | import com.instabug.reactlibrary.utils.MainThreadHandler;
|
16 | 22 |
|
|
27 | 33 |
|
28 | 34 | import java.util.concurrent.Executors;
|
29 | 35 | import java.util.concurrent.ScheduledExecutorService;
|
| 36 | +import java.util.Map; |
| 37 | +import java.util.HashMap; |
30 | 38 |
|
31 | 39 | import static org.mockito.Matchers.any;
|
32 | 40 | import static org.mockito.Matchers.anyLong;
|
|
36 | 44 | import static org.powermock.api.mockito.PowerMockito.when;
|
37 | 45 |
|
38 | 46 | @RunWith(PowerMockRunner.class)
|
39 |
| -@PrepareForTest({Looper.class, android.os.Handler.class, BugReporting.class, Replies.class, Surveys.class, SystemClock.class, Runnable.class, WritableNativeArray.class, JSONObject.class, Arguments.class, InstabugUtil.class, RNInstabugRepliesModule.class, MainThreadHandler.class}) |
| 47 | +@PrepareForTest({Looper.class, android.os.Handler.class, BugReporting.class, Replies.class, Surveys.class, SystemClock.class, Runnable.class, WritableNativeMap.class, WritableNativeArray.class, JSONObject.class, Arguments.class, InstabugUtil.class, RNInstabugRepliesModule.class, MainThreadHandler.class}) |
40 | 48 |
|
41 | 49 | public class RNInstabugRepliesModuleTest {
|
42 | 50 | private RNInstabugRepliesModule rnModule = new RNInstabugRepliesModule(null);
|
@@ -170,6 +178,65 @@ public Boolean answer(InvocationOnMock invocation) throws Throwable {
|
170 | 178 | Replies.setPushNotificationRegistrationToken("123");
|
171 | 179 | }
|
172 | 180 |
|
| 181 | + @Test |
| 182 | + public void givenBoolean$showNotification_whenQuery_thenShouldCallNativeApi() { |
| 183 | + // given |
| 184 | + PowerMockito.mockStatic(Replies.class); |
| 185 | + PowerMockito.mockStatic(SystemClock.class); |
| 186 | + PowerMockito.mockStatic(Arguments.class); |
| 187 | + PowerMockito.mock(JSONObject.class); |
| 188 | + |
| 189 | + // when |
| 190 | + final long ts = SystemClock.uptimeMillis(); |
| 191 | + PowerMockito.when(Arguments.createMap()) |
| 192 | + .thenAnswer( |
| 193 | + new Answer<Object>() { |
| 194 | + @Override |
| 195 | + public Object answer(InvocationOnMock invocation) throws Throwable { |
| 196 | + return new JavaOnlyMap(); |
| 197 | + } |
| 198 | + }); |
| 199 | + PowerMockito.when(SystemClock.uptimeMillis()) |
| 200 | + .thenAnswer( |
| 201 | + new Answer<Object>() { |
| 202 | + @Override |
| 203 | + public Object answer(InvocationOnMock invocation) throws Throwable { |
| 204 | + return ts; |
| 205 | + } |
| 206 | + }); |
| 207 | + |
| 208 | + HashMap<String, Object> hm = new HashMap<>(); |
| 209 | + hm.put("message", "{\"aps\":{\"alert\":\"You have an unread message from RN-TestAnything team\"},\"IBGHost\":true}"); |
| 210 | + WritableMap readableMap = MapUtil.toWritableMap(hm); |
| 211 | + |
| 212 | + Map<String, String> map = new HashMap<>(); |
| 213 | + ReadableMapKeySetIterator iterator = readableMap.keySetIterator(); |
| 214 | + while (iterator.hasNextKey()) { |
| 215 | + String key = iterator.nextKey(); |
| 216 | + ReadableType type = readableMap.getType(key); |
| 217 | + |
| 218 | + switch(type) { |
| 219 | + case String: |
| 220 | + String value = readableMap.getString(key); |
| 221 | + map.put(key, value); |
| 222 | + break; |
| 223 | + } |
| 224 | + } |
| 225 | + |
| 226 | + PowerMockito.when(Replies.isInstabugNotification(map)) |
| 227 | + .thenAnswer( |
| 228 | + new Answer<Object>() { |
| 229 | + @Override |
| 230 | + public Object answer(InvocationOnMock invocation) throws Throwable { |
| 231 | + return true; |
| 232 | + } |
| 233 | + }); |
| 234 | + rnModule.showNotification(readableMap); |
| 235 | + |
| 236 | + PowerMockito.verifyStatic(VerificationModeFactory.times(1)); |
| 237 | + Replies.showNotification(map); |
| 238 | + } |
| 239 | + |
173 | 240 | @Test
|
174 | 241 | public void givenBoolean$setNotificationIcon_whenQuery_thenShouldCallNativeApi() {
|
175 | 242 | // given
|
|
0 commit comments