feat(format-common-impl): add a regression test for flow emission

This commit is contained in:
Harsh Shandilya 2022-12-19 15:33:08 +05:30
parent b84f7ccd07
commit 39a0284cd5
No known key found for this signature in database

View file

@ -5,6 +5,7 @@
package app.passwordstore.data.passfile package app.passwordstore.data.passfile
import app.cash.turbine.Event
import app.cash.turbine.test import app.cash.turbine.test
import app.passwordstore.test.CoroutineTestRule import app.passwordstore.test.CoroutineTestRule
import app.passwordstore.util.time.TestUserClock import app.passwordstore.util.time.TestUserClock
@ -19,6 +20,7 @@ import kotlin.test.assertTrue
import kotlin.time.Duration.Companion.seconds import kotlin.time.Duration.Companion.seconds
import kotlin.time.ExperimentalTime import kotlin.time.ExperimentalTime
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
import kotlinx.coroutines.test.runTest import kotlinx.coroutines.test.runTest
import org.junit.Rule import org.junit.Rule
import org.junit.runner.RunWith import org.junit.runner.RunWith
@ -177,6 +179,17 @@ class PasswordEntryTest {
} }
} }
@Test
fun emitsTotpEverySecond() = runTest {
val entry = makeEntry(TOTP_URI)
entry.totp.test {
delay(3000L)
val events = cancelAndConsumeRemainingEvents()
assertEquals(3, events.size)
assertTrue { events.all { event -> event is Event.Item<Totp> } }
}
}
@Test @Test
fun onlyLooksForUriInFirstLine() { fun onlyLooksForUriInFirstLine() {
val entry = makeEntry("id:\n$TOTP_URI") val entry = makeEntry("id:\n$TOTP_URI")