Test logins settings
parent
0d4ceb186c
commit
294f29768d
|
@ -0,0 +1,55 @@
|
||||||
|
/* 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 android.view.LayoutInflater
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import io.mockk.mockk
|
||||||
|
import kotlinx.android.synthetic.main.fragment_login_detail.view.*
|
||||||
|
import mozilla.components.support.test.robolectric.testContext
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.mozilla.fenix.R
|
||||||
|
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
|
||||||
|
|
||||||
|
@RunWith(FenixRobolectricTestRunner::class)
|
||||||
|
class LoginDetailViewTest {
|
||||||
|
|
||||||
|
private val state = LoginsListState(
|
||||||
|
loginList = emptyList(),
|
||||||
|
filteredItems = emptyList(),
|
||||||
|
currentItem = SavedLogin(
|
||||||
|
guid = "abcd",
|
||||||
|
origin = "mozilla.org",
|
||||||
|
username = "admin",
|
||||||
|
password = "password",
|
||||||
|
timeLastUsed = 100L
|
||||||
|
),
|
||||||
|
searchedForText = null,
|
||||||
|
sortingStrategy = SortingStrategy.LastUsed(mockk()),
|
||||||
|
highlightedItem = SavedLoginsSortingStrategyMenu.Item.LastUsedSort
|
||||||
|
)
|
||||||
|
|
||||||
|
private lateinit var view: ViewGroup
|
||||||
|
private lateinit var detailView: LoginDetailView
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setup() {
|
||||||
|
view = LayoutInflater.from(testContext).inflate(R.layout.fragment_login_detail, null)
|
||||||
|
.findViewById(R.id.loginDetailLayout)
|
||||||
|
detailView = LoginDetailView(view)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `bind currentItem`() {
|
||||||
|
detailView.update(state)
|
||||||
|
|
||||||
|
assertEquals("mozilla.org", view.webAddressText.text)
|
||||||
|
assertEquals("admin", view.usernameText.text)
|
||||||
|
assertEquals("password", view.passwordText.text)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,126 @@
|
||||||
|
/* 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 mozilla.components.concept.storage.Login
|
||||||
|
import mozilla.components.support.test.ext.joinBlocking
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertFalse
|
||||||
|
import org.junit.Assert.assertNull
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class LoginsFragmentStoreTest {
|
||||||
|
|
||||||
|
private val baseLogin = SavedLogin(
|
||||||
|
guid = "",
|
||||||
|
origin = "",
|
||||||
|
username = "",
|
||||||
|
password = "",
|
||||||
|
timeLastUsed = 0L
|
||||||
|
)
|
||||||
|
private val exampleLogin = baseLogin.copy(origin = "example.com", timeLastUsed = 10)
|
||||||
|
private val firefoxLogin = baseLogin.copy(origin = "firefox.com", timeLastUsed = 20)
|
||||||
|
private val loginList = listOf(exampleLogin, firefoxLogin)
|
||||||
|
private val baseState = LoginsListState(
|
||||||
|
loginList = emptyList(),
|
||||||
|
filteredItems = emptyList(),
|
||||||
|
searchedForText = null,
|
||||||
|
sortingStrategy = SortingStrategy.LastUsed(mockk()),
|
||||||
|
highlightedItem = SavedLoginsSortingStrategyMenu.Item.LastUsedSort
|
||||||
|
)
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `convert login to saved login`() {
|
||||||
|
val login = Login(
|
||||||
|
guid = "abcd",
|
||||||
|
origin = "example.com",
|
||||||
|
username = "login",
|
||||||
|
password = "password",
|
||||||
|
timeLastUsed = 35L
|
||||||
|
).mapToSavedLogin()
|
||||||
|
|
||||||
|
assertEquals("abcd", login.guid)
|
||||||
|
assertEquals("example.com", login.origin)
|
||||||
|
assertEquals("login", login.username)
|
||||||
|
assertEquals("password", login.password)
|
||||||
|
assertEquals(35L, login.timeLastUsed)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `UpdateLoginsList action`() {
|
||||||
|
val store = LoginsFragmentStore(baseState.copy(isLoading = true))
|
||||||
|
|
||||||
|
store.dispatch(LoginsAction.UpdateLoginsList(loginList)).joinBlocking()
|
||||||
|
|
||||||
|
assertFalse(store.state.isLoading)
|
||||||
|
assertEquals(loginList, store.state.loginList)
|
||||||
|
assertEquals(listOf(firefoxLogin, exampleLogin), store.state.filteredItems)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `FilterLogins action`() {
|
||||||
|
val store = LoginsFragmentStore(baseState.copy(
|
||||||
|
isLoading = true,
|
||||||
|
searchedForText = "firefox",
|
||||||
|
loginList = loginList
|
||||||
|
))
|
||||||
|
|
||||||
|
store.dispatch(LoginsAction.FilterLogins(null)).joinBlocking()
|
||||||
|
|
||||||
|
assertFalse(store.state.isLoading)
|
||||||
|
assertNull(store.state.searchedForText)
|
||||||
|
assertEquals(listOf(firefoxLogin, exampleLogin), store.state.filteredItems)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `UpdateCurrentLogin action`() {
|
||||||
|
val store = LoginsFragmentStore(baseState.copy(isLoading = true))
|
||||||
|
|
||||||
|
store.dispatch(LoginsAction.UpdateCurrentLogin(baseLogin)).joinBlocking()
|
||||||
|
|
||||||
|
assertEquals(baseLogin, store.state.currentItem)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `SortLogins action`() {
|
||||||
|
val lastUsed = SortingStrategy.LastUsed(mockk())
|
||||||
|
val store = LoginsFragmentStore(baseState.copy(
|
||||||
|
isLoading = true,
|
||||||
|
searchedForText = null,
|
||||||
|
sortingStrategy = SortingStrategy.Alphabetically(mockk()),
|
||||||
|
highlightedItem = SavedLoginsSortingStrategyMenu.Item.AlphabeticallySort,
|
||||||
|
loginList = loginList
|
||||||
|
))
|
||||||
|
|
||||||
|
store.dispatch(LoginsAction.SortLogins(lastUsed)).joinBlocking()
|
||||||
|
|
||||||
|
assertFalse(store.state.isLoading)
|
||||||
|
assertEquals(lastUsed, store.state.sortingStrategy)
|
||||||
|
assertEquals(SavedLoginsSortingStrategyMenu.Item.LastUsedSort, store.state.highlightedItem)
|
||||||
|
assertNull(store.state.searchedForText)
|
||||||
|
assertEquals(listOf(firefoxLogin, exampleLogin), store.state.filteredItems)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `SortLogins action with search text`() {
|
||||||
|
val lastUsed = SortingStrategy.LastUsed(mockk())
|
||||||
|
val store = LoginsFragmentStore(baseState.copy(
|
||||||
|
isLoading = true,
|
||||||
|
searchedForText = "example",
|
||||||
|
sortingStrategy = SortingStrategy.Alphabetically(mockk()),
|
||||||
|
highlightedItem = SavedLoginsSortingStrategyMenu.Item.AlphabeticallySort,
|
||||||
|
loginList = loginList
|
||||||
|
))
|
||||||
|
|
||||||
|
store.dispatch(LoginsAction.SortLogins(lastUsed)).joinBlocking()
|
||||||
|
|
||||||
|
assertFalse(store.state.isLoading)
|
||||||
|
assertEquals(lastUsed, store.state.sortingStrategy)
|
||||||
|
assertEquals(SavedLoginsSortingStrategyMenu.Item.LastUsedSort, store.state.highlightedItem)
|
||||||
|
assertEquals("example", store.state.searchedForText)
|
||||||
|
assertEquals(listOf(exampleLogin), store.state.filteredItems)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
/* 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 android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import io.mockk.mockk
|
||||||
|
import io.mockk.verify
|
||||||
|
import kotlinx.android.synthetic.main.logins_item.view.*
|
||||||
|
import mozilla.components.support.test.robolectric.testContext
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.mozilla.fenix.R
|
||||||
|
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
|
||||||
|
|
||||||
|
@RunWith(FenixRobolectricTestRunner::class)
|
||||||
|
class LoginsListViewHolderTest {
|
||||||
|
|
||||||
|
private val baseLogin = SavedLogin(
|
||||||
|
guid = "abcd",
|
||||||
|
origin = "mozilla.org",
|
||||||
|
username = "admin",
|
||||||
|
password = "password",
|
||||||
|
timeLastUsed = 100L
|
||||||
|
)
|
||||||
|
|
||||||
|
private lateinit var view: View
|
||||||
|
private lateinit var interactor: SavedLoginsInteractor
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setup() {
|
||||||
|
view = LayoutInflater.from(testContext).inflate(R.layout.logins_item, null)
|
||||||
|
interactor = mockk(relaxed = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `bind url and username`() {
|
||||||
|
val holder = LoginsListViewHolder(view, interactor)
|
||||||
|
holder.bind(baseLogin)
|
||||||
|
|
||||||
|
assertEquals("mozilla.org", view.webAddressView.text)
|
||||||
|
assertEquals("admin", view.usernameView.text)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `call interactor on click`() {
|
||||||
|
val holder = LoginsListViewHolder(view, interactor)
|
||||||
|
holder.bind(baseLogin)
|
||||||
|
|
||||||
|
view.performClick()
|
||||||
|
verify { interactor.itemClicked(baseLogin) }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue