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

commonTest.tree.TestTreePresenter.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 tree

import com.algolia.instantsearch.core.tree.Node
import com.algolia.instantsearch.core.tree.Tree
import com.algolia.instantsearch.core.tree.TreePresenter
import com.algolia.instantsearch.core.tree.asTree
import shouldEqual
import kotlin.test.Test

class TestTreePresenter {

    private val book = "Book"
    private val bookScienceFiction = "$book > Science Fiction"
    private val bookRomance = "$book > Romance"
    private val clothing = "Clothing"
    private val clothingMen = "$clothing > Men"
    private val clothingMenHats = "$clothingMen > Hats"
    private val clothingMenShirts = "$clothingMen > Shirts"
    private val clothingWomen = "$clothing > Women"
    private val clothingWomenBags = "$clothingWomen > Bags"
    private val clothingWomenShoes = "$clothingWomen > Shoes"
    private val furniture = "Furniture"

    private val presenter: TreePresenter> = {
        val comparator = Comparator { a, b -> a.compareTo(b) }
        it.asTree(comparator) { node, _, _ -> node.content }
    }
    private val tree = Tree(
        mutableListOf(
            Node(
                book,
                mutableListOf(
                    Node(bookScienceFiction),
                    Node(bookRomance)
                )
            ),
            Node(furniture),
            Node(
                clothing,
                mutableListOf(
                    Node(
                        clothingMen,
                        mutableListOf(
                            Node(clothingMenHats),
                            Node(clothingMenShirts)
                        )
                    ),
                    Node(
                        clothingWomen,
                        mutableListOf(
                            Node(clothingWomenShoes),
                            Node(clothingWomenBags)
                        )
                    )
                )
            )
        )
    )

    @Test
    fun presenterShouldSortTree() {
        presenter(tree) shouldEqual listOf(
            book, bookRomance, bookScienceFiction,
            clothing, clothingMen, clothingMenHats, clothingMenShirts,
            clothingWomen, clothingWomenBags, clothingWomenShoes,
            furniture
        )
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy