mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 21:32:34 +00:00
Fix tests
Co-Authored-By: Benoit Marty <3940906+bmarty@users.noreply.github.com>
This commit is contained in:
+2
-2
@@ -16,8 +16,8 @@ import org.matrix.rustcomponents.sdk.NoHandle
|
|||||||
import org.matrix.rustcomponents.sdk.QrCodeData
|
import org.matrix.rustcomponents.sdk.QrCodeData
|
||||||
|
|
||||||
class FakeFfiGrantLoginWithQrCodeHandler(
|
class FakeFfiGrantLoginWithQrCodeHandler(
|
||||||
private val generateResult: () -> Unit = {},
|
private val generateResult: suspend () -> Unit = {},
|
||||||
private val scanResult: (QrCodeData) -> Unit = {},
|
private val scanResult: suspend (QrCodeData) -> Unit = {},
|
||||||
) : GrantLoginWithQrCodeHandler(NoHandle) {
|
) : GrantLoginWithQrCodeHandler(NoHandle) {
|
||||||
private var generateProgressListener: GrantGeneratedQrLoginProgressListener? = null
|
private var generateProgressListener: GrantGeneratedQrLoginProgressListener? = null
|
||||||
private var scanProgressListener: GrantQrLoginProgressListener? = null
|
private var scanProgressListener: GrantQrLoginProgressListener? = null
|
||||||
|
|||||||
+38
-1
@@ -15,6 +15,7 @@ import io.element.android.libraries.matrix.api.linknewdevice.ErrorType
|
|||||||
import io.element.android.libraries.matrix.api.linknewdevice.LinkDesktopStep
|
import io.element.android.libraries.matrix.api.linknewdevice.LinkDesktopStep
|
||||||
import io.element.android.libraries.matrix.impl.fixtures.fakes.FakeFfiGrantLoginWithQrCodeHandler
|
import io.element.android.libraries.matrix.impl.fixtures.fakes.FakeFfiGrantLoginWithQrCodeHandler
|
||||||
import io.element.android.libraries.matrix.test.QR_CODE_DATA
|
import io.element.android.libraries.matrix.test.QR_CODE_DATA
|
||||||
|
import kotlinx.coroutines.CompletableDeferred
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.test.StandardTestDispatcher
|
import kotlinx.coroutines.test.StandardTestDispatcher
|
||||||
@@ -29,7 +30,13 @@ import org.matrix.rustcomponents.sdk.QrCodeDecodeException
|
|||||||
class RustLinkDesktopHandlerTest {
|
class RustLinkDesktopHandlerTest {
|
||||||
@Test
|
@Test
|
||||||
fun `handleScannedQrCode function works as expected`() = runTest {
|
fun `handleScannedQrCode function works as expected`() = runTest {
|
||||||
val handler = FakeFfiGrantLoginWithQrCodeHandler()
|
val completable = CompletableDeferred<Unit>()
|
||||||
|
val handler = FakeFfiGrantLoginWithQrCodeHandler(
|
||||||
|
scanResult = {
|
||||||
|
// Ensure that the coroutine is hold
|
||||||
|
completable.await()
|
||||||
|
}
|
||||||
|
)
|
||||||
val sut = createRustLinkDesktopHandler(
|
val sut = createRustLinkDesktopHandler(
|
||||||
handler,
|
handler,
|
||||||
)
|
)
|
||||||
@@ -53,6 +60,36 @@ class RustLinkDesktopHandlerTest {
|
|||||||
handler.emitScanProgress(progress)
|
handler.emitScanProgress(progress)
|
||||||
assertThat(awaitItem()).isEqualTo(expectedStep)
|
assertThat(awaitItem()).isEqualTo(expectedStep)
|
||||||
}
|
}
|
||||||
|
// scan returns, no new event is emitted
|
||||||
|
completable.complete(Unit)
|
||||||
|
expectNoEvents()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `when scan does not emits the Done state, the code emits it`() = runTest {
|
||||||
|
val completable = CompletableDeferred<Unit>()
|
||||||
|
val handler = FakeFfiGrantLoginWithQrCodeHandler(
|
||||||
|
scanResult = {
|
||||||
|
// Ensure that the coroutine is hold
|
||||||
|
completable.await()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
val sut = createRustLinkDesktopHandler(
|
||||||
|
handler,
|
||||||
|
)
|
||||||
|
sut.linkDesktopStep.test {
|
||||||
|
val initialItem = awaitItem()
|
||||||
|
assertThat(initialItem).isEqualTo(LinkDesktopStep.Uninitialized)
|
||||||
|
backgroundScope.launch {
|
||||||
|
sut.handleScannedQrCode(QR_CODE_DATA)
|
||||||
|
}
|
||||||
|
runCurrent()
|
||||||
|
handler.emitScanProgress(GrantQrLoginProgress.Starting)
|
||||||
|
assertThat(awaitItem()).isEqualTo(LinkDesktopStep.Starting)
|
||||||
|
// scan returns, Done event is emitted
|
||||||
|
completable.complete(Unit)
|
||||||
|
assertThat(awaitItem()).isEqualTo(LinkDesktopStep.Done)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+38
-1
@@ -17,6 +17,7 @@ import io.element.android.libraries.matrix.impl.fixtures.fakes.FakeFfiCheckCodeS
|
|||||||
import io.element.android.libraries.matrix.impl.fixtures.fakes.FakeFfiGrantLoginWithQrCodeHandler
|
import io.element.android.libraries.matrix.impl.fixtures.fakes.FakeFfiGrantLoginWithQrCodeHandler
|
||||||
import io.element.android.libraries.matrix.impl.fixtures.fakes.FakeFfiQrCodeData
|
import io.element.android.libraries.matrix.impl.fixtures.fakes.FakeFfiQrCodeData
|
||||||
import io.element.android.libraries.matrix.test.QR_CODE_DATA_RECIPROCATE
|
import io.element.android.libraries.matrix.test.QR_CODE_DATA_RECIPROCATE
|
||||||
|
import kotlinx.coroutines.CompletableDeferred
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.test.StandardTestDispatcher
|
import kotlinx.coroutines.test.StandardTestDispatcher
|
||||||
@@ -30,7 +31,13 @@ import org.matrix.rustcomponents.sdk.HumanQrGrantLoginException
|
|||||||
class RustLinkMobileHandlerTest {
|
class RustLinkMobileHandlerTest {
|
||||||
@Test
|
@Test
|
||||||
fun `start function works as expected`() = runTest {
|
fun `start function works as expected`() = runTest {
|
||||||
val handler = FakeFfiGrantLoginWithQrCodeHandler()
|
val completable = CompletableDeferred<Unit>()
|
||||||
|
val handler = FakeFfiGrantLoginWithQrCodeHandler(
|
||||||
|
generateResult = {
|
||||||
|
// Ensure that the coroutine is hold
|
||||||
|
completable.await()
|
||||||
|
}
|
||||||
|
)
|
||||||
val sut = createRustLinkMobileHandler(
|
val sut = createRustLinkMobileHandler(
|
||||||
handler,
|
handler,
|
||||||
)
|
)
|
||||||
@@ -56,6 +63,36 @@ class RustLinkMobileHandlerTest {
|
|||||||
handler.emitGenerateProgress(progress)
|
handler.emitGenerateProgress(progress)
|
||||||
assertThat(awaitItem()).isInstanceOf(expectedStepClass)
|
assertThat(awaitItem()).isInstanceOf(expectedStepClass)
|
||||||
}
|
}
|
||||||
|
// generate returns, no new event is emitted
|
||||||
|
completable.complete(Unit)
|
||||||
|
expectNoEvents()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `when generates does not emits the Done state, the code emits it`() = runTest {
|
||||||
|
val completable = CompletableDeferred<Unit>()
|
||||||
|
val handler = FakeFfiGrantLoginWithQrCodeHandler(
|
||||||
|
generateResult = {
|
||||||
|
// Ensure that the coroutine is hold
|
||||||
|
completable.await()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
val sut = createRustLinkMobileHandler(
|
||||||
|
handler,
|
||||||
|
)
|
||||||
|
sut.linkMobileStep.test {
|
||||||
|
val initialItem = awaitItem()
|
||||||
|
assertThat(initialItem).isEqualTo(LinkMobileStep.Uninitialized)
|
||||||
|
backgroundScope.launch {
|
||||||
|
sut.start()
|
||||||
|
}
|
||||||
|
runCurrent()
|
||||||
|
handler.emitGenerateProgress(GrantGeneratedQrLoginProgress.Starting)
|
||||||
|
assertThat(awaitItem()).isEqualTo(LinkMobileStep.Starting)
|
||||||
|
// generate returns, Done event is emitted
|
||||||
|
completable.complete(Unit)
|
||||||
|
assertThat(awaitItem()).isEqualTo(LinkMobileStep.Done)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user