2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-03 23:15:31 +00:00

[fenix] Add test for initial logins list state

This commit is contained in:
Tiger Oakes 2020-08-17 12:52:12 -07:00 committed by ekager
parent e4bdd355d3
commit be11bfd5b4
5 changed files with 40 additions and 30 deletions

View File

@ -10,6 +10,7 @@ import mozilla.components.concept.storage.Login
import mozilla.components.lib.state.Action
import mozilla.components.lib.state.State
import mozilla.components.lib.state.Store
import org.mozilla.fenix.utils.Settings
/**
* Class representing a parcelable saved logins item
@ -80,6 +81,16 @@ data class LoginsListState(
val duplicateLogins: List<SavedLogin>
) : State
fun createInitialLoginsListState(settings: Settings) = LoginsListState(
isLoading = true,
loginList = emptyList(),
filteredItems = emptyList(),
searchedForText = null,
sortingStrategy = settings.savedLoginsSortingStrategy,
highlightedItem = settings.savedLoginsMenuHighlightedItem,
duplicateLogins = emptyList() // assume on load there are no dupes
)
/**
* Handles changes in the saved logins list, including updates and filtering.
*/

View File

@ -33,11 +33,11 @@ import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.settings.logins.LoginsAction
import org.mozilla.fenix.settings.logins.LoginsFragmentStore
import org.mozilla.fenix.settings.logins.LoginsListState
import org.mozilla.fenix.settings.logins.SavedLogin
import org.mozilla.fenix.settings.logins.togglePasswordReveal
import org.mozilla.fenix.settings.logins.controller.SavedLoginsStorageController
import org.mozilla.fenix.settings.logins.createInitialLoginsListState
import org.mozilla.fenix.settings.logins.interactor.EditLoginInteractor
import org.mozilla.fenix.settings.logins.togglePasswordReveal
/**
* Displays the editable saved login information for a single website
@ -69,15 +69,7 @@ class EditLoginFragment : Fragment(R.layout.fragment_edit_login) {
loginsFragmentStore = StoreProvider.get(this) {
LoginsFragmentStore(
LoginsListState(
isLoading = true,
loginList = listOf(),
filteredItems = listOf(),
searchedForText = null,
sortingStrategy = requireContext().settings().savedLoginsSortingStrategy,
highlightedItem = requireContext().settings().savedLoginsMenuHighlightedItem,
duplicateLogins = listOf()
)
createInitialLoginsListState(requireContext().settings())
)
}

View File

@ -41,6 +41,7 @@ import org.mozilla.fenix.settings.logins.LoginsFragmentStore
import org.mozilla.fenix.settings.logins.LoginsListState
import org.mozilla.fenix.settings.logins.SavedLogin
import org.mozilla.fenix.settings.logins.controller.SavedLoginsStorageController
import org.mozilla.fenix.settings.logins.createInitialLoginsListState
import org.mozilla.fenix.settings.logins.interactor.LoginDetailInteractor
import org.mozilla.fenix.settings.logins.togglePasswordReveal
import org.mozilla.fenix.settings.logins.view.LoginDetailView
@ -68,15 +69,7 @@ class LoginDetailFragment : Fragment(R.layout.fragment_login_detail) {
val view = inflater.inflate(R.layout.fragment_login_detail, container, false)
savedLoginsStore = StoreProvider.get(this) {
LoginsFragmentStore(
LoginsListState(
isLoading = true,
loginList = listOf(),
filteredItems = listOf(),
searchedForText = null,
sortingStrategy = requireContext().settings().savedLoginsSortingStrategy,
highlightedItem = requireContext().settings().savedLoginsMenuHighlightedItem,
duplicateLogins = listOf() // assume on load there are no dupes
)
createInitialLoginsListState(requireContext().settings())
)
}
loginDetailView = LoginDetailView(

View File

@ -35,11 +35,11 @@ import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.showToolbar
import org.mozilla.fenix.settings.logins.LoginsAction
import org.mozilla.fenix.settings.logins.LoginsFragmentStore
import org.mozilla.fenix.settings.logins.LoginsListState
import org.mozilla.fenix.settings.logins.SavedLoginsSortingStrategyMenu
import org.mozilla.fenix.settings.logins.SortingStrategy
import org.mozilla.fenix.settings.logins.controller.LoginsListController
import org.mozilla.fenix.settings.logins.controller.SavedLoginsStorageController
import org.mozilla.fenix.settings.logins.createInitialLoginsListState
import org.mozilla.fenix.settings.logins.interactor.SavedLoginsInteractor
import org.mozilla.fenix.settings.logins.view.SavedLoginsListView
@ -77,15 +77,7 @@ class SavedLoginsFragment : Fragment() {
val view = inflater.inflate(R.layout.fragment_saved_logins, container, false)
savedLoginsStore = StoreProvider.get(this) {
LoginsFragmentStore(
LoginsListState(
isLoading = true,
loginList = listOf(),
filteredItems = listOf(),
searchedForText = null,
sortingStrategy = requireContext().settings().savedLoginsSortingStrategy,
highlightedItem = requireContext().settings().savedLoginsMenuHighlightedItem,
duplicateLogins = listOf() // assume on load there are no dupes
)
createInitialLoginsListState(requireContext().settings())
)
}

View File

@ -4,6 +4,7 @@
package org.mozilla.fenix.settings.logins
import io.mockk.every
import io.mockk.mockk
import mozilla.components.concept.storage.Login
import mozilla.components.support.test.ext.joinBlocking
@ -12,6 +13,7 @@ import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
import org.mozilla.fenix.utils.Settings
class LoginsFragmentStoreTest {
@ -34,6 +36,26 @@ class LoginsFragmentStoreTest {
duplicateLogins = listOf()
)
@Test
fun `create initial state`() {
val settings = mockk<Settings>()
every { settings.savedLoginsSortingStrategy } returns SortingStrategy.LastUsed
every { settings.savedLoginsMenuHighlightedItem } returns SavedLoginsSortingStrategyMenu.Item.LastUsedSort
assertEquals(
LoginsListState(
isLoading = true,
loginList = emptyList(),
filteredItems = emptyList(),
searchedForText = null,
sortingStrategy = SortingStrategy.LastUsed,
highlightedItem = SavedLoginsSortingStrategyMenu.Item.LastUsedSort,
duplicateLogins = emptyList()
),
createInitialLoginsListState(settings)
)
}
@Test
fun `convert login to saved login`() {
val login = Login(