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

commonTest.number.range.TestNumberRangeConnectView.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 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