Use TestScope.backgroundScope
This commit is contained in:
parent
04e5d684d4
commit
3382aa2cfc
2 changed files with 3 additions and 20 deletions
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
package io.element.android.libraries.push.impl.notifications
|
||||
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import dev.zacsweers.metro.AppScope
|
||||
import dev.zacsweers.metro.ContributesBinding
|
||||
import dev.zacsweers.metro.SingleIn
|
||||
|
|
@ -31,7 +30,6 @@ import io.element.android.services.appnavstate.api.AppNavigationStateService
|
|||
import io.element.android.services.appnavstate.api.NavigationState
|
||||
import io.element.android.services.appnavstate.api.currentSessionId
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
|
||||
|
|
@ -54,25 +52,17 @@ class DefaultNotificationDrawerManager(
|
|||
private val imageLoaderHolder: ImageLoaderHolder,
|
||||
private val activeNotificationsProvider: ActiveNotificationsProvider,
|
||||
) : NotificationCleaner {
|
||||
private var appNavigationStateObserver: Job? = null
|
||||
|
||||
// TODO EAx add a setting per user for this
|
||||
private var useCompleteNotificationFormat = true
|
||||
|
||||
init {
|
||||
// Observe application state
|
||||
appNavigationStateObserver = coroutineScope.launch {
|
||||
coroutineScope.launch {
|
||||
appNavigationStateService.appNavigationState
|
||||
.collect { onAppNavigationStateChange(it.navigationState) }
|
||||
}
|
||||
}
|
||||
|
||||
// For test only
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
||||
internal fun destroy() {
|
||||
appNavigationStateObserver?.cancel()
|
||||
}
|
||||
|
||||
private var currentAppNavigationState: NavigationState? = null
|
||||
|
||||
private fun onAppNavigationStateChange(navigationState: NavigationState) {
|
||||
|
|
|
|||
|
|
@ -56,7 +56,6 @@ class DefaultNotificationDrawerManagerTest {
|
|||
fun `clearAllEvents should have no effect when queue is empty`() = runTest {
|
||||
val defaultNotificationDrawerManager = createDefaultNotificationDrawerManager()
|
||||
defaultNotificationDrawerManager.clearAllEvents(A_SESSION_ID)
|
||||
defaultNotificationDrawerManager.destroy()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -88,7 +87,6 @@ class DefaultNotificationDrawerManagerTest {
|
|||
defaultNotificationDrawerManager.onNotifiableEventReceived(aNotifiableMessageEvent())
|
||||
// Add the same Event again (will be ignored)
|
||||
defaultNotificationDrawerManager.onNotifiableEventReceived(aNotifiableMessageEvent())
|
||||
defaultNotificationDrawerManager.destroy()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -101,7 +99,7 @@ class DefaultNotificationDrawerManagerTest {
|
|||
)
|
||||
)
|
||||
val appNavigationStateService = FakeAppNavigationStateService(appNavigationState = appNavigationStateFlow)
|
||||
val defaultNotificationDrawerManager = createDefaultNotificationDrawerManager(
|
||||
createDefaultNotificationDrawerManager(
|
||||
appNavigationStateService = appNavigationStateService
|
||||
)
|
||||
appNavigationStateFlow.emit(AppNavigationState(aNavigationState(), isInForeground = true))
|
||||
|
|
@ -117,7 +115,6 @@ class DefaultNotificationDrawerManagerTest {
|
|||
// Like a user sign out
|
||||
appNavigationStateFlow.emit(AppNavigationState(aNavigationState(), isInForeground = true))
|
||||
runCurrent()
|
||||
defaultNotificationDrawerManager.destroy()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -172,8 +169,6 @@ class DefaultNotificationDrawerManagerTest {
|
|||
any(),
|
||||
),
|
||||
)
|
||||
|
||||
defaultNotificationDrawerManager.destroy()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -205,8 +200,6 @@ class DefaultNotificationDrawerManagerTest {
|
|||
listOf(value(null), value(roomMessageId)),
|
||||
listOf(value(null), value(summaryId)),
|
||||
)
|
||||
|
||||
defaultNotificationDrawerManager.destroy()
|
||||
}
|
||||
|
||||
private fun TestScope.createDefaultNotificationDrawerManager(
|
||||
|
|
@ -234,7 +227,7 @@ class DefaultNotificationDrawerManagerTest {
|
|||
sessionStore = sessionStore,
|
||||
),
|
||||
appNavigationStateService = appNavigationStateService,
|
||||
coroutineScope = this,
|
||||
coroutineScope = backgroundScope,
|
||||
matrixClientProvider = matrixClientProvider,
|
||||
imageLoaderHolder = FakeImageLoaderHolder(),
|
||||
activeNotificationsProvider = activeNotificationsProvider,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue