commonTest.searcher.TestDebouncer.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of instantsearch-core Show documentation
Show all versions of instantsearch-core Show documentation
InstantSearch Android is a library providing widgets and helpers to help you build the best instant-search experience on Android with Algolia. It is built on top of Algolia's Kotlin API Client to provide you a high-level solution to quickly build various search interfaces.
package searcher
import blocking
import com.algolia.instantsearch.core.searcher.Debouncer
import kotlinx.coroutines.delay
import shouldEqual
import kotlin.test.Test
class TestDebouncer {
@Test
fun shouldDebounce() {
val debouncer = Debouncer(100)
var count = 0
val block: suspend () -> Unit = { count++ }
blocking {
debouncer.debounce(this, block)
debouncer.debounce(this, block)
debouncer.debounce(this, block)
debouncer.job!!.join()
count shouldEqual 1
}
}
@Test
fun shouldNotDebounce() {
val debouncer = Debouncer(100)
var count = 0
val block: suspend () -> Unit = { count++ }
blocking {
debouncer.debounce(this, block)
delay(200)
debouncer.debounce(this, block)
delay(200)
debouncer.debounce(this, block)
debouncer.job!!.join()
count shouldEqual 3
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy