commonTest.number.TestNumberConnectView.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 number
import com.algolia.instantsearch.core.number.NumberView
import com.algolia.instantsearch.core.number.NumberViewModel
import com.algolia.instantsearch.core.number.connectView
import com.algolia.instantsearch.core.number.decrement
import com.algolia.instantsearch.core.number.increment
import shouldEqual
import kotlin.test.Test
class TestNumberConnectView {
private class MockNumberView : NumberView {
var onClickIncrement: (() -> Unit)? = null
var onClickDecrement: (() -> Unit)? = null
var string: String? = null
override fun setComputation(computation: ((Int?) -> Int?) -> Unit) {
onClickIncrement = {
computation.increment()
}
onClickDecrement = {
computation.decrement()
}
}
override fun setText(text: String) {
string = text
}
}
@Test
fun connectShouldCallSetItem() {
val view = MockNumberView()
val viewModel = NumberViewModel(0..10)
val connection = viewModel.connectView(view)
viewModel.number.value = 5
connection.connect()
view.string shouldEqual "5"
}
@Test
fun onSetNumberShouldCallSetItem() {
val view = MockNumberView()
val viewModel = NumberViewModel(0..10)
val connection = viewModel.connectView(view)
connection.connect()
viewModel.number.value = 5
view.string shouldEqual "5"
}
@Test
fun onClickShouldCallEventSubscription() {
val view = MockNumberView()
val viewModel = NumberViewModel(0..10)
val connection = viewModel.connectView(view)
viewModel.eventNumber.subscribe { viewModel.number.value = it }
connection.connect()
view.onClickIncrement!!()
view.string shouldEqual "0"
view.onClickIncrement!!()
view.string shouldEqual "1"
view.onClickDecrement!!()
view.string shouldEqual "0"
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy