commonTest.loading.TestLoadingConnectView.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 loading
import com.algolia.instantsearch.core.Callback
import com.algolia.instantsearch.core.loading.LoadingView
import com.algolia.instantsearch.core.loading.LoadingViewModel
import com.algolia.instantsearch.core.loading.connectView
import shouldBeNull
import shouldBeTrue
import shouldEqual
import shouldNotBeNull
import kotlin.test.Test
class TestLoadingConnectView {
private class MockLoadingView : LoadingView {
var boolean: Boolean? = null
override var onReload: Callback? = null
override fun setIsLoading(isLoading: Boolean) {
boolean = isLoading
}
}
@Test
fun connectShouldCallSetItem() {
val expected = true
val viewModel = LoadingViewModel(expected)
val view = MockLoadingView()
val connection = viewModel.connectView(view)
view.boolean.shouldBeNull()
connection.connect()
view.boolean shouldEqual expected
}
@Test
fun onItemChangedShouldCallSetItem() {
val viewModel = LoadingViewModel()
val view = MockLoadingView()
val expected = true
val connection = viewModel.connectView(view)
connection.connect()
view.boolean shouldEqual false
viewModel.isLoading.value = expected
view.boolean shouldEqual expected
}
@Test
fun onClickShouldCallEventSubscription() {
val viewModel = LoadingViewModel()
val view = MockLoadingView()
var expected = false
val connection = viewModel.connectView(view)
viewModel.eventReload.subscribe { expected = true }
view.onReload.shouldBeNull()
connection.connect()
view.onReload.shouldNotBeNull()
view.onReload!!(Unit)
expected.shouldBeTrue()
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy