Skip to content

Commit

Permalink
Let FakeKnockRoom and FakeLogoutUseCase use simulateLongTask
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarty committed Oct 16, 2024
1 parent d5bf8ae commit 2695513
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ package io.element.android.features.joinroom.impl

import io.element.android.features.joinroom.impl.di.KnockRoom
import io.element.android.libraries.matrix.api.core.RoomId
import io.element.android.tests.testutils.simulateLongTask

class FakeKnockRoom(
var lambda: (RoomId) -> Result<Unit> = { Result.success(Unit) }
) : KnockRoom {
override suspend fun invoke(roomId: RoomId) = lambda(roomId)
override suspend fun invoke(roomId: RoomId) = simulateLongTask {
lambda(roomId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ package io.element.android.features.logout.test

import io.element.android.features.logout.api.LogoutUseCase
import io.element.android.tests.testutils.lambda.lambdaError
import io.element.android.tests.testutils.simulateLongTask

class FakeLogoutUseCase(
var logoutLambda: (Boolean) -> String? = { lambdaError() }
) : LogoutUseCase {
override suspend fun logout(ignoreSdkError: Boolean): String? {
return logoutLambda(ignoreSdkError)
override suspend fun logout(ignoreSdkError: Boolean): String? = simulateLongTask {
logoutLambda(ignoreSdkError)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import io.element.android.libraries.preferences.test.InMemoryAppPreferencesStore
import io.element.android.tests.testutils.WarmUpRule
import io.element.android.tests.testutils.awaitLastSequentialItem
import io.element.android.tests.testutils.lambda.lambdaRecorder
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.test.runTest
import org.junit.Rule
Expand Down Expand Up @@ -168,11 +169,15 @@ class DeveloperSettingsPresenterTest {
initialState.eventSink(DeveloperSettingsEvents.SetSimplifiedSlidingSyncEnabled(true))
assertThat(awaitItem().isSimpleSlidingSyncEnabled).isTrue()
assertThat(preferences.isSimplifiedSlidingSyncEnabledFlow().first()).isTrue()
// Give time for the logout to be called, but for some reason using runCurrent() is not enough
delay(2)
logoutCallRecorder.assertions().isCalledOnce()

initialState.eventSink(DeveloperSettingsEvents.SetSimplifiedSlidingSyncEnabled(false))
assertThat(awaitItem().isSimpleSlidingSyncEnabled).isFalse()
assertThat(preferences.isSimplifiedSlidingSyncEnabledFlow().first()).isFalse()
// Give time for the logout to be called, but for some reason using runCurrent() is not enough
delay(2)
logoutCallRecorder.assertions().isCalledExactly(times = 2)
}
}
Expand Down

0 comments on commit 2695513

Please sign in to comment.