Rename AccountSettingsStore/State/Action to AccountSettingsFragmentStore/State/Action.

nightly-build-test
Sebastian Kaspari 5 years ago committed by Jeff Boek
parent 61e84c161d
commit f3d8a89c63

@ -35,7 +35,7 @@ import org.mozilla.fenix.ext.requireComponents
@SuppressWarnings("TooManyFunctions")
class AccountSettingsFragment : PreferenceFragmentCompat() {
private lateinit var accountManager: FxaAccountManager
private lateinit var accountSettingsStore: AccountSettingsStore
private lateinit var accountSettingsStore: AccountSettingsFragmentStore
private lateinit var accountSettingsInteractor: AccountSettingsInteractor
// Navigate away from this fragment when we encounter auth problems or logout events.
@ -97,8 +97,8 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
setPreferencesFromResource(R.xml.account_settings_preferences, rootKey)
accountSettingsStore = StoreProvider.get(this) {
AccountSettingsStore(
AccountSettingsState(
AccountSettingsFragmentStore(
AccountSettingsFragmentState(
lastSyncedDate =
if (getLastSynced(requireContext()) == 0L)
LastSyncTime.Never
@ -140,7 +140,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
deviceConstellation?.state()?.currentDevice?.let { device ->
summary = device.displayName
text = device.displayName
accountSettingsStore.dispatch(AccountSettingsAction.UpdateDeviceName(device.displayName))
accountSettingsStore.dispatch(AccountSettingsFragmentAction.UpdateDeviceName(device.displayName))
}
setOnBindEditTextListener { editText ->
editText.filters = arrayOf(InputFilter.LengthFilter(DEVICE_NAME_MAX_LENGTH))
@ -227,7 +227,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
pref.isEnabled = true
val time = getLastSynced(requireContext())
accountSettingsStore.dispatch(AccountSettingsAction.SyncEnded(time))
accountSettingsStore.dispatch(AccountSettingsFragmentAction.SyncEnded(time))
}
}
}
@ -241,7 +241,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
pref.isEnabled = true
val failedTime = getLastSynced(requireContext())
accountSettingsStore.dispatch(AccountSettingsAction.SyncFailed(failedTime))
accountSettingsStore.dispatch(AccountSettingsFragmentAction.SyncFailed(failedTime))
}
}
}
@ -250,18 +250,18 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
private val deviceConstellationObserver = object : DeviceConstellationObserver {
override fun onDevicesUpdate(constellation: ConstellationState) {
constellation.currentDevice?.displayName?.also {
accountSettingsStore.dispatch(AccountSettingsAction.UpdateDeviceName(it))
accountSettingsStore.dispatch(AccountSettingsFragmentAction.UpdateDeviceName(it))
}
}
}
private fun updateDeviceName(state: AccountSettingsState) {
private fun updateDeviceName(state: AccountSettingsFragmentState) {
val deviceNameKey = getPreferenceKey(R.string.pref_key_sync_device_name)
val preferenceDeviceName = findPreference<Preference>(deviceNameKey)
preferenceDeviceName?.summary = state.deviceName
}
private fun updateLastSyncTimePref(state: AccountSettingsState) {
private fun updateLastSyncTimePref(state: AccountSettingsFragmentState) {
val value = when (state.lastSyncedDate) {
LastSyncTime.Never -> getString(R.string.sync_never_synced_summary)
is LastSyncTime.Failed -> {

@ -9,11 +9,11 @@ import mozilla.components.lib.state.State
import mozilla.components.lib.state.Store
/**
* The [Store] for holding the [AccountSettingsState] and applying [AccountAction]s.
* The [Store] for holding the [AccountSettingsFragmentState] and applying [AccountAction]s.
*/
class AccountSettingsStore(
initialState: AccountSettingsState
) : Store<AccountSettingsState, AccountSettingsAction>(
class AccountSettingsFragmentStore(
initialState: AccountSettingsFragmentState
) : Store<AccountSettingsFragmentState, AccountSettingsFragmentAction>(
initialState,
::accountStateReducer
)
@ -27,7 +27,7 @@ sealed class LastSyncTime {
/**
* The state for the Account Settings Screen
*/
data class AccountSettingsState(
data class AccountSettingsFragmentState(
val lastSyncedDate: LastSyncTime = LastSyncTime.Never,
val deviceName: String = ""
) : State
@ -35,19 +35,19 @@ data class AccountSettingsState(
/**
* Actions to dispatch through the `SearchStore` to modify `SearchState` through the reducer.
*/
sealed class AccountSettingsAction : Action {
data class SyncFailed(val time: Long) : AccountSettingsAction()
data class SyncEnded(val time: Long) : AccountSettingsAction()
data class UpdateDeviceName(val name: String) : AccountSettingsAction()
sealed class AccountSettingsFragmentAction : Action {
data class SyncFailed(val time: Long) : AccountSettingsFragmentAction()
data class SyncEnded(val time: Long) : AccountSettingsFragmentAction()
data class UpdateDeviceName(val name: String) : AccountSettingsFragmentAction()
}
/**
* The SearchState Reducer.
*/
fun accountStateReducer(state: AccountSettingsState, action: AccountSettingsAction): AccountSettingsState {
private fun accountStateReducer(state: AccountSettingsFragmentState, action: AccountSettingsFragmentAction): AccountSettingsFragmentState {
return when (action) {
is AccountSettingsAction.SyncFailed -> state.copy(lastSyncedDate = LastSyncTime.Failed(action.time))
is AccountSettingsAction.SyncEnded -> state.copy(lastSyncedDate = LastSyncTime.Success(action.time))
is AccountSettingsAction.UpdateDeviceName -> state.copy(deviceName = action.name)
is AccountSettingsFragmentAction.SyncFailed -> state.copy(lastSyncedDate = LastSyncTime.Failed(action.time))
is AccountSettingsFragmentAction.SyncEnded -> state.copy(lastSyncedDate = LastSyncTime.Success(action.time))
is AccountSettingsFragmentAction.UpdateDeviceName -> state.copy(deviceName = action.name)
}
}

@ -32,7 +32,7 @@ class AccountSettingsInteractor(
private val navController: NavController,
private val syncNow: () -> Unit,
private val syncDeviceName: (String) -> Boolean,
private val store: AccountSettingsStore
private val store: AccountSettingsFragmentStore
) : AccountSettingsUserActions {
override fun onSyncNow() {
@ -50,7 +50,7 @@ class AccountSettingsInteractor(
// So, in case of a network (or other) failure when talking to the server,
// we'll have a discrepancy - the UI will reflect new value, but actually the value never changed.
// So, when user presses "sync now", we'll fetch the old value, and reset the UI.
store.dispatch(AccountSettingsAction.UpdateDeviceName(newDeviceName))
store.dispatch(AccountSettingsFragmentAction.UpdateDeviceName(newDeviceName))
return true
}

@ -8,42 +8,42 @@ import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotSame
import org.junit.Test
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.AccountSettingsFragmentAction
import org.mozilla.fenix.settings.account.AccountSettingsFragmentState
import org.mozilla.fenix.settings.account.AccountSettingsFragmentStore
import org.mozilla.fenix.settings.account.LastSyncTime
class AccountSettingsStoreTest {
class AccountSettingsFragmentStoreTest {
@Test
fun syncFailed() = runBlocking {
val initialState = AccountSettingsState()
val store = AccountSettingsStore(initialState)
val initialState = AccountSettingsFragmentState()
val store = AccountSettingsFragmentStore(initialState)
val duration = 1L
store.dispatch(AccountSettingsAction.SyncFailed(duration)).join()
store.dispatch(AccountSettingsFragmentAction.SyncFailed(duration)).join()
assertNotSame(initialState, store.state)
assertEquals(LastSyncTime.Failed(duration), store.state.lastSyncedDate)
}
@Test
fun syncEnded() = runBlocking {
val initialState = AccountSettingsState()
val store = AccountSettingsStore(initialState)
val initialState = AccountSettingsFragmentState()
val store = AccountSettingsFragmentStore(initialState)
val duration = 1L
store.dispatch(AccountSettingsAction.SyncEnded(duration)).join()
store.dispatch(AccountSettingsFragmentAction.SyncEnded(duration)).join()
assertNotSame(initialState, store.state)
assertEquals(LastSyncTime.Success(duration), store.state.lastSyncedDate)
}
@Test
fun signOut() = runBlocking {
val initialState = AccountSettingsState()
val store = AccountSettingsStore(initialState)
val initialState = AccountSettingsFragmentState()
val store = AccountSettingsFragmentStore(initialState)
val deviceName = "testing"
store.dispatch(AccountSettingsAction.UpdateDeviceName(deviceName)).join()
store.dispatch(AccountSettingsFragmentAction.UpdateDeviceName(deviceName)).join()
assertNotSame(initialState, store.state)
assertEquals(deviceName, store.state.deviceName)
}

@ -12,10 +12,10 @@ import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Test
import org.mozilla.fenix.R
import org.mozilla.fenix.settings.account.AccountSettingsAction
import org.mozilla.fenix.settings.account.AccountSettingsFragmentAction
import org.mozilla.fenix.settings.account.AccountSettingsFragmentDirections
import org.mozilla.fenix.settings.account.AccountSettingsInteractor
import org.mozilla.fenix.settings.account.AccountSettingsStore
import org.mozilla.fenix.settings.account.AccountSettingsFragmentStore
class AccountSettingsInteractorTest {
@ -37,7 +37,7 @@ class AccountSettingsInteractorTest {
@Test
fun onChangeDeviceName() {
val store: AccountSettingsStore = mockk(relaxed = true)
val store: AccountSettingsFragmentStore = mockk(relaxed = true)
val interactor = AccountSettingsInteractor(
mockk(),
@ -48,7 +48,7 @@ class AccountSettingsInteractorTest {
interactor.onChangeDeviceName("New Name") {}
verify { store.dispatch(AccountSettingsAction.UpdateDeviceName("New Name")) }
verify { store.dispatch(AccountSettingsFragmentAction.UpdateDeviceName("New Name")) }
}
@Test

Loading…
Cancel
Save