Improve FakeActiveNotificationsProvider.

This commit is contained in:
Benoit Marty
2024-08-28 11:06:26 +02:00
parent 0037552f77
commit e38d882d42
2 changed files with 16 additions and 10 deletions

View File

@@ -72,7 +72,7 @@ class DefaultNotificationDrawerManagerTest {
// For now just call all the API. Later, add more valuable tests.
val matrixUser = aMatrixUser(id = A_SESSION_ID.value, displayName = "alice", avatarUrl = "mxc://data")
val mockRoomGroupMessageCreator = FakeRoomGroupMessageCreator(
createRoomMessageResult = lambdaRecorder { user, _, roomId, _, existingNotification, ->
createRoomMessageResult = lambdaRecorder { user, _, roomId, _, existingNotification ->
assertThat(user).isEqualTo(matrixUser)
assertThat(roomId).isEqualTo(A_ROOM_ID)
assertThat(existingNotification).isNull()
@@ -167,11 +167,12 @@ class DefaultNotificationDrawerManagerTest {
}
val summaryId = NotificationIdProvider.getSummaryNotificationId(A_SESSION_ID)
val activeNotificationsProvider = FakeActiveNotificationsProvider(
mutableListOf(
getSummaryNotificationResult = {
mockk {
every { id } returns summaryId
}
)
},
countResult = { 1 },
)
val defaultNotificationDrawerManager = createDefaultNotificationDrawerManager(
notificationManager = notificationManager,

View File

@@ -22,29 +22,34 @@ import io.element.android.libraries.matrix.api.core.SessionId
import io.element.android.libraries.push.impl.notifications.ActiveNotificationsProvider
class FakeActiveNotificationsProvider(
var activeNotifications: MutableList<StatusBarNotification> = mutableListOf(),
private val getMessageNotificationsForRoomResult: (SessionId, RoomId) -> List<StatusBarNotification> = { _, _ -> emptyList() },
private val getNotificationsForSessionResult: (SessionId) -> List<StatusBarNotification> = { emptyList() },
private val getMembershipNotificationForSessionResult: (SessionId) -> List<StatusBarNotification> = { emptyList() },
private val getMembershipNotificationForRoomResult: (SessionId, RoomId) -> List<StatusBarNotification> = { _, _ -> emptyList() },
private val getSummaryNotificationResult: (SessionId) -> StatusBarNotification? = { null },
private val countResult: (SessionId) -> Int = { 0 },
) : ActiveNotificationsProvider {
override fun getMessageNotificationsForRoom(sessionId: SessionId, roomId: RoomId): List<StatusBarNotification> {
return activeNotifications
return getMessageNotificationsForRoomResult(sessionId, roomId)
}
override fun getNotificationsForSession(sessionId: SessionId): List<StatusBarNotification> {
return activeNotifications
return getNotificationsForSessionResult(sessionId)
}
override fun getMembershipNotificationForSession(sessionId: SessionId): List<StatusBarNotification> {
return activeNotifications
return getMembershipNotificationForSessionResult(sessionId)
}
override fun getMembershipNotificationForRoom(sessionId: SessionId, roomId: RoomId): List<StatusBarNotification> {
return activeNotifications
return getMembershipNotificationForRoomResult(sessionId, roomId)
}
override fun getSummaryNotification(sessionId: SessionId): StatusBarNotification? {
return activeNotifications.firstOrNull()
return getSummaryNotificationResult(sessionId)
}
override fun count(sessionId: SessionId): Int {
return activeNotifications.size
return countResult(sessionId)
}
}