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

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

@ -32,7 +32,7 @@ class AccountSettingsInteractor(
private val navController: NavController, private val navController: NavController,
private val syncNow: () -> Unit, private val syncNow: () -> Unit,
private val syncDeviceName: (String) -> Boolean, private val syncDeviceName: (String) -> Boolean,
private val store: AccountSettingsStore private val store: AccountSettingsFragmentStore
) : AccountSettingsUserActions { ) : AccountSettingsUserActions {
override fun onSyncNow() { override fun onSyncNow() {
@ -50,7 +50,7 @@ class AccountSettingsInteractor(
// So, in case of a network (or other) failure when talking to the server, // 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. // 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. // 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 return true
} }

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

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

Loading…
Cancel
Save