Add missing test for SecureBackupEnablePresenter

This commit is contained in:
Benoit Marty 2023-12-28 16:33:53 +01:00
parent 315cc1fd9d
commit 35baaa6209
2 changed files with 28 additions and 0 deletions

View file

@ -22,6 +22,7 @@ import app.cash.turbine.test
import com.google.common.truth.Truth.assertThat
import io.element.android.libraries.architecture.Async
import io.element.android.libraries.matrix.api.encryption.EncryptionService
import io.element.android.libraries.matrix.test.AN_EXCEPTION
import io.element.android.libraries.matrix.test.encryption.FakeEncryptionService
import io.element.android.tests.testutils.WarmUpRule
import kotlinx.coroutines.test.runTest
@ -58,6 +59,26 @@ class SecureBackupEnablePresenterTest {
}
}
@Test
fun `present - user enable backup with error`() = runTest {
val encryptionService = FakeEncryptionService()
encryptionService.givenEnableBackupsFailure(AN_EXCEPTION)
val presenter = createPresenter(encryptionService = encryptionService)
moleculeFlow(RecompositionMode.Immediate) {
presenter.present()
}.test {
val initialState = awaitItem()
initialState.eventSink(SecureBackupEnableEvents.EnableBackup)
val loadingState = awaitItem()
assertThat(loadingState.enableAction).isInstanceOf(Async.Loading::class.java)
val errorState = awaitItem()
assertThat(errorState.enableAction).isEqualTo(Async.Failure<Unit>(AN_EXCEPTION))
errorState.eventSink(SecureBackupEnableEvents.DismissDialog)
val finalState = awaitItem()
assertThat(finalState.enableAction).isEqualTo(Async.Uninitialized)
}
}
private fun createPresenter(
encryptionService: EncryptionService = FakeEncryptionService(),
) = SecureBackupEnablePresenter(