Move test data to TestData.kt

This commit is contained in:
Benoit Marty
2023-02-09 18:41:58 +01:00
parent 173f768301
commit 6169323043
8 changed files with 21 additions and 17 deletions

View File

@@ -19,12 +19,11 @@ package io.element.android.x.root
import io.element.android.features.rageshake.reporter.BugReporter
import io.element.android.features.rageshake.reporter.BugReporterListener
import io.element.android.features.rageshake.reporter.ReportType
import io.element.android.libraries.matrixtest.A_FAILURE_REASON
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
const val A_REASON = "There has been a failure"
// TODO Remove this duplicated class when we will rework modules.
class FakeBugReporter(val mode: FakeBugReporterMode = FakeBugReporterMode.Success) : BugReporter {
override fun sendBugReport(
@@ -49,7 +48,7 @@ class FakeBugReporter(val mode: FakeBugReporterMode = FakeBugReporterMode.Succes
when (mode) {
FakeBugReporterMode.Success -> Unit
FakeBugReporterMode.Failure -> {
listener?.onUploadFailed(A_REASON)
listener?.onUploadFailed(A_FAILURE_REASON)
return@launch
}
FakeBugReporterMode.Cancel -> {

View File

@@ -23,11 +23,11 @@ import app.cash.molecule.moleculeFlow
import app.cash.turbine.test
import com.google.common.truth.Truth.assertThat
import io.element.android.libraries.matrix.core.SessionId
import io.element.android.libraries.matrixtest.A_FAILURE
import io.element.android.libraries.matrixtest.A_HOMESERVER
import io.element.android.libraries.matrixtest.A_HOMESERVER_2
import io.element.android.libraries.matrixtest.A_PASSWORD
import io.element.android.libraries.matrixtest.A_SESSION_ID
import io.element.android.libraries.matrixtest.A_THROWABLE
import io.element.android.libraries.matrixtest.A_USER_NAME
import io.element.android.libraries.matrixtest.auth.FakeAuthenticationService
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -106,12 +106,12 @@ class LoginRootPresenterTest {
initialState.eventSink.invoke(LoginRootEvents.SetPassword(A_PASSWORD))
skipItems(1)
val loginAndPasswordState = awaitItem()
authenticationService.givenLoginError(A_FAILURE)
authenticationService.givenLoginError(A_THROWABLE)
loginAndPasswordState.eventSink.invoke(LoginRootEvents.Submit)
val submitState = awaitItem()
assertThat(submitState.loggedInState).isEqualTo(LoggedInState.LoggingIn)
val loggedInState = awaitItem()
assertThat(loggedInState.loggedInState).isEqualTo(LoggedInState.ErrorLoggingIn(A_FAILURE))
assertThat(loggedInState.loggedInState).isEqualTo(LoggedInState.ErrorLoggingIn(A_THROWABLE))
}
}

View File

@@ -24,7 +24,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.core.SessionId
import io.element.android.libraries.matrixtest.A_FAILURE
import io.element.android.libraries.matrixtest.A_THROWABLE
import io.element.android.libraries.matrixtest.FakeMatrixClient
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
@@ -71,12 +71,12 @@ class LogoutPreferencePresenterTest {
presenter.present()
}.test {
val initialState = awaitItem()
matrixClient.givenLogoutError(A_FAILURE)
matrixClient.givenLogoutError(A_THROWABLE)
initialState.eventSink.invoke(LogoutPreferenceEvents.Logout)
val loadingState = awaitItem()
assertThat(loadingState.logoutAction).isInstanceOf(Async.Loading::class.java)
val successState = awaitItem()
assertThat(successState.logoutAction).isEqualTo(Async.Failure<LogoutPreferenceState>(A_FAILURE))
assertThat(successState.logoutAction).isEqualTo(Async.Failure<LogoutPreferenceState>(A_THROWABLE))
}
}
}

View File

@@ -25,6 +25,7 @@ import com.google.common.truth.Truth.assertThat
import io.element.android.features.rageshake.crash.ui.A_CRASH_DATA
import io.element.android.features.rageshake.crash.ui.FakeCrashDataStore
import io.element.android.libraries.architecture.Async
import io.element.android.libraries.matrixtest.A_FAILURE_REASON
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import org.junit.Test
@@ -218,7 +219,7 @@ class BugReportPresenterTest {
assertThat(awaitItem().sendingProgress).isEqualTo(0.5f)
// Failure
assertThat(awaitItem().sendingProgress).isEqualTo(0f)
assertThat((awaitItem().sending as Async.Failure).error.message).isEqualTo(A_REASON)
assertThat((awaitItem().sending as Async.Failure).error.message).isEqualTo(A_FAILURE_REASON)
}
}

View File

@@ -19,12 +19,11 @@ package io.element.android.features.rageshake.bugreport
import io.element.android.features.rageshake.reporter.BugReporter
import io.element.android.features.rageshake.reporter.BugReporterListener
import io.element.android.features.rageshake.reporter.ReportType
import io.element.android.libraries.matrixtest.A_FAILURE_REASON
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
const val A_REASON = "There has been a failure"
class FakeBugReporter(val mode: FakeBugReporterMode = FakeBugReporterMode.Success) : BugReporter {
override fun sendBugReport(
coroutineScope: CoroutineScope,
@@ -48,7 +47,7 @@ class FakeBugReporter(val mode: FakeBugReporterMode = FakeBugReporterMode.Succes
when (mode) {
FakeBugReporterMode.Success -> Unit
FakeBugReporterMode.Failure -> {
listener?.onUploadFailed(A_REASON)
listener?.onUploadFailed(A_FAILURE_REASON)
return@launch
}
FakeBugReporterMode.Cancel -> {

View File

@@ -28,6 +28,7 @@ import io.element.android.features.rageshake.preferences.FakeRageShake
import io.element.android.features.rageshake.preferences.FakeRageshakeDataStore
import io.element.android.features.rageshake.preferences.RageshakePreferencesPresenter
import io.element.android.features.rageshake.screenshot.ImageResult
import io.element.android.libraries.matrixtest.AN_EXCEPTION
import io.mockk.mockk
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.first
@@ -142,7 +143,7 @@ class RageshakeDetectionPresenterTest {
rageshake.triggerPhoneRageshake()
assertThat(awaitItem().takeScreenshot).isTrue()
initialState.eventSink.invoke(
RageshakeDetectionEvents.ProcessScreenshot(ImageResult.Error(Exception("Error")))
RageshakeDetectionEvents.ProcessScreenshot(ImageResult.Error(AN_EXCEPTION))
)
assertThat(awaitItem().showDialog).isTrue()
initialState.eventSink.invoke(RageshakeDetectionEvents.Dismiss)

View File

@@ -28,6 +28,7 @@ import io.element.android.libraries.dateformatter.LastMessageFormatter
import io.element.android.libraries.designsystem.components.avatar.AvatarData
import io.element.android.libraries.matrix.core.SessionId
import io.element.android.libraries.matrixtest.AN_AVATAR_URL
import io.element.android.libraries.matrixtest.AN_EXCEPTION
import io.element.android.libraries.matrixtest.A_MESSAGE
import io.element.android.libraries.matrixtest.A_ROOM_ID
import io.element.android.libraries.matrixtest.A_ROOM_NAME
@@ -69,8 +70,8 @@ class RoomListPresenterTests {
val presenter = RoomListPresenter(
FakeMatrixClient(
SessionId("sessionId"),
userDisplayName = Result.failure(Exception("Error")),
userAvatarURLString = Result.failure(Exception("Error")),
userDisplayName = Result.failure(AN_EXCEPTION),
userAvatarURLString = Result.failure(AN_EXCEPTION),
),
createDateFormatter()
)

View File

@@ -38,4 +38,7 @@ const val A_SESSION_ID = "sessionId"
const val AN_AVATAR_URL = "mxc://data"
val A_FAILURE = Throwable("error")
const val A_FAILURE_REASON = "There has been a failure"
val A_THROWABLE = Throwable(A_FAILURE_REASON)
val AN_EXCEPTION = Exception(A_FAILURE_REASON)