commonTest.selectable.TestSelectableItemConnectView.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 selectable
import com.algolia.instantsearch.core.Callback
import com.algolia.instantsearch.core.selectable.SelectableItemView
import com.algolia.instantsearch.core.selectable.SelectableItemViewModel
import com.algolia.instantsearch.core.selectable.connectView
import shouldEqual
import shouldNotBeNull
import kotlin.test.Test
class TestFilterToggleConnectView {
private val input = 0
private val output = "0"
private val presenter: (Int) -> String = { it.toString() }
private class MockSelectableItemView : SelectableItemView {
var boolean: Boolean? = null
var string: String? = null
override var onSelectionChanged: Callback? = null
override fun setIsSelected(isSelected: Boolean) {
boolean = isSelected
}
override fun setItem(item: String) {
string = item
}
}
@Test
fun connectShouldCallSetIsSelectedAndSetItem() {
val view = MockSelectableItemView()
val viewModel = SelectableItemViewModel(input, true)
val connection = viewModel.connectView(view, presenter)
connection.connect()
view.boolean shouldEqual true
view.string shouldEqual output
}
@Test
fun onItemChangedShouldCallSetItem() {
val view = MockSelectableItemView()
val viewModel = SelectableItemViewModel(input)
val connection = viewModel.connectView(view, presenter)
connection.connect()
viewModel.item.value = 1
view.string shouldEqual "1"
}
@Test
fun onClickShouldCallOnIsSelectedComputed() {
val view = MockSelectableItemView()
val viewModel = SelectableItemViewModel(input)
val connection = viewModel.connectView(view, presenter)
viewModel.eventSelection.subscribe { viewModel.isSelected.value = it }
connection.connect()
view.onSelectionChanged.shouldNotBeNull()
view.onSelectionChanged!!(true)
view.boolean shouldEqual true
}
@Test
fun onIsSelectedChangedShouldCallSetIsSelected() {
val view = MockSelectableItemView()
val viewModel = SelectableItemViewModel(input)
val connection = viewModel.connectView(view, presenter)
connection.connect()
viewModel.isSelected.value = true
view.boolean shouldEqual true
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy