Use test extension on presenters.

This commit is contained in:
Benoit Marty 2026-04-27 17:06:49 +02:00
parent f511023507
commit 7f16b69f3b
2 changed files with 13 additions and 36 deletions

View file

@ -8,11 +8,9 @@
package io.element.android.features.call.impl.pip package io.element.android.features.call.impl.pip
import app.cash.molecule.RecompositionMode
import app.cash.molecule.moleculeFlow
import app.cash.turbine.test
import com.google.common.truth.Truth.assertThat import com.google.common.truth.Truth.assertThat
import io.element.android.tests.testutils.lambda.lambdaRecorder import io.element.android.tests.testutils.lambda.lambdaRecorder
import io.element.android.tests.testutils.test
import kotlinx.coroutines.test.runTest import kotlinx.coroutines.test.runTest
import org.junit.Test import org.junit.Test
@ -20,9 +18,7 @@ class PictureInPicturePresenterTest {
@Test @Test
fun `when pip is not supported, the state value supportPip is false`() = runTest { fun `when pip is not supported, the state value supportPip is false`() = runTest {
val presenter = createPictureInPicturePresenter(supportPip = false) val presenter = createPictureInPicturePresenter(supportPip = false)
moleculeFlow(RecompositionMode.Immediate) { presenter.test {
presenter.present()
}.test {
val initialState = awaitItem() val initialState = awaitItem()
assertThat(initialState.supportPip).isFalse() assertThat(initialState.supportPip).isFalse()
} }
@ -35,9 +31,7 @@ class PictureInPicturePresenterTest {
supportPip = true, supportPip = true,
pipView = FakePipView(setPipParamsResult = { }), pipView = FakePipView(setPipParamsResult = { }),
) )
moleculeFlow(RecompositionMode.Immediate) { presenter.test {
presenter.present()
}.test {
val initialState = awaitItem() val initialState = awaitItem()
assertThat(initialState.supportPip).isTrue() assertThat(initialState.supportPip).isTrue()
} }
@ -53,9 +47,7 @@ class PictureInPicturePresenterTest {
enterPipModeResult = enterPipModeResult, enterPipModeResult = enterPipModeResult,
), ),
) )
moleculeFlow(RecompositionMode.Immediate) { presenter.test {
presenter.present()
}.test {
val initialState = awaitItem() val initialState = awaitItem()
assertThat(initialState.isInPictureInPicture).isFalse() assertThat(initialState.isInPictureInPicture).isFalse()
initialState.eventSink(PictureInPictureEvent.EnterPictureInPicture) initialState.eventSink(PictureInPictureEvent.EnterPictureInPicture)
@ -80,9 +72,7 @@ class PictureInPicturePresenterTest {
handUpResult = handUpResult handUpResult = handUpResult
), ),
) )
moleculeFlow(RecompositionMode.Immediate) { presenter.test {
presenter.present()
}.test {
val initialState = awaitItem() val initialState = awaitItem()
initialState.eventSink(PictureInPictureEvent.SetPipController(FakePipController(canEnterPipResult = { false }))) initialState.eventSink(PictureInPictureEvent.SetPipController(FakePipController(canEnterPipResult = { false })))
initialState.eventSink(PictureInPictureEvent.EnterPictureInPicture) initialState.eventSink(PictureInPictureEvent.EnterPictureInPicture)
@ -102,9 +92,7 @@ class PictureInPicturePresenterTest {
enterPipModeResult = enterPipModeResult enterPipModeResult = enterPipModeResult
), ),
) )
moleculeFlow(RecompositionMode.Immediate) { presenter.test {
presenter.present()
}.test {
val initialState = awaitItem() val initialState = awaitItem()
initialState.eventSink( initialState.eventSink(
PictureInPictureEvent.SetPipController( PictureInPictureEvent.SetPipController(

View file

@ -39,6 +39,7 @@ import io.element.android.services.toolbox.api.systemclock.SystemClock
import io.element.android.tests.testutils.WarmUpRule import io.element.android.tests.testutils.WarmUpRule
import io.element.android.tests.testutils.lambda.lambdaRecorder import io.element.android.tests.testutils.lambda.lambdaRecorder
import io.element.android.tests.testutils.lambda.value import io.element.android.tests.testutils.lambda.value
import io.element.android.tests.testutils.test
import io.element.android.tests.testutils.testCoroutineDispatchers import io.element.android.tests.testutils.testCoroutineDispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.cancelAndJoin import kotlinx.coroutines.cancelAndJoin
@ -71,9 +72,7 @@ class CallScreenPresenterTest {
screenTracker = FakeScreenTracker(analyticsLambda), screenTracker = FakeScreenTracker(analyticsLambda),
activeCallManager = FakeActiveCallManager(joinedCallResult = joinedCallLambda), activeCallManager = FakeActiveCallManager(joinedCallResult = joinedCallLambda),
) )
moleculeFlow(RecompositionMode.Immediate) { presenter.test {
presenter.present()
}.test {
// Wait until the URL is loaded // Wait until the URL is loaded
advanceTimeBy(1.seconds) advanceTimeBy(1.seconds)
skipItems(1) skipItems(1)
@ -102,9 +101,7 @@ class CallScreenPresenterTest {
screenTracker = FakeScreenTracker {}, screenTracker = FakeScreenTracker {},
) )
val messageInterceptor = FakeWidgetMessageInterceptor() val messageInterceptor = FakeWidgetMessageInterceptor()
moleculeFlow(RecompositionMode.Immediate) { presenter.test {
presenter.present()
}.test {
// Give it time to load the URL and WidgetDriver // Give it time to load the URL and WidgetDriver
advanceTimeBy(1.seconds) advanceTimeBy(1.seconds)
@ -135,9 +132,7 @@ class CallScreenPresenterTest {
screenTracker = FakeScreenTracker {}, screenTracker = FakeScreenTracker {},
) )
val messageInterceptor = FakeWidgetMessageInterceptor() val messageInterceptor = FakeWidgetMessageInterceptor()
moleculeFlow(RecompositionMode.Immediate) { presenter.test {
presenter.present()
}.test {
val initialState = awaitItem() val initialState = awaitItem()
// Give it time to load the URL and WidgetDriver // Give it time to load the URL and WidgetDriver
@ -169,9 +164,7 @@ class CallScreenPresenterTest {
screenTracker = FakeScreenTracker {}, screenTracker = FakeScreenTracker {},
) )
val messageInterceptor = FakeWidgetMessageInterceptor() val messageInterceptor = FakeWidgetMessageInterceptor()
moleculeFlow(RecompositionMode.Immediate) { presenter.test {
presenter.present()
}.test {
val initialState = awaitItem() val initialState = awaitItem()
// Give it time to load the URL and WidgetDriver // Give it time to load the URL and WidgetDriver
@ -204,9 +197,7 @@ class CallScreenPresenterTest {
screenTracker = FakeScreenTracker {}, screenTracker = FakeScreenTracker {},
) )
val messageInterceptor = FakeWidgetMessageInterceptor() val messageInterceptor = FakeWidgetMessageInterceptor()
moleculeFlow(RecompositionMode.Immediate) { presenter.test {
presenter.present()
}.test {
// Give it time to load the URL and WidgetDriver // Give it time to load the URL and WidgetDriver
advanceTimeBy(1.seconds) advanceTimeBy(1.seconds)
skipItems(2) skipItems(2)
@ -241,9 +232,7 @@ class CallScreenPresenterTest {
screenTracker = FakeScreenTracker {}, screenTracker = FakeScreenTracker {},
) )
val messageInterceptor = FakeWidgetMessageInterceptor() val messageInterceptor = FakeWidgetMessageInterceptor()
moleculeFlow(RecompositionMode.Immediate) { presenter.test {
presenter.present()
}.test {
// Give it time to load the URL and WidgetDriver // Give it time to load the URL and WidgetDriver
advanceTimeBy(1.seconds) advanceTimeBy(1.seconds)
skipItems(2) skipItems(2)