@@ -26,9 +26,8 @@ import io.element.android.libraries.preferences.test.InMemoryAppPreferencesStore
2626import io.element.android.tests.testutils.WarmUpRule
2727import io.element.android.tests.testutils.awaitLastSequentialItem
2828import io.element.android.tests.testutils.lambda.lambdaRecorder
29- import kotlinx.coroutines.ExperimentalCoroutinesApi
29+ import kotlinx.coroutines.CompletableDeferred
3030import kotlinx.coroutines.flow.first
31- import kotlinx.coroutines.test.advanceUntilIdle
3231import kotlinx.coroutines.test.runTest
3332import org.junit.Rule
3433import org.junit.Test
@@ -155,10 +154,18 @@ class DeveloperSettingsPresenterTest {
155154 }
156155 }
157156
158- @OptIn(ExperimentalCoroutinesApi ::class )
159157 @Test
160158 fun `present - toggling simplified sliding sync changes the preferences and logs out the user` () = runTest {
161- val logoutCallRecorder = lambdaRecorder<Boolean , String ?> { " " }
159+ val latch1 = CompletableDeferred <Unit >()
160+ val latch2 = CompletableDeferred <Unit >()
161+ val logoutCallRecorder = lambdaRecorder<Boolean , String ?> {
162+ if (latch1.isActive) {
163+ latch1.complete(Unit )
164+ } else {
165+ latch2.complete(Unit )
166+ }
167+ " "
168+ }
162169 val logoutUseCase = FakeLogoutUseCase (logoutLambda = logoutCallRecorder)
163170 val preferences = InMemoryAppPreferencesStore ()
164171 val presenter = createDeveloperSettingsPresenter(preferencesStore = preferences, logoutUseCase = logoutUseCase)
@@ -171,13 +178,12 @@ class DeveloperSettingsPresenterTest {
171178 initialState.eventSink(DeveloperSettingsEvents .SetSimplifiedSlidingSyncEnabled (true ))
172179 assertThat(awaitItem().isSimpleSlidingSyncEnabled).isTrue()
173180 assertThat(preferences.isSimplifiedSlidingSyncEnabledFlow().first()).isTrue()
174- advanceUntilIdle ()
181+ latch1.await ()
175182 logoutCallRecorder.assertions().isCalledOnce()
176-
177183 initialState.eventSink(DeveloperSettingsEvents .SetSimplifiedSlidingSyncEnabled (false ))
178184 assertThat(awaitItem().isSimpleSlidingSyncEnabled).isFalse()
179185 assertThat(preferences.isSimplifiedSlidingSyncEnabledFlow().first()).isFalse()
180- advanceUntilIdle ()
186+ latch2.await ()
181187 logoutCallRecorder.assertions().isCalledExactly(times = 2 )
182188 }
183189 }
0 commit comments