For #9505: Adds tests for sort saved logins
parent
24ba9f2fc8
commit
77705d1a27
|
@ -0,0 +1,37 @@
|
|||
/* 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue