Closes #4513: adds tests for bookmark loading state
parent
fbdd537bc7
commit
fd7f1b2665
|
@ -73,7 +73,7 @@ class BookmarkFragment : LibraryPageFragment<BookmarkNode>(), BackHandler, Accou
|
|||
val view = inflater.inflate(R.layout.fragment_bookmark, container, false)
|
||||
|
||||
bookmarkStore = StoreProvider.get(this) {
|
||||
BookmarkFragmentStore(BookmarkFragmentState(null, isLoading = true))
|
||||
BookmarkFragmentStore(BookmarkFragmentState(null))
|
||||
}
|
||||
bookmarkInteractor = BookmarkFragmentInteractor(
|
||||
bookmarkStore = bookmarkStore,
|
||||
|
|
|
@ -23,7 +23,7 @@ class BookmarkFragmentStore(
|
|||
data class BookmarkFragmentState(
|
||||
val tree: BookmarkNode?,
|
||||
val mode: Mode = Mode.Normal,
|
||||
val isLoading: Boolean
|
||||
val isLoading: Boolean = true
|
||||
) : State {
|
||||
sealed class Mode {
|
||||
open val selectedItems = emptySet<BookmarkNode>()
|
||||
|
|
|
@ -9,7 +9,9 @@ import assertk.assertions.isEqualTo
|
|||
import kotlinx.coroutines.runBlocking
|
||||
import mozilla.components.concept.storage.BookmarkNode
|
||||
import mozilla.components.concept.storage.BookmarkNodeType
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertSame
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class BookmarkFragmentStoreTest {
|
||||
|
@ -134,6 +136,30 @@ class BookmarkFragmentStoreTest {
|
|||
assertThat(initialState.copy(tree = newTree, mode = BookmarkFragmentState.Mode.Normal)).isEqualTo(store.state)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `selecting and deselecting bookmarks does not affect loading state`() = runBlocking {
|
||||
val initialState = BookmarkFragmentState(tree, isLoading = true)
|
||||
val store = BookmarkFragmentStore(initialState)
|
||||
|
||||
store.dispatch(BookmarkFragmentAction.Select(newTree)).join()
|
||||
assertTrue(store.state.isLoading)
|
||||
|
||||
store.dispatch(BookmarkFragmentAction.Deselect(newTree)).join()
|
||||
assertTrue(store.state.isLoading)
|
||||
|
||||
store.dispatch(BookmarkFragmentAction.DeselectAll).join()
|
||||
assertTrue(store.state.isLoading)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `changing bookmarks disables loading state`() = runBlocking {
|
||||
val initialState = BookmarkFragmentState(tree, isLoading = true)
|
||||
val store = BookmarkFragmentStore(initialState)
|
||||
|
||||
store.dispatch(BookmarkFragmentAction.Change(newTree)).join()
|
||||
assertFalse(store.state.isLoading)
|
||||
}
|
||||
|
||||
private val item = BookmarkNode(BookmarkNodeType.ITEM, "456", "123", 0, "Mozilla", "http://mozilla.org", null)
|
||||
private val separator = BookmarkNode(BookmarkNodeType.SEPARATOR, "789", "123", 1, null, null, null)
|
||||
private val subfolder = BookmarkNode(BookmarkNodeType.FOLDER, "987", "123", 0, "Subfolder", null, listOf())
|
||||
|
|
Loading…
Reference in New Issue