All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonTest.selectable.map.TestSelectableMapConnectView.kt Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 3.3.1
Show newest version
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