From be11bfd5b4f81b9e0460cb59bb8c80a0d4103348 Mon Sep 17 00:00:00 2001 From: Tiger Oakes Date: Mon, 17 Aug 2020 12:52:12 -0700 Subject: [PATCH] [fenix] Add test for initial logins list state --- .../settings/logins/LoginsFragmentStore.kt | 11 ++++++++++ .../logins/fragment/EditLoginFragment.kt | 14 +++--------- .../logins/fragment/LoginDetailFragment.kt | 11 ++-------- .../logins/fragment/SavedLoginsFragment.kt | 12 ++-------- .../logins/LoginsFragmentStoreTest.kt | 22 +++++++++++++++++++ 5 files changed, 40 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/settings/logins/LoginsFragmentStore.kt b/app/src/main/java/org/mozilla/fenix/settings/logins/LoginsFragmentStore.kt index ea130f07e8..9ab138c305 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/logins/LoginsFragmentStore.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/logins/LoginsFragmentStore.kt @@ -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 ) : 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. */ diff --git a/app/src/main/java/org/mozilla/fenix/settings/logins/fragment/EditLoginFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/logins/fragment/EditLoginFragment.kt index c65654fe0e..62a624169a 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/logins/fragment/EditLoginFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/logins/fragment/EditLoginFragment.kt @@ -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()) ) } diff --git a/app/src/main/java/org/mozilla/fenix/settings/logins/fragment/LoginDetailFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/logins/fragment/LoginDetailFragment.kt index ed452e33b1..60c94290ca 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/logins/fragment/LoginDetailFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/logins/fragment/LoginDetailFragment.kt @@ -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( diff --git a/app/src/main/java/org/mozilla/fenix/settings/logins/fragment/SavedLoginsFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/logins/fragment/SavedLoginsFragment.kt index fe2431ae0e..dc50cc4458 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/logins/fragment/SavedLoginsFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/logins/fragment/SavedLoginsFragment.kt @@ -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()) ) } diff --git a/app/src/test/java/org/mozilla/fenix/settings/logins/LoginsFragmentStoreTest.kt b/app/src/test/java/org/mozilla/fenix/settings/logins/LoginsFragmentStoreTest.kt index dbf41c2bd7..3fe11eeb27 100644 --- a/app/src/test/java/org/mozilla/fenix/settings/logins/LoginsFragmentStoreTest.kt +++ b/app/src/test/java/org/mozilla/fenix/settings/logins/LoginsFragmentStoreTest.kt @@ -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() + 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(