Created
August 12, 2019 21:16
-
-
Save drawers/130b443257e0d059947859aaaa84961c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val testScheduler = TestScheduler() | |
val states = listOf(Loading, Loaded, ClickX, ClickY) | |
@Test | |
fun `loading followed 500ms later by loaded is emitted`() { | |
val observable = Observable.fromIterable(listOf(0, 500, 1000, 2000)) | |
.zipWith(states) { index, state -> Pair(index, state) } | |
.delay { | |
Observable.timer(it.first.toLong(), TimeUnit.MILLISECONDS, testScheduler) | |
} | |
.map { it.second } | |
.debounceIf({ it is Loading }, 250, TimeUnit.MILLISECONDS, testScheduler) | |
val test = observable.test() | |
testScheduler.advanceTimeTo(2000, TimeUnit.MILLISECONDS) | |
test.assertResult(Loading, Loaded, ClickX, ClickY) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment