Skip to content

Commit 7c199a6

Browse files
committed
Add unit test for dismissing individual groupless summary notifications
1 parent ba9c717 commit 7c199a6

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

OneSignalSDK/unittest/src/test/java/com/test/onesignal/GenerateNotificationRunner.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@
7474
import android.net.Uri;
7575
import android.os.Build;
7676
import android.os.Bundle;
77-
import android.os.SystemClock;
7877
import android.util.Log;
7978

8079
import androidx.annotation.NonNull;
@@ -450,6 +449,34 @@ public void testGrouplessSummaryNotificationIsDismissedOnClear() throws Exceptio
450449
assertEquals(0, postedNotifs.size());
451450
}
452451

452+
@Test
453+
@Config(sdk = Build.VERSION_CODES.N, shadows = { ShadowGenerateNotification.class })
454+
public void testIndividualGrouplessSummaryNotificationDismissal() throws Exception {
455+
OneSignal.setAppId("b2f7f966-d8cc-11e4-bed1-df8f05be55ba");
456+
OneSignal.initWithContext(blankActivity.getApplicationContext());
457+
threadAndTaskWait();
458+
459+
// Add 4 groupless notifications
460+
postNotificationWithOptionalGroup(4, null);
461+
threadAndTaskWait();
462+
463+
// Obtain the posted notifications
464+
Map<Integer, PostedNotification> postedNotifs = ShadowRoboNotificationManager.notifications;
465+
Iterator<Map.Entry<Integer, PostedNotification>> iterator = postedNotifs.entrySet().iterator();
466+
Map.Entry<Integer, PostedNotification> entry = iterator.next();
467+
Map.Entry<Integer, PostedNotification> entry2 = iterator.next();
468+
Map.Entry<Integer, PostedNotification> entry3 = iterator.next();
469+
Map.Entry<Integer, PostedNotification> entry4 = iterator.next();
470+
Integer id4 = entry4.getKey();
471+
assertNotNull(id4);
472+
473+
assertEquals(5, postedNotifs.size());
474+
// Clear a OneSignal Notification
475+
OneSignal.removeNotification(id4);
476+
threadAndTaskWait();
477+
assertEquals(4, postedNotifs.size());
478+
}
479+
453480
@Test
454481
@Config(sdk = Build.VERSION_CODES.LOLLIPOP, shadows = { ShadowGenerateNotification.class })
455482
public void testNotifDismissAllOnGroupSummaryClickForAndroidUnderM() throws Exception {

0 commit comments

Comments
 (0)