Merge pull request #3554 from element-hq/feature/bma/testEmptyTimeline

Add unit tests on TimelineItemsSubscriber
This commit is contained in:
Benoit Marty
2024-10-02 14:04:48 +02:00
committed by GitHub
14 changed files with 349 additions and 130 deletions

View File

@@ -23,9 +23,9 @@ import io.element.android.services.appnavstate.test.A_SESSION_OWNER
import io.element.android.services.appnavstate.test.A_SPACE_OWNER
import io.element.android.services.appnavstate.test.A_THREAD_OWNER
import io.element.android.services.appnavstate.test.FakeAppForegroundStateService
import io.element.android.tests.testutils.runCancellableScopeTest
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.test.runTest
import org.junit.Test
class DefaultNavigationStateServiceTest {
@@ -51,8 +51,8 @@ class DefaultNavigationStateServiceTest {
)
@Test
fun testNavigation() = runCancellableScopeTest { scope ->
val service = createStateService(scope)
fun testNavigation() = runTest {
val service = createStateService(backgroundScope)
assertThat(service.appNavigationState.first().navigationState).isEqualTo(navigationStateRoot)
service.onNavigateToSession(A_SESSION_OWNER, A_SESSION_ID)
assertThat(service.appNavigationState.first().navigationState).isEqualTo(navigationStateSession)
@@ -74,15 +74,15 @@ class DefaultNavigationStateServiceTest {
}
@Test
fun testFailure() = runCancellableScopeTest { scope ->
val service = createStateService(scope)
fun testFailure() = runTest {
val service = createStateService(backgroundScope)
service.onNavigateToSpace(A_SPACE_OWNER, A_SPACE_ID)
assertThat(service.appNavigationState.value.navigationState).isEqualTo(NavigationState.Root)
}
@Test
fun testOnNavigateToThread() = runCancellableScopeTest { scope ->
val service = createStateService(scope)
fun testOnNavigateToThread() = runTest {
val service = createStateService(backgroundScope)
// From root (no effect)
service.onNavigateToThread(A_THREAD_OWNER, A_THREAD_ID)
assertThat(service.appNavigationState.first().navigationState).isEqualTo(navigationStateRoot)
@@ -110,8 +110,8 @@ class DefaultNavigationStateServiceTest {
}
@Test
fun testOnNavigateToRoom() = runCancellableScopeTest { scope ->
val service = createStateService(scope)
fun testOnNavigateToRoom() = runTest {
val service = createStateService(backgroundScope)
// From root (no effect)
service.onNavigateToRoom(A_ROOM_OWNER, A_ROOM_ID)
assertThat(service.appNavigationState.first().navigationState).isEqualTo(navigationStateRoot)
@@ -139,8 +139,8 @@ class DefaultNavigationStateServiceTest {
}
@Test
fun testOnNavigateToSpace() = runCancellableScopeTest { scope ->
val service = createStateService(scope)
fun testOnNavigateToSpace() = runTest {
val service = createStateService(backgroundScope)
// From root (no effect)
service.onNavigateToSpace(A_SPACE_OWNER, A_SPACE_ID)
assertThat(service.appNavigationState.first().navigationState).isEqualTo(navigationStateRoot)
@@ -168,8 +168,8 @@ class DefaultNavigationStateServiceTest {
}
@Test
fun testOnNavigateToSession() = runCancellableScopeTest { scope ->
val service = createStateService(scope)
fun testOnNavigateToSession() = runTest {
val service = createStateService(backgroundScope)
// From root
service.onNavigateToSession(A_SESSION_OWNER, A_SESSION_ID)
assertThat(service.appNavigationState.first().navigationState).isEqualTo(navigationStateSession)
@@ -197,8 +197,8 @@ class DefaultNavigationStateServiceTest {
}
@Test
fun testOnLeavingThread() = runCancellableScopeTest { scope ->
val service = createStateService(scope)
fun testOnLeavingThread() = runTest {
val service = createStateService(backgroundScope)
// From root (no effect)
service.onLeavingThread(A_THREAD_OWNER)
assertThat(service.appNavigationState.first().navigationState).isEqualTo(navigationStateRoot)
@@ -225,8 +225,8 @@ class DefaultNavigationStateServiceTest {
}
@Test
fun testOnLeavingRoom() = runCancellableScopeTest { scope ->
val service = createStateService(scope)
fun testOnLeavingRoom() = runTest {
val service = createStateService(backgroundScope)
// From root (no effect)
service.onLeavingRoom(A_ROOM_OWNER)
assertThat(service.appNavigationState.first().navigationState).isEqualTo(navigationStateRoot)
@@ -253,8 +253,8 @@ class DefaultNavigationStateServiceTest {
}
@Test
fun testOnLeavingSpace() = runCancellableScopeTest { scope ->
val service = createStateService(scope)
fun testOnLeavingSpace() = runTest {
val service = createStateService(backgroundScope)
// From root (no effect)
service.onLeavingSpace(A_SPACE_OWNER)
assertThat(service.appNavigationState.first().navigationState).isEqualTo(navigationStateRoot)
@@ -281,8 +281,8 @@ class DefaultNavigationStateServiceTest {
}
@Test
fun testOnLeavingSession() = runCancellableScopeTest { scope ->
val service = createStateService(scope)
fun testOnLeavingSession() = runTest {
val service = createStateService(backgroundScope)
// From root
service.onLeavingSession(A_SESSION_OWNER)
assertThat(service.appNavigationState.first().navigationState).isEqualTo(navigationStateRoot)