Skip to content

Commit a5e2b27

Browse files
committed
[Link new device] and add tests.
1 parent 552307d commit a5e2b27

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/linknewdevice/RustLinkMobileHandlerTest.kt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,35 @@ class RustLinkMobileHandlerTest {
118118
}
119119
}
120120

121+
@Test
122+
fun `when start throws HumanQrGrantLoginException_NotFound when in state QrReady, the handler emits QrRotating step`() = runTest {
123+
val completable = CompletableDeferred<Unit>()
124+
val handler = FakeFfiGrantLoginWithQrCodeHandler(
125+
generateResult = {
126+
completable.await()
127+
throw HumanQrGrantLoginException.NotFound("Timeout")
128+
}
129+
)
130+
val sut = createRustLinkMobileHandler(
131+
handler,
132+
)
133+
sut.linkMobileStep.test {
134+
val initialItem = awaitItem()
135+
assertThat(initialItem).isEqualTo(LinkMobileStep.Uninitialized)
136+
backgroundScope.launch {
137+
sut.start()
138+
}
139+
runCurrent()
140+
handler.emitGenerateProgress(GrantGeneratedQrLoginProgress.QrReady(FakeFfiQrCodeData(toBytesResult = { QR_CODE_DATA_RECIPROCATE })))
141+
val readyState = awaitItem()
142+
assertThat(readyState).isInstanceOf(LinkMobileStep.QrReady::class.java)
143+
// generate returns, error is emitted
144+
completable.complete(Unit)
145+
val qrRotatingState = awaitItem()
146+
assertThat(qrRotatingState).isEqualTo(LinkMobileStep.QrRotating)
147+
}
148+
}
149+
121150
private fun TestScope.createRustLinkMobileHandler(
122151
handler: FakeFfiGrantLoginWithQrCodeHandler = FakeFfiGrantLoginWithQrCodeHandler(),
123152
) = RustLinkMobileHandler(

0 commit comments

Comments
 (0)