commonTest.selectable.map.TestSelectableMapConnectView.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.map
import com.algolia.instantsearch.core.Callback
import com.algolia.instantsearch.core.selectable.map.SelectableMapView
import com.algolia.instantsearch.core.selectable.map.SelectableMapViewModel
import com.algolia.instantsearch.core.selectable.map.connectView
import shouldEqual
import shouldNotBeNull
import kotlin.test.Test
class TestSelectableMapConnectView {
private val input = 0
private val output = "0"
private val id = 0
private val map = mapOf(id to input)
private val presenter: (Int) -> String = { it.toString() }
private class MockSelectableView : SelectableMapView {
override var onSelectionChange: Callback? = null
var int: Int? = null
var data: Map = mapOf()
override fun setMap(map: Map) {
data = map
}
override fun setSelected(selected: Int?) {
int = selected
}
}
@Test
fun connectShouldCallSetSelectedAndSetItem() {
val view = MockSelectableView()
val viewModel = SelectableMapViewModel(map)
val connection = viewModel.connectView(view, presenter)
viewModel.selected.value = id
connection.connect()
view.int shouldEqual id
view.data shouldEqual mapOf(id to output)
}
@Test
fun onItemChangedShouldCallSetItem() {
val view = MockSelectableView()
val viewModel = SelectableMapViewModel(map)
val connection = viewModel.connectView(view, presenter)
connection.connect()
viewModel.map.value = mapOf(1 to 1)
view.data shouldEqual mapOf(1 to "1")
}
@Test
fun onClickShouldCallOnSelectionsComputed() {
val view = MockSelectableView()
val viewModel = SelectableMapViewModel(map)
val connection = viewModel.connectView(view, presenter)
viewModel.eventSelection.subscribe { viewModel.selected.value = it }
connection.connect()
view.onSelectionChange.shouldNotBeNull()
view.onSelectionChange!!(id)
view.int shouldEqual id
}
@Test
fun onSelectedChangedShouldCallSetSelected() {
val view = MockSelectableView()
val viewModel = SelectableMapViewModel(map)
val connection = viewModel.connectView(view, presenter)
connection.connect()
viewModel.selected.value = id
view.int shouldEqual id
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy