Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
react-native-notifications
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Jira
Jira
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
冷佳娟
react-native-notifications
Commits
12dff6de
Commit
12dff6de
authored
Nov 27, 2016
by
d4vidi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add java-code tests
parent
35a89f7e
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
208 additions
and
54 deletions
+208
-54
android/build.gradle
android/build.gradle
+6
-1
android/src/main/java/com/wix/reactnativenotifications/core/AppLaunchHelper.java
...om/wix/reactnativenotifications/core/AppLaunchHelper.java
+3
-3
android/src/main/java/com/wix/reactnativenotifications/core/ProxyService.java
...a/com/wix/reactnativenotifications/core/ProxyService.java
+5
-0
android/src/main/java/com/wix/reactnativenotifications/core/ReactContextAdapter.java
...ix/reactnativenotifications/core/ReactContextAdapter.java
+51
-0
android/src/main/java/com/wix/reactnativenotifications/core/notification/INotificationsApplication.java
...ications/core/notification/INotificationsApplication.java
+2
-1
android/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java
...tivenotifications/core/notification/PushNotification.java
+20
-43
android/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/PushNotificationsDrawer.java
...ions/core/notificationdrawer/PushNotificationsDrawer.java
+12
-6
android/src/test/java/com/wix/reactnativenotifications/core/notification/PushNotificationTest.java
...notifications/core/notification/PushNotificationTest.java
+109
-0
No files found.
android/build.gradle
View file @
12dff6de
...
@@ -16,13 +16,18 @@ android {
...
@@ -16,13 +16,18 @@ android {
proguardFiles
getDefaultProguardFile
(
'proguard-android.txt'
),
'proguard-rules.pro'
proguardFiles
getDefaultProguardFile
(
'proguard-android.txt'
),
'proguard-rules.pro'
}
}
}
}
testOptions
{
unitTests
.
returnDefaultValues
=
true
}
}
}
dependencies
{
dependencies
{
// Google's GCM.
// Google's GCM.
compile
"com.google.android.gms:play-services-gcm:9.4.0"
compile
'com.google.android.gms:play-services-gcm:9.4.0'
compile
'com.facebook.react:react-native:+'
compile
'com.facebook.react:react-native:+'
testCompile
'junit:junit:4.12'
testCompile
'junit:junit:4.12'
testCompile
'org.mockito:mockito-core:2.+'
}
}
android/src/main/java/com/wix/reactnativenotifications/core/AppLaunchHelper.java
View file @
12dff6de
...
@@ -10,7 +10,7 @@ public class AppLaunchHelper {
...
@@ -10,7 +10,7 @@ public class AppLaunchHelper {
private
static
final
String
LAUNCH_FLAG_KEY_NAME
=
"launchedFromNotification"
;
private
static
final
String
LAUNCH_FLAG_KEY_NAME
=
"launchedFromNotification"
;
public
static
Intent
getLaunchIntent
(
Context
appContext
)
{
public
Intent
getLaunchIntent
(
Context
appContext
)
{
try
{
try
{
// The desired behavior upon notification opening is as follows:
// The desired behavior upon notification opening is as follows:
// - If app is in foreground (and possibly has several activities in stack), simply keep it as-is in foreground.
// - If app is in foreground (and possibly has several activities in stack), simply keep it as-is in foreground.
...
@@ -32,14 +32,14 @@ public class AppLaunchHelper {
...
@@ -32,14 +32,14 @@ public class AppLaunchHelper {
}
}
}
}
public
static
boolean
isLaunchIntentsActivity
(
Activity
activity
)
{
public
boolean
isLaunchIntentsActivity
(
Activity
activity
)
{
final
Intent
helperIntent
=
activity
.
getPackageManager
().
getLaunchIntentForPackage
(
activity
.
getPackageName
());
final
Intent
helperIntent
=
activity
.
getPackageManager
().
getLaunchIntentForPackage
(
activity
.
getPackageName
());
final
String
activityName
=
activity
.
getComponentName
().
getClassName
();
final
String
activityName
=
activity
.
getComponentName
().
getClassName
();
final
String
launchIntentActivityName
=
helperIntent
.
getComponent
().
getClassName
();
final
String
launchIntentActivityName
=
helperIntent
.
getComponent
().
getClassName
();
return
activityName
.
equals
(
launchIntentActivityName
);
return
activityName
.
equals
(
launchIntentActivityName
);
}
}
public
static
boolean
isLaunchIntent
(
Intent
intent
)
{
public
boolean
isLaunchIntent
(
Intent
intent
)
{
return
intent
.
getBooleanExtra
(
LAUNCH_FLAG_KEY_NAME
,
false
);
return
intent
.
getBooleanExtra
(
LAUNCH_FLAG_KEY_NAME
,
false
);
}
}
}
}
android/src/main/java/com/wix/reactnativenotifications/core/ProxyService.java
View file @
12dff6de
...
@@ -7,6 +7,8 @@ import android.util.Log;
...
@@ -7,6 +7,8 @@ import android.util.Log;
import
com.wix.reactnativenotifications.core.notification.IPushNotification
;
import
com.wix.reactnativenotifications.core.notification.IPushNotification
;
import
com.wix.reactnativenotifications.core.notification.PushNotification
;
import
com.wix.reactnativenotifications.core.notification.PushNotification
;
import
com.wix.reactnativenotifications.core.notificationdrawer.IPushNotificationsDrawer
;
import
com.wix.reactnativenotifications.core.notificationdrawer.PushNotificationsDrawer
;
public
class
ProxyService
extends
IntentService
{
public
class
ProxyService
extends
IntentService
{
...
@@ -24,5 +26,8 @@ public class ProxyService extends IntentService {
...
@@ -24,5 +26,8 @@ public class ProxyService extends IntentService {
if
(
pushNotification
!=
null
)
{
if
(
pushNotification
!=
null
)
{
pushNotification
.
onOpened
();
pushNotification
.
onOpened
();
}
}
final
IPushNotificationsDrawer
pushNotificationDrawer
=
PushNotificationsDrawer
.
get
(
this
);
pushNotificationDrawer
.
onNotificationOpened
();
}
}
}
}
android/src/main/java/com/wix/reactnativenotifications/core/ReactContextAdapter.java
0 → 100644
View file @
12dff6de
package
com.wix.reactnativenotifications.core
;
import
android.content.Context
;
import
android.os.Bundle
;
import
com.facebook.react.ReactApplication
;
import
com.facebook.react.ReactInstanceManager
;
import
com.facebook.react.ReactNativeHost
;
import
com.facebook.react.bridge.Arguments
;
import
com.facebook.react.bridge.ReactContext
;
import
com.facebook.react.bridge.WritableMap
;
import
com.facebook.react.modules.core.DeviceEventManagerModule
;
public
class
ReactContextAdapter
{
public
ReactContext
getRunningReactContext
(
Context
context
)
{
final
ReactNativeHost
rnHost
=
((
ReactApplication
)
context
.
getApplicationContext
()).
getReactNativeHost
();
if
(!
rnHost
.
hasInstance
())
{
return
null
;
}
final
ReactInstanceManager
instanceManager
=
rnHost
.
getReactInstanceManager
();
final
ReactContext
reactContext
=
instanceManager
.
getCurrentReactContext
();
if
(
reactContext
==
null
||
!
reactContext
.
hasActiveCatalystInstance
())
{
return
null
;
}
return
reactContext
;
}
public
void
sendEventToJS
(
String
eventName
,
Bundle
data
,
Context
context
)
{
final
ReactContext
reactContext
=
getRunningReactContext
(
context
);
if
(
reactContext
!=
null
)
{
sendEventToJS
(
eventName
,
data
,
reactContext
);
}
}
public
void
sendEventToJS
(
String
eventName
,
WritableMap
data
,
Context
context
)
{
final
ReactContext
reactContext
=
getRunningReactContext
(
context
);
if
(
reactContext
!=
null
)
{
sendEventToJS
(
eventName
,
data
,
reactContext
);
}
}
public
void
sendEventToJS
(
String
eventName
,
Bundle
data
,
ReactContext
reactContext
)
{
sendEventToJS
(
eventName
,
Arguments
.
fromBundle
(
data
),
reactContext
);
}
public
void
sendEventToJS
(
String
eventName
,
WritableMap
data
,
ReactContext
reactContext
)
{
reactContext
.
getJSModule
(
DeviceEventManagerModule
.
RCTDeviceEventEmitter
.
class
).
emit
(
eventName
,
data
);
}
}
android/src/main/java/com/wix/reactnativenotifications/core/notification/INotificationsApplication.java
View file @
12dff6de
...
@@ -3,8 +3,9 @@ package com.wix.reactnativenotifications.core.notification;
...
@@ -3,8 +3,9 @@ package com.wix.reactnativenotifications.core.notification;
import
android.content.Context
;
import
android.content.Context
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
com.wix.reactnativenotifications.core.AppLaunchHelper
;
import
com.wix.reactnativenotifications.core.AppLifecycleFacade
;
import
com.wix.reactnativenotifications.core.AppLifecycleFacade
;
public
interface
INotificationsApplication
{
public
interface
INotificationsApplication
{
IPushNotification
getPushNotification
(
Context
context
,
Bundle
bundle
,
AppLifecycleFacade
facade
);
IPushNotification
getPushNotification
(
Context
context
,
Bundle
bundle
,
AppLifecycleFacade
defaultFacade
,
AppLaunchHelper
defaultAppLaunchHelper
);
}
}
android/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java
View file @
12dff6de
...
@@ -20,7 +20,7 @@ import com.wix.reactnativenotifications.core.AppLifecycleFacade.AppVisibilityLis
...
@@ -20,7 +20,7 @@ import com.wix.reactnativenotifications.core.AppLifecycleFacade.AppVisibilityLis
import
com.wix.reactnativenotifications.core.InitialNotification
;
import
com.wix.reactnativenotifications.core.InitialNotification
;
import
com.wix.reactnativenotifications.core.NotificationIntentAdapter
;
import
com.wix.reactnativenotifications.core.NotificationIntentAdapter
;
import
com.wix.reactnativenotifications.core.ProxyService
;
import
com.wix.reactnativenotifications.core.ProxyService
;
import
com.wix.reactnativenotifications.core.
notificationdrawer.PushNotificationsDraw
er
;
import
com.wix.reactnativenotifications.core.
ReactContextAdapt
er
;
import
static
com
.
wix
.
reactnativenotifications
.
Defs
.
NOTIFICATION_OPENED_EVENT_NAME
;
import
static
com
.
wix
.
reactnativenotifications
.
Defs
.
NOTIFICATION_OPENED_EVENT_NAME
;
import
static
com
.
wix
.
reactnativenotifications
.
Defs
.
NOTIFICATION_RECEIVED_EVENT_NAME
;
import
static
com
.
wix
.
reactnativenotifications
.
Defs
.
NOTIFICATION_RECEIVED_EVENT_NAME
;
...
@@ -29,6 +29,8 @@ public class PushNotification implements IPushNotification {
...
@@ -29,6 +29,8 @@ public class PushNotification implements IPushNotification {
final
protected
Context
mContext
;
final
protected
Context
mContext
;
final
protected
AppLifecycleFacade
mAppLifecycleFacade
;
final
protected
AppLifecycleFacade
mAppLifecycleFacade
;
final
protected
AppLaunchHelper
mAppLaunchHelper
;
final
protected
ReactContextAdapter
mReactContextAdapter
;
final
protected
PushNotificationProps
mNotificationProps
;
final
protected
PushNotificationProps
mNotificationProps
;
final
protected
AppVisibilityListener
mAppVisibilityListener
=
new
AppVisibilityListener
()
{
final
protected
AppVisibilityListener
mAppVisibilityListener
=
new
AppVisibilityListener
()
{
@Override
@Override
...
@@ -42,18 +44,24 @@ public class PushNotification implements IPushNotification {
...
@@ -42,18 +44,24 @@ public class PushNotification implements IPushNotification {
}
}
};
};
protected
PushNotification
(
Context
context
,
Bundle
bundle
,
AppLifecycleFacade
appLifecycleFacade
)
{
public
static
IPushNotification
get
(
Context
context
,
Bundle
bundle
,
AppLifecycleFacade
facade
)
{
mContext
=
context
;
return
PushNotification
.
get
(
context
,
bundle
,
facade
,
new
AppLaunchHelper
());
mAppLifecycleFacade
=
appLifecycleFacade
;
mNotificationProps
=
createProps
(
bundle
);
}
}
public
static
IPushNotification
get
(
Context
context
,
Bundle
bundle
,
AppLifecycleFacade
facade
)
{
public
static
IPushNotification
get
(
Context
context
,
Bundle
bundle
,
AppLifecycleFacade
facade
,
AppLaunchHelper
appLaunchHelper
)
{
Context
appContext
=
context
.
getApplicationContext
();
Context
appContext
=
context
.
getApplicationContext
();
if
(
appContext
instanceof
INotificationsApplication
)
{
if
(
appContext
instanceof
INotificationsApplication
)
{
return
((
INotificationsApplication
)
appContext
).
getPushNotification
(
context
,
bundle
,
facade
);
return
((
INotificationsApplication
)
appContext
).
getPushNotification
(
context
,
bundle
,
facade
,
appLaunchHelper
);
}
return
new
PushNotification
(
context
,
bundle
,
facade
,
appLaunchHelper
,
new
ReactContextAdapter
());
}
}
return
new
PushNotification
(
context
,
bundle
,
facade
);
protected
PushNotification
(
Context
context
,
Bundle
bundle
,
AppLifecycleFacade
appLifecycleFacade
,
AppLaunchHelper
appLaunchHelper
,
ReactContextAdapter
reactContextAdapter
)
{
mContext
=
context
;
mAppLifecycleFacade
=
appLifecycleFacade
;
mAppLaunchHelper
=
appLaunchHelper
;
mReactContextAdapter
=
reactContextAdapter
;
mNotificationProps
=
createProps
(
bundle
);
}
}
@Override
@Override
...
@@ -65,7 +73,6 @@ public class PushNotification implements IPushNotification {
...
@@ -65,7 +73,6 @@ public class PushNotification implements IPushNotification {
@Override
@Override
public
void
onOpened
()
{
public
void
onOpened
()
{
digestNotification
();
digestNotification
();
PushNotificationsDrawer
.
get
(
mContext
).
onNotificationOpened
();
}
}
@Override
@Override
...
@@ -91,7 +98,7 @@ public class PushNotification implements IPushNotification {
...
@@ -91,7 +98,7 @@ public class PushNotification implements IPushNotification {
return
;
return
;
}
}
final
ReactContext
reactContext
=
getRunningReactContext
(
);
final
ReactContext
reactContext
=
mReactContextAdapter
.
getRunningReactContext
(
mContext
);
if
(
reactContext
.
getCurrentActivity
()
==
null
)
{
if
(
reactContext
.
getCurrentActivity
()
==
null
)
{
setAsInitialNotification
();
setAsInitialNotification
();
}
}
...
@@ -161,46 +168,16 @@ public class PushNotification implements IPushNotification {
...
@@ -161,46 +168,16 @@ public class PushNotification implements IPushNotification {
return
(
int
)
System
.
currentTimeMillis
();
return
(
int
)
System
.
currentTimeMillis
();
}
}
protected
ReactContext
getRunningReactContext
()
{
final
ReactNativeHost
rnHost
=
((
ReactApplication
)
mContext
.
getApplicationContext
()).
getReactNativeHost
();
if
(!
rnHost
.
hasInstance
())
{
return
null
;
}
final
ReactInstanceManager
instanceManager
=
rnHost
.
getReactInstanceManager
();
final
ReactContext
reactContext
=
instanceManager
.
getCurrentReactContext
();
if
(
reactContext
==
null
||
!
reactContext
.
hasActiveCatalystInstance
())
{
return
null
;
}
return
reactContext
;
}
private
void
notifyReceivedToJS
()
{
private
void
notifyReceivedToJS
()
{
notifyJS
(
NOTIFICATION_RECEIVED_EVENT_NAME
,
null
);
mReactContextAdapter
.
sendEventToJS
(
NOTIFICATION_RECEIVED_EVENT_NAME
,
mNotificationProps
.
asBundle
(),
mContext
);
}
}
private
void
notifyOpenedToJS
()
{
private
void
notifyOpenedToJS
()
{
notifyOpenedToJS
(
null
);
mReactContextAdapter
.
sendEventToJS
(
NOTIFICATION_OPENED_EVENT_NAME
,
mNotificationProps
.
asBundle
(),
mContext
);
}
private
void
notifyOpenedToJS
(
ReactContext
reactContext
)
{
notifyJS
(
NOTIFICATION_OPENED_EVENT_NAME
,
reactContext
);
}
private
void
notifyJS
(
String
eventName
,
ReactContext
reactContext
)
{
if
(
reactContext
==
null
)
{
reactContext
=
getRunningReactContext
();
}
if
(
reactContext
!=
null
)
{
final
WritableMap
notificationAsMap
=
Arguments
.
fromBundle
(
mNotificationProps
.
asBundle
());
reactContext
.
getJSModule
(
DeviceEventManagerModule
.
RCTDeviceEventEmitter
.
class
).
emit
(
eventName
,
notificationAsMap
);
}
}
}
protected
void
launchOrResumeApp
()
{
protected
void
launchOrResumeApp
()
{
final
Intent
intent
=
AppLaunchHelper
.
getLaunchIntent
(
mContext
);
final
Intent
intent
=
m
AppLaunchHelper
.
getLaunchIntent
(
mContext
);
mContext
.
startActivity
(
intent
);
mContext
.
startActivity
(
intent
);
}
}
}
}
android/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/PushNotificationsDrawer.java
View file @
12dff6de
...
@@ -10,18 +10,24 @@ import com.wix.reactnativenotifications.core.InitialNotification;
...
@@ -10,18 +10,24 @@ import com.wix.reactnativenotifications.core.InitialNotification;
public
class
PushNotificationsDrawer
implements
IPushNotificationsDrawer
{
public
class
PushNotificationsDrawer
implements
IPushNotificationsDrawer
{
final
protected
Context
mContext
;
final
protected
Context
mContext
;
final
protected
AppLaunchHelper
mAppLaunchHelper
;
public
PushNotificationsDrawer
(
Context
context
)
{
public
static
IPushNotificationsDrawer
get
(
Context
context
)
{
mContext
=
context
;
return
PushNotificationsDrawer
.
get
(
context
,
new
AppLaunchHelper
())
;
}
}
public
static
IPushNotificationsDrawer
get
(
Context
context
)
{
public
static
IPushNotificationsDrawer
get
(
Context
context
,
AppLaunchHelper
appLaunchHelper
)
{
final
Context
appContext
=
context
.
getApplicationContext
();
final
Context
appContext
=
context
.
getApplicationContext
();
if
(
appContext
instanceof
INotificationsDrawerApplication
)
{
if
(
appContext
instanceof
INotificationsDrawerApplication
)
{
return
((
INotificationsDrawerApplication
)
appContext
).
getPushNotificationsDrawer
(
context
);
return
((
INotificationsDrawerApplication
)
appContext
).
getPushNotificationsDrawer
(
context
);
}
}
return
new
PushNotificationsDrawer
(
context
);
return
new
PushNotificationsDrawer
(
context
,
appLaunchHelper
);
}
protected
PushNotificationsDrawer
(
Context
context
,
AppLaunchHelper
appLaunchHelper
)
{
mContext
=
context
;
mAppLaunchHelper
=
appLaunchHelper
;
}
}
@Override
@Override
...
@@ -36,8 +42,8 @@ public class PushNotificationsDrawer implements IPushNotificationsDrawer {
...
@@ -36,8 +42,8 @@ public class PushNotificationsDrawer implements IPushNotificationsDrawer {
@Override
@Override
public
void
onNewActivity
(
Activity
activity
)
{
public
void
onNewActivity
(
Activity
activity
)
{
if
(
AppLaunchHelper
.
isLaunchIntentsActivity
(
activity
)
&&
if
(
m
AppLaunchHelper
.
isLaunchIntentsActivity
(
activity
)
&&
!
AppLaunchHelper
.
isLaunchIntent
(
activity
.
getIntent
()))
{
!
m
AppLaunchHelper
.
isLaunchIntent
(
activity
.
getIntent
()))
{
InitialNotification
.
clear
();
InitialNotification
.
clear
();
}
}
}
}
...
...
android/src/test/java/com/wix/reactnativenotifications/core/notification/PushNotificationTest.java
0 → 100644
View file @
12dff6de
package
com.wix.reactnativenotifications.core.notification
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.os.Bundle
;
import
com.facebook.react.bridge.ReactContext
;
import
com.wix.reactnativenotifications.core.AppLaunchHelper
;
import
com.wix.reactnativenotifications.core.AppLifecycleFacade
;
import
com.wix.reactnativenotifications.core.AppLifecycleFacade.AppVisibilityListener
;
import
com.wix.reactnativenotifications.core.ReactContextAdapter
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.Mock
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
ArgumentMatchers
.
eq
;
import
static
org
.
mockito
.
Mockito
.
never
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
@RunWith
(
MockitoJUnitRunner
.
Silent
.
class
)
public
class
PushNotificationTest
{
@Mock
private
ReactContext
mReactContext
;
@Mock
private
Context
mContext
;
@Mock
private
Bundle
mDefaultBundle
;
@Mock
private
Intent
mLaunchIntent
;
@Mock
private
AppLifecycleFacade
mAppLifecycleFacade
;
@Mock
private
AppLaunchHelper
mAppLaunchHelper
;
@Mock
private
ReactContextAdapter
mReactContextAdapter
;
@Before
public
void
setup
()
throws
Exception
{
when
(
mDefaultBundle
.
getString
(
eq
(
"title"
))).
thenReturn
(
"Notification-title"
);
when
(
mDefaultBundle
.
getString
(
eq
(
"body"
))).
thenReturn
(
"Notification-body"
);
when
(
mDefaultBundle
.
clone
()).
thenReturn
(
mDefaultBundle
);
when
(
mAppLaunchHelper
.
getLaunchIntent
(
eq
(
mContext
))).
thenReturn
(
mLaunchIntent
);
when
(
mReactContextAdapter
.
getRunningReactContext
(
mContext
)).
thenReturn
(
mReactContext
);
}
@Test
public
void
onOpened_noReactContext_launchApp
()
throws
Exception
{
when
(
mAppLifecycleFacade
.
isReactInitialized
()).
thenReturn
(
false
);
final
PushNotification
uut
=
createUUT
();
uut
.
onOpened
();
verify
(
mContext
).
startActivity
(
eq
(
mLaunchIntent
));
}
@Test
public
void
onOpened_appInvisible_resumeAppWaitForVisibility
()
throws
Exception
{
when
(
mAppLifecycleFacade
.
isReactInitialized
()).
thenReturn
(
true
);
when
(
mAppLifecycleFacade
.
isAppVisible
()).
thenReturn
(
false
);
final
PushNotification
uut
=
createUUT
();
uut
.
onOpened
();
verify
(
mContext
).
startActivity
(
any
(
Intent
.
class
));
verify
(
mAppLifecycleFacade
).
addVisibilityListener
(
any
(
AppVisibilityListener
.
class
));
}
@Test
public
void
onOpened_appGoesVisible_resumeAppAndNotifyJs
()
throws
Exception
{
// Arrange
when
(
mAppLifecycleFacade
.
isReactInitialized
()).
thenReturn
(
true
);
when
(
mAppLifecycleFacade
.
isAppVisible
()).
thenReturn
(
false
);
// Act
final
PushNotification
uut
=
createUUT
();
uut
.
onOpened
();
// Hijack and invoke visibility listener
ArgumentCaptor
<
AppVisibilityListener
>
listenerCaptor
=
ArgumentCaptor
.
forClass
(
AppVisibilityListener
.
class
);
verify
(
mAppLifecycleFacade
).
addVisibilityListener
(
listenerCaptor
.
capture
());
AppVisibilityListener
listener
=
listenerCaptor
.
getValue
();
listener
.
onAppVisible
();
// Assert
verify
(
mReactContextAdapter
).
sendEventToJS
(
eq
(
"notificationOpened"
),
eq
(
mDefaultBundle
),
eq
(
mContext
));
}
@Test
public
void
onOpened_appVisible_notifyJS
()
throws
Exception
{
when
(
mAppLifecycleFacade
.
isReactInitialized
()).
thenReturn
(
true
);
when
(
mAppLifecycleFacade
.
isAppVisible
()).
thenReturn
(
true
);
final
PushNotification
uut
=
createUUT
();
uut
.
onOpened
();
verify
(
mContext
,
never
()).
startActivity
(
any
(
Intent
.
class
));
verify
(
mReactContextAdapter
).
sendEventToJS
(
eq
(
"notificationOpened"
),
eq
(
mDefaultBundle
),
eq
(
mContext
));
}
protected
PushNotification
createUUT
()
{
return
new
PushNotification
(
mContext
,
mDefaultBundle
,
mAppLifecycleFacade
,
mAppLaunchHelper
,
mReactContextAdapter
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment