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

commonTest.loading.TestLoadingConnectView.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 loading

import com.algolia.instantsearch.core.Callback
import com.algolia.instantsearch.core.loading.LoadingView
import com.algolia.instantsearch.core.loading.LoadingViewModel
import com.algolia.instantsearch.core.loading.connectView
import shouldBeNull
import shouldBeTrue
import shouldEqual
import shouldNotBeNull
import kotlin.test.Test

class TestLoadingConnectView {

    private class MockLoadingView : LoadingView {

        var boolean: Boolean? = null

        override var onReload: Callback? = null

        override fun setIsLoading(isLoading: Boolean) {
            boolean = isLoading
        }
    }

    @Test
    fun connectShouldCallSetItem() {
        val expected = true
        val viewModel = LoadingViewModel(expected)
        val view = MockLoadingView()
        val connection = viewModel.connectView(view)

        view.boolean.shouldBeNull()
        connection.connect()
        view.boolean shouldEqual expected
    }

    @Test
    fun onItemChangedShouldCallSetItem() {
        val viewModel = LoadingViewModel()
        val view = MockLoadingView()
        val expected = true
        val connection = viewModel.connectView(view)

        connection.connect()
        view.boolean shouldEqual false
        viewModel.isLoading.value = expected
        view.boolean shouldEqual expected
    }

    @Test
    fun onClickShouldCallEventSubscription() {
        val viewModel = LoadingViewModel()
        val view = MockLoadingView()
        var expected = false
        val connection = viewModel.connectView(view)

        viewModel.eventReload.subscribe { expected = true }
        view.onReload.shouldBeNull()
        connection.connect()
        view.onReload.shouldNotBeNull()
        view.onReload!!(Unit)
        expected.shouldBeTrue()
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy