[fenix] Finish adding tests

pull/600/head
Yeon Taek Jeong 5 years ago committed by Jeff Boek
parent 6517ffed64
commit b050218cd6

@ -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 interactor = AccountSettingsInteractor( val duration = 1L
mockk(),
mockk(),
{ true },
store
)
interactor.onChangeDeviceName("New Name") {}
verify { store.dispatch(AccountSettingsAction.UpdateDeviceName("New Name")) } store.dispatch(AccountSettingsAction.SyncEnded(duration)).join()
assertNotSame(initialState, store.state)
assertEquals(LastSyncTime.Success(duration), store.state.lastSyncedDate)
} }
@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(
navController,
mockk(),
mockk(),
mockk()
)
interactor.onSignOut()
verify { store.dispatch(AccountSettingsAction.UpdateDeviceName(deviceName)).join()
navController.navigate(AccountSettingsFragmentDirections.actionAccountSettingsFragmentToSignOutFragment()) assertNotSame(initialState, store.state)
} assertEquals(deviceName, store.state.deviceName)
} }
} }

Loading…
Cancel
Save