Finish adding tests
parent
6c9ce784b1
commit
aac73a8fe2
|
@ -4,12 +4,15 @@
|
||||||
|
|
||||||
package org.mozilla.fenix.settings
|
package org.mozilla.fenix.settings
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import androidx.navigation.NavDestination
|
import androidx.navigation.NavDestination
|
||||||
import io.mockk.every
|
import io.mockk.every
|
||||||
import io.mockk.mockk
|
import io.mockk.mockk
|
||||||
import io.mockk.verify
|
import io.mockk.verify
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertNotSame
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.R
|
||||||
import org.mozilla.fenix.search.SearchState
|
import org.mozilla.fenix.search.SearchState
|
||||||
|
@ -18,47 +21,35 @@ import org.mozilla.fenix.settings.account.*
|
||||||
class AccountSettingsStoreTest {
|
class AccountSettingsStoreTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun onSyncFailed() {
|
fun syncFailed() = runBlocking {
|
||||||
val initialState = AccountSettingsState()
|
val initialState = AccountSettingsState()
|
||||||
val store = AccountSettingsStore(initialState)
|
val store = AccountSettingsStore(initialState)
|
||||||
|
val duration = 1L
|
||||||
|
|
||||||
.onSyncNow()
|
store.dispatch(AccountSettingsAction.SyncFailed(duration)).join()
|
||||||
|
assertNotSame(initialState, store.state)
|
||||||
assertEquals(ranSyncNow, true)
|
assertEquals(LastSyncTime.Failed(duration), store.state.lastSyncedDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun onSyncEnded() {
|
fun syncEnded() = runBlocking {
|
||||||
val store: AccountSettingsStore = mockk(relaxed = true)
|
val initialState = AccountSettingsState()
|
||||||
|
val store = AccountSettingsStore(initialState)
|
||||||
|
val duration = 1L
|
||||||
|
|
||||||
val interactor = AccountSettingsInteractor(
|
store.dispatch(AccountSettingsAction.SyncEnded(duration)).join()
|
||||||
mockk(),
|
assertNotSame(initialState, store.state)
|
||||||
mockk(),
|
assertEquals(LastSyncTime.Success(duration), store.state.lastSyncedDate)
|
||||||
{ true },
|
|
||||||
store
|
|
||||||
)
|
|
||||||
|
|
||||||
interactor.onChangeDeviceName("New Name") {}
|
|
||||||
|
|
||||||
verify { store.dispatch(AccountSettingsAction.UpdateDeviceName("New Name")) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun onSignOut() {
|
fun signOut() = runBlocking {
|
||||||
val navController: NavController = mockk(relaxed = true)
|
val initialState = AccountSettingsState()
|
||||||
every { navController.currentDestination } returns NavDestination("").apply { id = R.id.accountSettingsFragment }
|
val store = AccountSettingsStore(initialState)
|
||||||
|
val deviceName = "testing"
|
||||||
|
|
||||||
val interactor = AccountSettingsInteractor(
|
store.dispatch(AccountSettingsAction.UpdateDeviceName(deviceName)).join()
|
||||||
navController,
|
assertNotSame(initialState, store.state)
|
||||||
mockk(),
|
assertEquals(deviceName, store.state.deviceName)
|
||||||
mockk(),
|
|
||||||
mockk()
|
|
||||||
)
|
|
||||||
|
|
||||||
interactor.onSignOut()
|
|
||||||
|
|
||||||
verify {
|
|
||||||
navController.navigate(AccountSettingsFragmentDirections.actionAccountSettingsFragmentToSignOutFragment())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue