Use test extension on presenter.
This commit is contained in:
parent
4f3065d1c6
commit
56c564c499
1 changed files with 10 additions and 30 deletions
|
|
@ -7,10 +7,7 @@
|
||||||
|
|
||||||
package io.element.android.features.userprofile.impl
|
package io.element.android.features.userprofile.impl
|
||||||
|
|
||||||
import app.cash.molecule.RecompositionMode
|
|
||||||
import app.cash.molecule.moleculeFlow
|
|
||||||
import app.cash.turbine.ReceiveTurbine
|
import app.cash.turbine.ReceiveTurbine
|
||||||
import app.cash.turbine.test
|
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
import io.element.android.features.createroom.api.StartDMAction
|
import io.element.android.features.createroom.api.StartDMAction
|
||||||
import io.element.android.features.createroom.test.FakeStartDMAction
|
import io.element.android.features.createroom.test.FakeStartDMAction
|
||||||
|
|
@ -32,6 +29,7 @@ import io.element.android.libraries.matrix.test.room.FakeMatrixRoom
|
||||||
import io.element.android.libraries.matrix.ui.components.aMatrixUser
|
import io.element.android.libraries.matrix.ui.components.aMatrixUser
|
||||||
import io.element.android.tests.testutils.WarmUpRule
|
import io.element.android.tests.testutils.WarmUpRule
|
||||||
import io.element.android.tests.testutils.awaitLastSequentialItem
|
import io.element.android.tests.testutils.awaitLastSequentialItem
|
||||||
|
import io.element.android.tests.testutils.test
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
|
|
@ -51,9 +49,7 @@ class UserProfilePresenterTest {
|
||||||
val presenter = createUserProfilePresenter(
|
val presenter = createUserProfilePresenter(
|
||||||
client = client,
|
client = client,
|
||||||
)
|
)
|
||||||
moleculeFlow(RecompositionMode.Immediate) {
|
presenter.test {
|
||||||
presenter.present()
|
|
||||||
}.test {
|
|
||||||
val initialState = awaitFirstItem()
|
val initialState = awaitFirstItem()
|
||||||
assertThat(initialState.userId).isEqualTo(matrixUser.userId)
|
assertThat(initialState.userId).isEqualTo(matrixUser.userId)
|
||||||
assertThat(initialState.userName).isEqualTo(matrixUser.displayName)
|
assertThat(initialState.userName).isEqualTo(matrixUser.displayName)
|
||||||
|
|
@ -122,9 +118,7 @@ class UserProfilePresenterTest {
|
||||||
userId = A_USER_ID_2,
|
userId = A_USER_ID_2,
|
||||||
client = client,
|
client = client,
|
||||||
)
|
)
|
||||||
moleculeFlow(RecompositionMode.Immediate) {
|
presenter.test {
|
||||||
presenter.present()
|
|
||||||
}.test {
|
|
||||||
val initialState = awaitLastSequentialItem()
|
val initialState = awaitLastSequentialItem()
|
||||||
assertThat(initialState.canCall).isEqualTo(expectedResult)
|
assertThat(initialState.canCall).isEqualTo(expectedResult)
|
||||||
}
|
}
|
||||||
|
|
@ -138,9 +132,7 @@ class UserProfilePresenterTest {
|
||||||
val presenter = createUserProfilePresenter(
|
val presenter = createUserProfilePresenter(
|
||||||
client = client,
|
client = client,
|
||||||
)
|
)
|
||||||
moleculeFlow(RecompositionMode.Immediate) {
|
presenter.test {
|
||||||
presenter.present()
|
|
||||||
}.test {
|
|
||||||
val initialState = awaitFirstItem()
|
val initialState = awaitFirstItem()
|
||||||
assertThat(initialState.userId).isEqualTo(A_USER_ID)
|
assertThat(initialState.userId).isEqualTo(A_USER_ID)
|
||||||
assertThat(initialState.userName).isNull()
|
assertThat(initialState.userName).isNull()
|
||||||
|
|
@ -152,9 +144,7 @@ class UserProfilePresenterTest {
|
||||||
@Test
|
@Test
|
||||||
fun `present - BlockUser needing confirmation displays confirmation dialog`() = runTest {
|
fun `present - BlockUser needing confirmation displays confirmation dialog`() = runTest {
|
||||||
val presenter = createUserProfilePresenter()
|
val presenter = createUserProfilePresenter()
|
||||||
moleculeFlow(RecompositionMode.Immediate) {
|
presenter.test {
|
||||||
presenter.present()
|
|
||||||
}.test {
|
|
||||||
val initialState = awaitFirstItem()
|
val initialState = awaitFirstItem()
|
||||||
initialState.eventSink(UserProfileEvents.BlockUser(needsConfirmation = true))
|
initialState.eventSink(UserProfileEvents.BlockUser(needsConfirmation = true))
|
||||||
|
|
||||||
|
|
@ -175,9 +165,7 @@ class UserProfilePresenterTest {
|
||||||
client = client,
|
client = client,
|
||||||
userId = A_USER_ID
|
userId = A_USER_ID
|
||||||
)
|
)
|
||||||
moleculeFlow(RecompositionMode.Immediate) {
|
presenter.test {
|
||||||
presenter.present()
|
|
||||||
}.test {
|
|
||||||
val initialState = awaitFirstItem()
|
val initialState = awaitFirstItem()
|
||||||
initialState.eventSink(UserProfileEvents.BlockUser(needsConfirmation = false))
|
initialState.eventSink(UserProfileEvents.BlockUser(needsConfirmation = false))
|
||||||
assertThat(awaitItem().isBlocked.isLoading()).isTrue()
|
assertThat(awaitItem().isBlocked.isLoading()).isTrue()
|
||||||
|
|
@ -196,9 +184,7 @@ class UserProfilePresenterTest {
|
||||||
val matrixClient = FakeMatrixClient()
|
val matrixClient = FakeMatrixClient()
|
||||||
matrixClient.givenIgnoreUserResult(Result.failure(A_THROWABLE))
|
matrixClient.givenIgnoreUserResult(Result.failure(A_THROWABLE))
|
||||||
val presenter = createUserProfilePresenter(client = matrixClient)
|
val presenter = createUserProfilePresenter(client = matrixClient)
|
||||||
moleculeFlow(RecompositionMode.Immediate) {
|
presenter.test {
|
||||||
presenter.present()
|
|
||||||
}.test {
|
|
||||||
val initialState = awaitFirstItem()
|
val initialState = awaitFirstItem()
|
||||||
initialState.eventSink(UserProfileEvents.BlockUser(needsConfirmation = false))
|
initialState.eventSink(UserProfileEvents.BlockUser(needsConfirmation = false))
|
||||||
assertThat(awaitItem().isBlocked.isLoading()).isTrue()
|
assertThat(awaitItem().isBlocked.isLoading()).isTrue()
|
||||||
|
|
@ -215,9 +201,7 @@ class UserProfilePresenterTest {
|
||||||
val matrixClient = FakeMatrixClient()
|
val matrixClient = FakeMatrixClient()
|
||||||
matrixClient.givenUnignoreUserResult(Result.failure(A_THROWABLE))
|
matrixClient.givenUnignoreUserResult(Result.failure(A_THROWABLE))
|
||||||
val presenter = createUserProfilePresenter(client = matrixClient)
|
val presenter = createUserProfilePresenter(client = matrixClient)
|
||||||
moleculeFlow(RecompositionMode.Immediate) {
|
presenter.test {
|
||||||
presenter.present()
|
|
||||||
}.test {
|
|
||||||
val initialState = awaitFirstItem()
|
val initialState = awaitFirstItem()
|
||||||
initialState.eventSink(UserProfileEvents.UnblockUser(needsConfirmation = false))
|
initialState.eventSink(UserProfileEvents.UnblockUser(needsConfirmation = false))
|
||||||
assertThat(awaitItem().isBlocked.isLoading()).isTrue()
|
assertThat(awaitItem().isBlocked.isLoading()).isTrue()
|
||||||
|
|
@ -232,9 +216,7 @@ class UserProfilePresenterTest {
|
||||||
@Test
|
@Test
|
||||||
fun `present - UnblockUser needing confirmation displays confirmation dialog`() = runTest {
|
fun `present - UnblockUser needing confirmation displays confirmation dialog`() = runTest {
|
||||||
val presenter = createUserProfilePresenter()
|
val presenter = createUserProfilePresenter()
|
||||||
moleculeFlow(RecompositionMode.Immediate) {
|
presenter.test {
|
||||||
presenter.present()
|
|
||||||
}.test {
|
|
||||||
val initialState = awaitFirstItem()
|
val initialState = awaitFirstItem()
|
||||||
initialState.eventSink(UserProfileEvents.UnblockUser(needsConfirmation = true))
|
initialState.eventSink(UserProfileEvents.UnblockUser(needsConfirmation = true))
|
||||||
|
|
||||||
|
|
@ -252,9 +234,7 @@ class UserProfilePresenterTest {
|
||||||
fun `present - start DM action complete scenario`() = runTest {
|
fun `present - start DM action complete scenario`() = runTest {
|
||||||
val startDMAction = FakeStartDMAction()
|
val startDMAction = FakeStartDMAction()
|
||||||
val presenter = createUserProfilePresenter(startDMAction = startDMAction)
|
val presenter = createUserProfilePresenter(startDMAction = startDMAction)
|
||||||
moleculeFlow(RecompositionMode.Immediate) {
|
presenter.test {
|
||||||
presenter.present()
|
|
||||||
}.test {
|
|
||||||
val initialState = awaitFirstItem()
|
val initialState = awaitFirstItem()
|
||||||
assertThat(initialState.startDmActionState).isInstanceOf(AsyncAction.Uninitialized::class.java)
|
assertThat(initialState.startDmActionState).isInstanceOf(AsyncAction.Uninitialized::class.java)
|
||||||
val startDMSuccessResult = AsyncAction.Success(A_ROOM_ID)
|
val startDMSuccessResult = AsyncAction.Success(A_ROOM_ID)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue