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

51 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 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
2019-08-09 19:57:49 +02:00
import org.mozilla.fenix.settings.account.AccountSettingsAction
import org.mozilla.fenix.settings.account.AccountSettingsState
import org.mozilla.fenix.settings.account.AccountSettingsStore
import org.mozilla.fenix.settings.account.LastSyncTime
2019-08-09 18:55:24 +02:00
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
}
}