Skip to content

Instantly share code, notes, and snippets.

@igorescodro
Last active May 2, 2022 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igorescodro/31ce370f47ac3309995ae4131285e0d6 to your computer and use it in GitHub Desktop.
Save igorescodro/31ce370f47ac3309995ae4131285e0d6 to your computer and use it in GitHub Desktop.
@Test
fun test_markAsReadViaNotificationActions() {
// Send the notification
val id = 99
val name = "New message received from Bruno"
myNotification.send(id = id, name = name)
val manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
// Wait until the active notification list has a new one
composeTestRule.waitUntil { manager.activeNotifications.isNotEmpty() }
// Run the PendingIntent in the "Mark as read" action button
manager.activeNotifications.first().notification.actions[0].actionIntent.send()
// Validate the message is mark as read
Assert.assertTrue(messageRepository.getLatestMessage(id = id).isRead())
// Validate the notification was dismissed
Assert.assertTrue(manager.activeNotifications.isEmpty())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment