Skip to content

Instantly share code, notes, and snippets.

@drawers
Created August 12, 2019 21:16
Show Gist options
  • Save drawers/130b443257e0d059947859aaaa84961c to your computer and use it in GitHub Desktop.
Save drawers/130b443257e0d059947859aaaa84961c to your computer and use it in GitHub Desktop.
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