Commit 77705d1a authored by ValentinTimisica's avatar ValentinTimisica Committed by Emily Kager
Browse files

For #9505: Adds tests for sort saved logins

parent 24ba9f2f
/* This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.settings.logins
import io.mockk.mockk
import io.mockk.verify
import mozilla.components.support.test.robolectric.testContext
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.utils.Settings
@RunWith(FenixRobolectricTestRunner::class)
class SavedLoginsControllerTest {
private val store: SavedLoginsFragmentStore = mockk(relaxed = true)
private val settings: Settings = mockk(relaxed = true)
private val sortingStrategy: SortingStrategy = SortingStrategy.Alphabetically(testContext)
private val controller = DefaultSavedLoginsController(store, settings)
@Test
fun `GIVEN a sorting strategy, WHEN handleSort is called on the controller, THEN the correct action should be dispatched and the strategy saved in sharedPref`() {
controller.handleSort(sortingStrategy)
verify {
store.dispatch(
SavedLoginsFragmentAction.SortLogins(
SortingStrategy.Alphabetically(
testContext
)
)
)
settings.savedLoginsSortingStrategy = sortingStrategy
}
}
}
......@@ -6,24 +6,41 @@ package org.mozilla.fenix.settings.logins
import io.mockk.mockk
import io.mockk.verify
import mozilla.components.support.test.robolectric.testContext
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import kotlin.random.Random
@RunWith(FenixRobolectricTestRunner::class)
class SavedLoginsInteractorTest {
private val controller: SavedLoginsController = mockk(relaxed = true)
private val savedLoginClicked: (SavedLoginsItem) -> Unit = mockk(relaxed = true)
private val learnMore: () -> Unit = mockk(relaxed = true)
private val interactor = SavedLoginsInteractor(
controller,
savedLoginClicked,
learnMore
)
@Test
fun itemClicked() {
val savedLoginClicked: (SavedLoginsItem) -> Unit = mockk(relaxed = true)
val learnMore: () -> Unit = mockk(relaxed = true)
val interactor = SavedLoginsInteractor(
savedLoginClicked,
learnMore
)
val item = SavedLoginsItem("mozilla.org", "username", "password", "id")
val item = SavedLoginsItem("mozilla.org", "username", "password", "id", Random.nextLong())
interactor.itemClicked(item)
verify {
savedLoginClicked.invoke(item)
}
}
@Test
fun `GIVEN a sorting strategy, WHEN sort method is called on the interactor, THEN controller should call handleSort with the same parameter`() {
val sortingStrategy: SortingStrategy = SortingStrategy.Alphabetically(testContext)
interactor.sort(sortingStrategy)
verify {
controller.handleSort(sortingStrategy)
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment