@imatis/react-native-notifications 4.2.4-imatis.21 → 4.3.1-imatis.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.gren.md +167 -79
- package/android/app/src/reactNative59/reactNative59.iml +11 -0
- package/android/app/src/reactNative60/reactNative60.iml +11 -0
- package/lib/android/.gradle/6.1.1/executionHistory/executionHistory.lock +0 -0
- package/lib/android/.gradle/6.1.1/fileHashes/fileHashes.bin +0 -0
- package/lib/android/.gradle/6.1.1/fileHashes/fileHashes.lock +0 -0
- package/lib/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/lib/android/.gradle/buildOutputCleanup/cache.properties +1 -1
- package/lib/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
- package/lib/android/.gradle/checksums/checksums.lock +0 -0
- package/lib/android/.gradle/checksums/md5-checksums.bin +0 -0
- package/lib/android/.gradle/checksums/sha1-checksums.bin +0 -0
- package/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java +3 -1
- package/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/ReactAppLifecycleFacade.java +5 -1
- package/lib/android/local.properties +2 -2
- package/lib/dist/adapters/NativeEventsReceiver.d.ts +1 -0
- package/lib/dist/adapters/NativeEventsReceiver.js +3 -0
- package/lib/dist/events/EventsRegistry.d.ts +1 -0
- package/lib/dist/events/EventsRegistry.js +3 -0
- package/lib/ios/RNEventEmitter.h +1 -0
- package/lib/ios/RNEventEmitter.m +1 -0
- package/lib/ios/RNNotificationCenter.m +4 -0
- package/lib/ios/RNNotifications.xcodeproj/project.xcworkspace/xcuserdata/troy.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/lib/src/adapters/NativeEventsReceiver.ts +6 -2
- package/lib/src/events/EventsRegistry.ts +4 -0
- package/package-lock.json +13507 -0
- package/package.json +2 -2
- package/react-native.config.js +0 -1
- package/lib/android/.gradle/6.1.1/executionHistory/executionHistory.bin +0 -0
- package/lib/android/.gradle/6.1.1/fileContent/fileContent.lock +0 -0
- package/lib/android/.gradle/6.1.1/fileHashes/resourceHashesCache.bin +0 -0
- package/lib/android/.gradle/6.1.1/javaCompile/classAnalysis.bin +0 -0
- package/lib/android/.gradle/6.1.1/javaCompile/jarAnalysis.bin +0 -0
- package/lib/android/.gradle/6.1.1/javaCompile/javaCompile.lock +0 -0
- package/lib/android/.gradle/6.1.1/javaCompile/taskHistory.bin +0 -0
- package/lib/android/app/src/test/java/com/wix/reactnativenotifications/core/AppLaunchHelperTest.java +0 -117
- package/lib/android/app/src/test/java/com/wix/reactnativenotifications/core/InitialNotificationHolderTest.java +0 -59
- package/lib/android/app/src/test/java/com/wix/reactnativenotifications/core/JsIOHelperTest.java +0 -60
- package/lib/android/app/src/test/java/com/wix/reactnativenotifications/core/notification/PushNotificationTest.java +0 -381
- package/lib/android/app/src/test/java/com/wix/reactnativenotifications/core/notificationdrawer/PushNotificationsDrawerTest.java +0 -96
- package/lib/android/app/src/test/resources/robolectric.properties +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imatis/react-native-notifications",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.1-imatis.24",
|
|
4
4
|
"description": "Advanced Push Notifications (Silent, interactive notifications) for iOS & Android",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -131,4 +131,4 @@
|
|
|
131
131
|
"html"
|
|
132
132
|
]
|
|
133
133
|
}
|
|
134
|
-
}
|
|
134
|
+
}
|
package/react-native.config.js
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/lib/android/app/src/test/java/com/wix/reactnativenotifications/core/AppLaunchHelperTest.java
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
package com.wix.reactnativenotifications.core;
|
|
2
|
-
|
|
3
|
-
import android.app.Activity;
|
|
4
|
-
import android.content.ComponentName;
|
|
5
|
-
import android.content.Context;
|
|
6
|
-
import android.content.Intent;
|
|
7
|
-
import android.content.pm.PackageManager;
|
|
8
|
-
|
|
9
|
-
import org.junit.Before;
|
|
10
|
-
import org.junit.Test;
|
|
11
|
-
import org.junit.runner.RunWith;
|
|
12
|
-
import org.mockito.Mock;
|
|
13
|
-
import org.mockito.MockitoAnnotations;
|
|
14
|
-
import org.robolectric.RobolectricTestRunner;
|
|
15
|
-
|
|
16
|
-
import static org.junit.Assert.assertEquals;
|
|
17
|
-
import static org.junit.Assert.assertFalse;
|
|
18
|
-
import static org.junit.Assert.assertNotNull;
|
|
19
|
-
import static org.junit.Assert.assertTrue;
|
|
20
|
-
import static org.mockito.ArgumentMatchers.eq;
|
|
21
|
-
import static org.mockito.Mockito.mock;
|
|
22
|
-
import static org.mockito.Mockito.when;
|
|
23
|
-
|
|
24
|
-
@RunWith(RobolectricTestRunner.class)
|
|
25
|
-
public class AppLaunchHelperTest {
|
|
26
|
-
|
|
27
|
-
private static final String LAUNCHED_FROM_NOTIF_BOOLEAN_EXTRA_NAME = "launchedFromNotification";
|
|
28
|
-
|
|
29
|
-
static class ActivityMock extends Activity {
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
private final String APP_PACKAGE_NAME = "the.package";
|
|
33
|
-
private final String APP_MAIN_ACTIVITY_NAME = ActivityMock.class.getName();
|
|
34
|
-
|
|
35
|
-
@Mock private Context mContext;
|
|
36
|
-
@Mock private PackageManager mPackageManager;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
@Before
|
|
40
|
-
public void setup() throws Exception {
|
|
41
|
-
MockitoAnnotations.initMocks(this);
|
|
42
|
-
when(mContext.getApplicationContext()).thenReturn(mContext);
|
|
43
|
-
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
|
44
|
-
when(mContext.getPackageName()).thenReturn(APP_PACKAGE_NAME);
|
|
45
|
-
|
|
46
|
-
// Set-up the intent (mock) returned by the SDK for getLaunchIntentForPackage()
|
|
47
|
-
Intent intent = mock(Intent.class);
|
|
48
|
-
when(intent.getComponent()).thenReturn(new ComponentName(APP_PACKAGE_NAME, APP_MAIN_ACTIVITY_NAME));
|
|
49
|
-
when(mPackageManager.getLaunchIntentForPackage(eq(APP_PACKAGE_NAME))).thenReturn(intent);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
@Test
|
|
53
|
-
public void getLaunchIntent__returnsCustomIntentWithNotifFlagExtra() throws Exception {
|
|
54
|
-
final AppLaunchHelper uut = getUUT();
|
|
55
|
-
Intent intent = uut.getLaunchIntent(mContext);
|
|
56
|
-
|
|
57
|
-
assertNotNull(intent);
|
|
58
|
-
assertEquals(APP_PACKAGE_NAME, intent.getComponent().getPackageName());
|
|
59
|
-
assertEquals(APP_MAIN_ACTIVITY_NAME, intent.getComponent().getClassName());
|
|
60
|
-
assertEquals(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED, intent.getFlags());
|
|
61
|
-
assertTrue(intent.getBooleanExtra(LAUNCHED_FROM_NOTIF_BOOLEAN_EXTRA_NAME, false));
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
@Test
|
|
65
|
-
public void isLaunchIntentsActivity_activityIsMainLauncherActivity_returnTrue() throws Exception {
|
|
66
|
-
Activity activity = getActivityMock(APP_MAIN_ACTIVITY_NAME);
|
|
67
|
-
|
|
68
|
-
final AppLaunchHelper uut = getUUT();
|
|
69
|
-
boolean result = uut.isLaunchIntentsActivity(activity);
|
|
70
|
-
|
|
71
|
-
assertTrue(result);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
@Test
|
|
75
|
-
public void isLaunchIntentsActivity_activityIsNotMainActivity_returnFalse() throws Exception {
|
|
76
|
-
Activity activity = getActivityMock("other.activity");
|
|
77
|
-
|
|
78
|
-
final AppLaunchHelper uut = getUUT();
|
|
79
|
-
boolean result = uut.isLaunchIntentsActivity(activity);
|
|
80
|
-
|
|
81
|
-
assertFalse(result);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
@Test
|
|
85
|
-
public void isLaunchIntentOfNotification_hasFlagInBundle_returnTrue() throws Exception {
|
|
86
|
-
Intent intent = mock(Intent.class);
|
|
87
|
-
when(intent.getBooleanExtra(eq(LAUNCHED_FROM_NOTIF_BOOLEAN_EXTRA_NAME), eq(false))).thenReturn(true);
|
|
88
|
-
|
|
89
|
-
final AppLaunchHelper uut = getUUT();
|
|
90
|
-
boolean result = uut.isLaunchIntentOfNotification(intent);
|
|
91
|
-
|
|
92
|
-
assertTrue(result);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
@Test
|
|
96
|
-
public void isLaunchIntentOfNotification_noFlagInBundle_returnFalse() throws Exception {
|
|
97
|
-
Intent intent = mock(Intent.class);
|
|
98
|
-
|
|
99
|
-
final AppLaunchHelper uut = getUUT();
|
|
100
|
-
boolean result = uut.isLaunchIntentOfNotification(intent);
|
|
101
|
-
|
|
102
|
-
assertFalse(result);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
protected Activity getActivityMock(String activityClassName) {
|
|
106
|
-
Activity activity = mock(Activity.class);
|
|
107
|
-
when(activity.getPackageManager()).thenReturn(mPackageManager);
|
|
108
|
-
when(activity.getPackageName()).thenReturn(APP_PACKAGE_NAME);
|
|
109
|
-
when(activity.getComponentName()).thenReturn(new ComponentName(APP_PACKAGE_NAME, activityClassName));
|
|
110
|
-
when(activity.getLocalClassName()).thenReturn(activityClassName);
|
|
111
|
-
return activity;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
private AppLaunchHelper getUUT() {
|
|
115
|
-
return new AppLaunchHelper();
|
|
116
|
-
}
|
|
117
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
package com.wix.reactnativenotifications.core;
|
|
2
|
-
|
|
3
|
-
import com.wix.reactnativenotifications.core.notification.PushNotificationProps;
|
|
4
|
-
|
|
5
|
-
import org.junit.Test;
|
|
6
|
-
import org.junit.runner.RunWith;
|
|
7
|
-
import org.mockito.junit.MockitoJUnitRunner;
|
|
8
|
-
|
|
9
|
-
import static org.junit.Assert.*;
|
|
10
|
-
import static org.mockito.Mockito.mock;
|
|
11
|
-
|
|
12
|
-
@RunWith(MockitoJUnitRunner.class)
|
|
13
|
-
public class InitialNotificationHolderTest {
|
|
14
|
-
|
|
15
|
-
@Test
|
|
16
|
-
public void initialState() throws Exception {
|
|
17
|
-
final InitialNotificationHolder uut = createUUT();
|
|
18
|
-
assertNull(uut.get());
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
@Test
|
|
22
|
-
public void setsInitialNotification() throws Exception {
|
|
23
|
-
PushNotificationProps props = mock(PushNotificationProps.class);
|
|
24
|
-
final InitialNotificationHolder uut = createUUT();
|
|
25
|
-
uut.set(props);
|
|
26
|
-
assertEquals(props, uut.get());
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
@Test
|
|
30
|
-
public void clearsInitialNotification() throws Exception {
|
|
31
|
-
PushNotificationProps props = mock(PushNotificationProps.class);
|
|
32
|
-
final InitialNotificationHolder uut = createUUT();
|
|
33
|
-
uut.set(props);
|
|
34
|
-
uut.clear();
|
|
35
|
-
assertNull(uut.get());
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
@Test
|
|
39
|
-
public void replacesInitialNotification() throws Exception {
|
|
40
|
-
PushNotificationProps props1 = mock(PushNotificationProps.class);
|
|
41
|
-
PushNotificationProps props2 = mock(PushNotificationProps.class);
|
|
42
|
-
final InitialNotificationHolder uut = createUUT();
|
|
43
|
-
uut.set(props1);
|
|
44
|
-
uut.set(props2);
|
|
45
|
-
assertNotEquals(props1, props2);
|
|
46
|
-
assertEquals(props2, uut.get());
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
@Test
|
|
50
|
-
public void isALazySingleton() throws Exception {
|
|
51
|
-
final InitialNotificationHolder instance = InitialNotificationHolder.getInstance();
|
|
52
|
-
assertNotNull(instance);
|
|
53
|
-
assertEquals(instance, InitialNotificationHolder.getInstance());
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
private InitialNotificationHolder createUUT() {
|
|
57
|
-
return new InitialNotificationHolder();
|
|
58
|
-
}
|
|
59
|
-
}
|
package/lib/android/app/src/test/java/com/wix/reactnativenotifications/core/JsIOHelperTest.java
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
package com.wix.reactnativenotifications.core;
|
|
2
|
-
|
|
3
|
-
import android.os.Bundle;
|
|
4
|
-
|
|
5
|
-
import com.facebook.react.bridge.ReactContext;
|
|
6
|
-
import com.facebook.react.bridge.WritableMap;
|
|
7
|
-
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
8
|
-
|
|
9
|
-
import org.junit.Before;
|
|
10
|
-
import org.junit.Test;
|
|
11
|
-
import org.junit.runner.RunWith;
|
|
12
|
-
import org.mockito.Mock;
|
|
13
|
-
import org.mockito.junit.MockitoJUnitRunner;
|
|
14
|
-
|
|
15
|
-
import static org.junit.Assert.assertFalse;
|
|
16
|
-
import static org.junit.Assert.assertTrue;
|
|
17
|
-
import static org.mockito.ArgumentMatchers.any;
|
|
18
|
-
import static org.mockito.ArgumentMatchers.anyString;
|
|
19
|
-
import static org.mockito.Mockito.mock;
|
|
20
|
-
import static org.mockito.Mockito.never;
|
|
21
|
-
import static org.mockito.Mockito.verify;
|
|
22
|
-
import static org.mockito.Mockito.when;
|
|
23
|
-
|
|
24
|
-
@RunWith(MockitoJUnitRunner.class)
|
|
25
|
-
public class JsIOHelperTest {
|
|
26
|
-
|
|
27
|
-
@Mock DeviceEventManagerModule.RCTDeviceEventEmitter mRCTDeviceEventEmitter;
|
|
28
|
-
@Mock ReactContext mReactContext;
|
|
29
|
-
|
|
30
|
-
@Before
|
|
31
|
-
public void setup() throws Exception {
|
|
32
|
-
when(mReactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)).thenReturn(mRCTDeviceEventEmitter);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
@Test
|
|
36
|
-
public void sendEventToJS_hasReactContext_emitsEventToJs() throws Exception {
|
|
37
|
-
WritableMap data = mock(WritableMap.class);
|
|
38
|
-
|
|
39
|
-
final JsIOHelper uut = createUUT();
|
|
40
|
-
boolean result = uut.sendEventToJS("my-event", data, mReactContext);
|
|
41
|
-
|
|
42
|
-
assertTrue(result);
|
|
43
|
-
verify(mRCTDeviceEventEmitter).emit("my-event", data);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
@Test
|
|
47
|
-
public void sendEventToJS_noReactContext_returnsFalse() throws Exception {
|
|
48
|
-
WritableMap data = mock(WritableMap.class);
|
|
49
|
-
|
|
50
|
-
final JsIOHelper uut = createUUT();
|
|
51
|
-
boolean result = uut.sendEventToJS("my-event", data, null);
|
|
52
|
-
|
|
53
|
-
assertFalse(result);
|
|
54
|
-
verify(mRCTDeviceEventEmitter, never()).emit(anyString(), any(WritableMap.class));
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
private JsIOHelper createUUT() {
|
|
58
|
-
return new JsIOHelper();
|
|
59
|
-
}
|
|
60
|
-
}
|
|
@@ -1,381 +0,0 @@
|
|
|
1
|
-
package com.wix.reactnativenotifications.core.notification;
|
|
2
|
-
|
|
3
|
-
import android.app.Activity;
|
|
4
|
-
import android.app.Notification;
|
|
5
|
-
import android.app.NotificationChannel;
|
|
6
|
-
import android.app.NotificationManager;
|
|
7
|
-
import android.content.Context;
|
|
8
|
-
import android.content.Intent;
|
|
9
|
-
import android.content.pm.ApplicationInfo;
|
|
10
|
-
import android.content.pm.PackageManager;
|
|
11
|
-
import android.content.res.Resources;
|
|
12
|
-
import android.os.Bundle;
|
|
13
|
-
import android.os.Message;
|
|
14
|
-
|
|
15
|
-
import com.facebook.react.bridge.Arguments;
|
|
16
|
-
import com.facebook.react.bridge.JavaOnlyMap;
|
|
17
|
-
import com.facebook.react.bridge.ReactContext;
|
|
18
|
-
import com.facebook.react.bridge.WritableMap;
|
|
19
|
-
import com.wix.reactnativenotifications.core.AppLaunchHelper;
|
|
20
|
-
import com.wix.reactnativenotifications.core.AppLifecycleFacade;
|
|
21
|
-
import com.wix.reactnativenotifications.core.AppLifecycleFacade.AppVisibilityListener;
|
|
22
|
-
import com.wix.reactnativenotifications.core.InitialNotificationHolder;
|
|
23
|
-
import com.wix.reactnativenotifications.core.JsIOHelper;
|
|
24
|
-
|
|
25
|
-
import org.junit.Before;
|
|
26
|
-
import org.junit.Test;
|
|
27
|
-
import org.junit.runner.RunWith;
|
|
28
|
-
import org.mockito.ArgumentCaptor;
|
|
29
|
-
import org.mockito.ArgumentMatcher;
|
|
30
|
-
import org.mockito.Mock;
|
|
31
|
-
import org.mockito.MockitoAnnotations;
|
|
32
|
-
import org.robolectric.RobolectricTestRunner;
|
|
33
|
-
import org.robolectric.Shadows;
|
|
34
|
-
import org.robolectric.shadows.ShadowNotification;
|
|
35
|
-
|
|
36
|
-
import static org.junit.Assert.assertEquals;
|
|
37
|
-
import static org.junit.Assert.assertNotEquals;
|
|
38
|
-
import static org.mockito.ArgumentMatchers.any;
|
|
39
|
-
import static org.mockito.ArgumentMatchers.anyInt;
|
|
40
|
-
import static org.mockito.ArgumentMatchers.eq;
|
|
41
|
-
import static org.mockito.Mockito.mock;
|
|
42
|
-
import static org.mockito.Mockito.never;
|
|
43
|
-
import static org.mockito.Mockito.times;
|
|
44
|
-
import static org.mockito.Mockito.verify;
|
|
45
|
-
import static org.mockito.Mockito.when;
|
|
46
|
-
import static org.mockito.Mockito.argThat;
|
|
47
|
-
|
|
48
|
-
import java.util.ArrayList;
|
|
49
|
-
import java.util.List;
|
|
50
|
-
|
|
51
|
-
import edu.emory.mathcs.backport.java.util.Arrays;
|
|
52
|
-
|
|
53
|
-
@RunWith(RobolectricTestRunner.class)
|
|
54
|
-
public class PushNotificationTest {
|
|
55
|
-
|
|
56
|
-
private static final String NOTIFICATION_OPENED_EVENT_NAME = "notificationOpened";
|
|
57
|
-
private static final String NOTIFICATION_RECEIVED_EVENT_NAME = "notificationReceived";
|
|
58
|
-
private static final String NOTIFICATION_RECEIVED_BACKGROUND_EVENT_NAME = "notificationReceivedBackground";
|
|
59
|
-
|
|
60
|
-
private static final String DEFAULT_NOTIFICATION_TITLE = "Notification-title";
|
|
61
|
-
private static final String DEFAULT_NOTIFICATION_BODY = "Notification-body";
|
|
62
|
-
|
|
63
|
-
@Mock private ReactContext mReactContext;
|
|
64
|
-
@Mock private Context mContext;
|
|
65
|
-
@Mock private NotificationManager mNotificationManager;
|
|
66
|
-
|
|
67
|
-
private Bundle mResponseBundle;
|
|
68
|
-
private Bundle mNotificationBundle;
|
|
69
|
-
@Mock private Intent mLaunchIntent;
|
|
70
|
-
@Mock private AppLifecycleFacade mAppLifecycleFacade;
|
|
71
|
-
@Mock private AppLaunchHelper mAppLaunchHelper;
|
|
72
|
-
@Mock private JsIOHelper mJsIOHelper;
|
|
73
|
-
@Mock private Resources mResources;
|
|
74
|
-
@Mock private PackageManager mPackageManager;
|
|
75
|
-
|
|
76
|
-
@Before
|
|
77
|
-
public void setup() throws Exception {
|
|
78
|
-
MockitoAnnotations.initMocks(this);
|
|
79
|
-
InitialNotificationHolder.setInstance(mock(InitialNotificationHolder.class));
|
|
80
|
-
|
|
81
|
-
mNotificationBundle = new Bundle();
|
|
82
|
-
mNotificationBundle.putString("title", DEFAULT_NOTIFICATION_TITLE);
|
|
83
|
-
mNotificationBundle.putString("body", DEFAULT_NOTIFICATION_BODY);
|
|
84
|
-
|
|
85
|
-
mResponseBundle = new Bundle();
|
|
86
|
-
mResponseBundle.putBundle("notification", mNotificationBundle);
|
|
87
|
-
|
|
88
|
-
when(mAppLaunchHelper.getLaunchIntent(eq(mContext))).thenReturn(mLaunchIntent);
|
|
89
|
-
|
|
90
|
-
ApplicationInfo ai = mock(ApplicationInfo.class);
|
|
91
|
-
when(mContext.getApplicationInfo()).thenReturn(ai);
|
|
92
|
-
when(mContext.getResources()).thenReturn(mResources);
|
|
93
|
-
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
|
94
|
-
when(mContext.getSystemService(Context.NOTIFICATION_SERVICE)).thenReturn(mNotificationManager);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
@Test
|
|
98
|
-
public void onOpened_noReactContext_launchApp() throws Exception {
|
|
99
|
-
when(mAppLifecycleFacade.isReactInitialized()).thenReturn(false);
|
|
100
|
-
|
|
101
|
-
final PushNotification uut = createUUT();
|
|
102
|
-
uut.onOpened();
|
|
103
|
-
|
|
104
|
-
verify(mContext).startActivity(eq(mLaunchIntent));
|
|
105
|
-
|
|
106
|
-
// The unit shouldn't wait for visibility in this case cause we dont make the extra effort of
|
|
107
|
-
// notifying the notification upon app launch completion (simply cause we dont know when in completes).
|
|
108
|
-
// Instead, the user is expected to use getInitialNotification().
|
|
109
|
-
verify(mAppLifecycleFacade, never()).addVisibilityListener(any(AppVisibilityListener.class));
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
@Test
|
|
113
|
-
public void onOpened_noReactContext_setAsInitialNotification() throws Exception {
|
|
114
|
-
when(mAppLifecycleFacade.isReactInitialized()).thenReturn(false);
|
|
115
|
-
Activity currentActivity = mock(Activity.class);
|
|
116
|
-
when(mReactContext.getCurrentActivity()).thenReturn(currentActivity);
|
|
117
|
-
|
|
118
|
-
final PushNotification uut = createUUT();
|
|
119
|
-
uut.onOpened();
|
|
120
|
-
|
|
121
|
-
verify(InitialNotificationHolder.getInstance()).set(any(PushNotificationProps.class));
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
@Test
|
|
125
|
-
public void onOpened_appInvisible_resumeAppWaitForVisibility() throws Exception {
|
|
126
|
-
setUpBackgroundApp();
|
|
127
|
-
|
|
128
|
-
final PushNotification uut = createUUT();
|
|
129
|
-
uut.onOpened();
|
|
130
|
-
|
|
131
|
-
verify(mContext).startActivity(any(Intent.class));
|
|
132
|
-
verify(mAppLifecycleFacade).addVisibilityListener(any(AppVisibilityListener.class));
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
@Test
|
|
136
|
-
public void onOpened_appInvisible_dontSetInitialNotification() throws Exception {
|
|
137
|
-
setUpBackgroundApp();
|
|
138
|
-
Activity currentActivity = mock(Activity.class);
|
|
139
|
-
when(mReactContext.getCurrentActivity()).thenReturn(currentActivity);
|
|
140
|
-
|
|
141
|
-
final PushNotification uut = createUUT();
|
|
142
|
-
uut.onOpened();
|
|
143
|
-
|
|
144
|
-
verify(InitialNotificationHolder.getInstance(), never()).set(any(PushNotificationProps.class));
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
@Test
|
|
148
|
-
public void onOpened_appGoesVisible_resumeAppAndNotifyJs() throws Exception {
|
|
149
|
-
|
|
150
|
-
// Arrange
|
|
151
|
-
|
|
152
|
-
setUpBackgroundApp();
|
|
153
|
-
|
|
154
|
-
// Act
|
|
155
|
-
|
|
156
|
-
final PushNotification uut = createUUT();
|
|
157
|
-
uut.onOpened();
|
|
158
|
-
|
|
159
|
-
// Hijack and invoke visibility listener
|
|
160
|
-
ArgumentCaptor<AppVisibilityListener> listenerCaptor = ArgumentCaptor.forClass(AppVisibilityListener.class);
|
|
161
|
-
verify(mAppLifecycleFacade).addVisibilityListener(listenerCaptor.capture());
|
|
162
|
-
AppVisibilityListener listener = listenerCaptor.getValue();
|
|
163
|
-
listener.onAppVisible();
|
|
164
|
-
|
|
165
|
-
// Assert
|
|
166
|
-
|
|
167
|
-
verify(mJsIOHelper).sendEventToJS(eq(NOTIFICATION_OPENED_EVENT_NAME), argThat(new isValidResponse(mResponseBundle)), eq(mReactContext));
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
@Test
|
|
171
|
-
public void onOpened_appVisible_notifyJS() throws Exception {
|
|
172
|
-
setUpForegroundApp();
|
|
173
|
-
|
|
174
|
-
final PushNotification uut = createUUT();
|
|
175
|
-
uut.onOpened();
|
|
176
|
-
|
|
177
|
-
verify(mContext, never()).startActivity(any(Intent.class));
|
|
178
|
-
verify(mJsIOHelper).sendEventToJS(eq(NOTIFICATION_OPENED_EVENT_NAME), argThat(new isValidResponse(mResponseBundle)), eq(mReactContext));
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
@Test
|
|
182
|
-
public void onOpened_appVisible_clearNotificationsDrawer() throws Exception {
|
|
183
|
-
verify(mNotificationManager, never()).cancelAll();
|
|
184
|
-
setUpForegroundApp();
|
|
185
|
-
|
|
186
|
-
final PushNotification uut = createUUT();
|
|
187
|
-
uut.onOpened();
|
|
188
|
-
|
|
189
|
-
verify(mNotificationManager, never()).cancelAll();
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
@Test
|
|
193
|
-
public void onOpened_appVisible_dontSetInitialNotification() throws Exception {
|
|
194
|
-
setUpForegroundApp();
|
|
195
|
-
Activity currentActivity = mock(Activity.class);
|
|
196
|
-
when(mReactContext.getCurrentActivity()).thenReturn(currentActivity);
|
|
197
|
-
|
|
198
|
-
final PushNotification uut = createUUT();
|
|
199
|
-
uut.onOpened();
|
|
200
|
-
|
|
201
|
-
verify(InitialNotificationHolder.getInstance(), never()).set(any(PushNotificationProps.class));
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
@Test
|
|
205
|
-
public void onOpened_reactInitializedWithNoActivities_setAsInitialNotification() throws Exception {
|
|
206
|
-
setUpBackgroundApp();
|
|
207
|
-
when(mReactContext.getCurrentActivity()).thenReturn(null); // Just for clarity
|
|
208
|
-
|
|
209
|
-
final PushNotification uut = createUUT();
|
|
210
|
-
uut.onOpened();
|
|
211
|
-
|
|
212
|
-
verify(InitialNotificationHolder.getInstance()).set(any(PushNotificationProps.class));
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
@Test
|
|
216
|
-
public void onReceived_validData_dontPostNotificationAndNotifyJS() throws Exception {
|
|
217
|
-
// Arrange
|
|
218
|
-
|
|
219
|
-
setUpForegroundApp();
|
|
220
|
-
|
|
221
|
-
// Act
|
|
222
|
-
|
|
223
|
-
final PushNotification uut = createUUT();
|
|
224
|
-
uut.onReceived();
|
|
225
|
-
|
|
226
|
-
// Assert
|
|
227
|
-
|
|
228
|
-
ArgumentCaptor<Notification> notificationCaptor = ArgumentCaptor.forClass(Notification.class);
|
|
229
|
-
verify(mNotificationManager, never()).notify(anyInt(), notificationCaptor.capture());
|
|
230
|
-
verify(mJsIOHelper).sendEventToJS(eq(NOTIFICATION_RECEIVED_EVENT_NAME), argThat(new isValidNotification(mNotificationBundle)), eq(mReactContext));
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
@Test
|
|
234
|
-
public void onReceived_validDataForBackgroundApp_postNotificationAndNotifyJs() throws Exception {
|
|
235
|
-
// Arrange
|
|
236
|
-
|
|
237
|
-
setUpBackgroundApp();
|
|
238
|
-
|
|
239
|
-
// Act
|
|
240
|
-
|
|
241
|
-
final PushNotification uut = createUUT();
|
|
242
|
-
uut.onReceived();
|
|
243
|
-
|
|
244
|
-
// Assert
|
|
245
|
-
|
|
246
|
-
ArgumentCaptor<Notification> notificationCaptor = ArgumentCaptor.forClass(Notification.class);
|
|
247
|
-
verify(mNotificationManager).notify(anyInt(), notificationCaptor.capture());
|
|
248
|
-
verify(mJsIOHelper).sendEventToJS(eq(NOTIFICATION_RECEIVED_BACKGROUND_EVENT_NAME), argThat(new isValidNotification(mNotificationBundle)), eq(mReactContext));
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
@Test
|
|
252
|
-
public void onReceived_validDataForDeadApp_postNotificationDontNotifyJS() throws Exception {
|
|
253
|
-
final PushNotification uut = createUUT();
|
|
254
|
-
uut.onReceived();
|
|
255
|
-
|
|
256
|
-
ArgumentCaptor<Notification> notificationCaptor = ArgumentCaptor.forClass(Notification.class);
|
|
257
|
-
verify(mNotificationManager).notify(anyInt(), notificationCaptor.capture());
|
|
258
|
-
verifyNotification(notificationCaptor.getValue());
|
|
259
|
-
verify(mJsIOHelper).sendEventToJS(eq(NOTIFICATION_RECEIVED_BACKGROUND_EVENT_NAME), argThat(new isValidNotification(mNotificationBundle)), eq(null));
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
@Test
|
|
263
|
-
public void onPostRequest_withValidDataButNoId_postNotifications() throws Exception {
|
|
264
|
-
|
|
265
|
-
// Arrange
|
|
266
|
-
|
|
267
|
-
setUpForegroundApp();
|
|
268
|
-
|
|
269
|
-
// Act
|
|
270
|
-
|
|
271
|
-
final PushNotification uut = createUUT();
|
|
272
|
-
uut.onPostRequest(null);
|
|
273
|
-
|
|
274
|
-
// Assert
|
|
275
|
-
|
|
276
|
-
ArgumentCaptor<Notification> notificationCaptor = ArgumentCaptor.forClass(Notification.class);
|
|
277
|
-
verify(mNotificationManager).notify(anyInt(), notificationCaptor.capture());
|
|
278
|
-
verifyNotification(notificationCaptor.getValue());
|
|
279
|
-
|
|
280
|
-
// Shouldn't notify an event on an explicit call to notification posting
|
|
281
|
-
verify(mJsIOHelper, never()).sendEventToJS(eq(NOTIFICATION_RECEIVED_EVENT_NAME), any(Bundle.class), any(ReactContext.class));
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
@Test
|
|
285
|
-
public void onPostRequest_withValidDataButNoId_idsShouldBeUnique() throws Exception {
|
|
286
|
-
createUUT().onPostRequest(null);
|
|
287
|
-
createUUT().onPostRequest(null);
|
|
288
|
-
|
|
289
|
-
ArgumentCaptor<Integer> idsCaptor = ArgumentCaptor.forClass(Integer.class);
|
|
290
|
-
verify(mNotificationManager, times(2)).notify(idsCaptor.capture(), any(Notification.class));
|
|
291
|
-
assertNotEquals(idsCaptor.getAllValues().get(0), idsCaptor.getAllValues().get(1));
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
@Test
|
|
295
|
-
public void onPostRequest_withValidDataAndExplicitId_postNotification() throws Exception {
|
|
296
|
-
final int id = 666;
|
|
297
|
-
|
|
298
|
-
final PushNotification uut = createUUT();
|
|
299
|
-
uut.onPostRequest(id);
|
|
300
|
-
|
|
301
|
-
verify(mNotificationManager).notify(eq(id), any(Notification.class));
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
@Test
|
|
305
|
-
public void onPostRequest_emptyData_postNotification() throws Exception {
|
|
306
|
-
PushNotification uut = createUUT(new Bundle());
|
|
307
|
-
uut.onPostRequest(null);
|
|
308
|
-
|
|
309
|
-
verify(mNotificationManager, never()).notify(anyInt(), any(Notification.class));
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
@Test
|
|
313
|
-
public void onCreate_noExistingChannel_createDefaultChannel() throws Exception {
|
|
314
|
-
createUUT();
|
|
315
|
-
|
|
316
|
-
verify(mNotificationManager).createNotificationChannel(any(NotificationChannel.class));
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
@Test
|
|
320
|
-
public void onCreate_existingChannel_notCreateDefaultChannel() throws Exception {
|
|
321
|
-
List<NotificationChannel> existingChannel = new ArrayList<>();
|
|
322
|
-
existingChannel.add(new NotificationChannel("id", "name", 1));
|
|
323
|
-
when(mNotificationManager.getNotificationChannels()).thenReturn(existingChannel);
|
|
324
|
-
|
|
325
|
-
createUUT();
|
|
326
|
-
|
|
327
|
-
verify(mNotificationManager, never()).createNotificationChannel(any(NotificationChannel.class));
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
protected PushNotification createUUT() {
|
|
331
|
-
return createUUT(mNotificationBundle);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
protected PushNotification createUUT(Bundle bundle) {
|
|
335
|
-
return new PushNotification(mContext, bundle, mAppLifecycleFacade, mAppLaunchHelper, mJsIOHelper);
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
protected void setUpBackgroundApp() {
|
|
339
|
-
when(mAppLifecycleFacade.isReactInitialized()).thenReturn(true);
|
|
340
|
-
when(mAppLifecycleFacade.getRunningReactContext()).thenReturn(mReactContext);
|
|
341
|
-
when(mAppLifecycleFacade.isAppVisible()).thenReturn(false);
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
protected void setUpForegroundApp() {
|
|
345
|
-
when(mAppLifecycleFacade.isReactInitialized()).thenReturn(true);
|
|
346
|
-
when(mAppLifecycleFacade.getRunningReactContext()).thenReturn(mReactContext);
|
|
347
|
-
when(mAppLifecycleFacade.isAppVisible()).thenReturn(true);
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
protected void verifyNotification(Notification notification) {
|
|
351
|
-
ShadowNotification shadowNotification = Shadows.shadowOf(notification);
|
|
352
|
-
assertEquals(shadowNotification.getContentText(), DEFAULT_NOTIFICATION_BODY);
|
|
353
|
-
assertEquals(shadowNotification.getContentTitle(), DEFAULT_NOTIFICATION_TITLE);
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
private class isValidNotification implements ArgumentMatcher<Bundle> {
|
|
357
|
-
private Bundle left;
|
|
358
|
-
|
|
359
|
-
protected isValidNotification(Bundle left) {
|
|
360
|
-
this.left = left;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
@Override
|
|
364
|
-
public boolean matches(Bundle right) {
|
|
365
|
-
return right.getString("body").equals(left.getString("body"));
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
private class isValidResponse implements ArgumentMatcher<Bundle> {
|
|
370
|
-
private Bundle left;
|
|
371
|
-
|
|
372
|
-
protected isValidResponse(Bundle left) {
|
|
373
|
-
this.left = left;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
@Override
|
|
377
|
-
public boolean matches(Bundle right) {
|
|
378
|
-
return right.getBundle("notification").getString("body").equals(left.getBundle("notification").getString("body"));
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
}
|