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