1
0
Fork 0
fenix/app/src/test/java/org/mozilla/fenix/settings/AccountSettingsStoreTest.kt

56 lines
1.8 KiB
Kotlin
Raw Normal View History

2019-08-09 18:55:24 +02:00
/* 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
2019-08-09 19:49:58 +02:00
import android.util.Log
2019-08-09 18:55:24 +02:00
import androidx.navigation.NavController
import androidx.navigation.NavDestination
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
2019-08-09 19:49:58 +02:00
import kotlinx.coroutines.runBlocking
2019-08-09 18:55:24 +02:00
import org.junit.Assert.assertEquals
2019-08-09 19:49:58 +02:00
import org.junit.Assert.assertNotSame
2019-08-09 18:55:24 +02:00
import org.junit.Test
import org.mozilla.fenix.R
import org.mozilla.fenix.search.SearchState
import org.mozilla.fenix.settings.account.*
class AccountSettingsStoreTest {
@Test
2019-08-09 19:49:58 +02:00
fun syncFailed() = runBlocking {
2019-08-09 18:55:24 +02:00
val initialState = AccountSettingsState()
val store = AccountSettingsStore(initialState)
2019-08-09 19:49:58 +02:00
val duration = 1L
2019-08-09 18:55:24 +02:00
2019-08-09 19:49:58 +02:00
store.dispatch(AccountSettingsAction.SyncFailed(duration)).join()
assertNotSame(initialState, store.state)
assertEquals(LastSyncTime.Failed(duration), store.state.lastSyncedDate)
2019-08-09 18:55:24 +02:00
}
@Test
2019-08-09 19:49:58 +02:00
fun syncEnded() = runBlocking {
val initialState = AccountSettingsState()
val store = AccountSettingsStore(initialState)
val duration = 1L
2019-08-09 18:55:24 +02:00
2019-08-09 19:49:58 +02:00
store.dispatch(AccountSettingsAction.SyncEnded(duration)).join()
assertNotSame(initialState, store.state)
assertEquals(LastSyncTime.Success(duration), store.state.lastSyncedDate)
2019-08-09 18:55:24 +02:00
}
@Test
2019-08-09 19:49:58 +02:00
fun signOut() = runBlocking {
val initialState = AccountSettingsState()
val store = AccountSettingsStore(initialState)
val deviceName = "testing"
2019-08-09 18:55:24 +02:00
2019-08-09 19:49:58 +02:00
store.dispatch(AccountSettingsAction.UpdateDeviceName(deviceName)).join()
assertNotSame(initialState, store.state)
assertEquals(deviceName, store.state.deviceName)
2019-08-09 18:55:24 +02:00
}
}