commonTest.number.range.TestNumberRangeConnectView.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.range
import com.algolia.instantsearch.core.Callback
import com.algolia.instantsearch.core.number.range.NumberRangeView
import com.algolia.instantsearch.core.number.range.NumberRangeViewModel
import com.algolia.instantsearch.core.number.range.Range
import com.algolia.instantsearch.core.number.range.connectView
import shouldEqual
import kotlin.test.Test
class TestNumberRangeConnectView {
private class MockNumberRangeView : NumberRangeView {
public var range: Range? = null
@JvmName("_setRange") set
public var bounds: Range? = null
private set
override var onRangeChanged: Callback>? = null
override fun setRange(range: Range?) {
this.range = range
}
override fun setBounds(bounds: Range?) {
this.bounds = bounds
}
}
@Test
fun connectShouldCallSetItem() {
val viewModel = NumberRangeViewModel()
val view = MockNumberRangeView()
val connection = viewModel.connectView(view)
viewModel.range.value = Range(0..20)
connection.connect()
view.range shouldEqual viewModel.range.value
}
@Test
fun connectShouldCallSetBounds() {
val viewModel = NumberRangeViewModel()
val view = MockNumberRangeView()
val connection = viewModel.connectView(view)
viewModel.bounds.value = Range(0..20)
connection.connect()
view.bounds shouldEqual viewModel.bounds.value
}
@Test
fun onRangeChangedShouldUpdateRange() {
val viewModel = NumberRangeViewModel()
val view = MockNumberRangeView()
val connection = viewModel.connectView(view)
connection.connect()
viewModel.range.value = Range(0..20)
view.range shouldEqual viewModel.range.value
}
@Test
fun onBoundsComputedShouldUpdateBounds() {
val viewModel = NumberRangeViewModel()
val view = MockNumberRangeView()
val connection = viewModel.connectView(view)
connection.connect()
viewModel.bounds.value = Range(0..20)
view.bounds shouldEqual viewModel.bounds.value
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy