For #19797 - Browser menu: go to problems page if account exists but not signed in
This commit is contained in:
parent
d663383cf7
commit
3d071dd049
|
@ -35,6 +35,7 @@ import org.mozilla.fenix.browser.readermode.ReaderModeController
|
|||
import org.mozilla.fenix.collections.SaveCollectionStep
|
||||
import org.mozilla.fenix.components.FenixSnackbar
|
||||
import org.mozilla.fenix.components.TabCollectionStorage
|
||||
import org.mozilla.fenix.components.accounts.AccountState
|
||||
import org.mozilla.fenix.components.metrics.Event
|
||||
import org.mozilla.fenix.components.metrics.MetricController
|
||||
import org.mozilla.fenix.ext.components
|
||||
|
@ -220,10 +221,13 @@ class DefaultBrowserToolbarMenuController(
|
|||
navController.nav(R.id.browserFragment, directions)
|
||||
}
|
||||
is ToolbarMenu.Item.SyncAccount -> {
|
||||
val directions = if (item.signedIn) {
|
||||
BrowserFragmentDirections.actionGlobalAccountSettingsFragment()
|
||||
} else {
|
||||
BrowserFragmentDirections.actionGlobalTurnOnSync()
|
||||
val directions = when (item.accountState) {
|
||||
AccountState.AUTHENTICATED ->
|
||||
BrowserFragmentDirections.actionGlobalAccountSettingsFragment()
|
||||
AccountState.NEEDS_REAUTHENTICATION ->
|
||||
BrowserFragmentDirections.actionGlobalAccountProblemFragment()
|
||||
AccountState.NO_ACCOUNT ->
|
||||
BrowserFragmentDirections.actionGlobalTurnOnSync()
|
||||
}
|
||||
browserAnimator.captureEngineViewAndDrawStatically {
|
||||
navController.nav(
|
||||
|
|
|
@ -348,7 +348,9 @@ open class DefaultToolbarMenu(
|
|||
R.drawable.ic_signed_out,
|
||||
primaryTextColor()
|
||||
) {
|
||||
onItemTapped.invoke(ToolbarMenu.Item.SyncAccount(accountManager.signedInToFxa()))
|
||||
onItemTapped.invoke(
|
||||
ToolbarMenu.Item.SyncAccount(accountManager.accountState)
|
||||
)
|
||||
}
|
||||
|
||||
@VisibleForTesting(otherwise = PRIVATE)
|
||||
|
|
|
@ -6,6 +6,7 @@ package org.mozilla.fenix.components.toolbar
|
|||
|
||||
import mozilla.components.browser.menu.BrowserMenuBuilder
|
||||
import mozilla.components.browser.menu.item.BrowserMenuItemToolbar
|
||||
import org.mozilla.fenix.components.accounts.AccountState
|
||||
|
||||
interface ToolbarMenu {
|
||||
sealed class Item {
|
||||
|
@ -22,7 +23,7 @@ interface ToolbarMenu {
|
|||
object AddToTopSites : Item()
|
||||
object InstallPwaToHomeScreen : Item()
|
||||
object AddToHomeScreen : Item()
|
||||
data class SyncAccount(val signedIn: Boolean) : Item()
|
||||
data class SyncAccount(val accountState: AccountState) : Item()
|
||||
object AddonsManager : Item()
|
||||
object Quit : Item()
|
||||
object OpenInApp : Item()
|
||||
|
|
|
@ -57,6 +57,7 @@ import org.mozilla.fenix.browser.readermode.ReaderModeController
|
|||
import org.mozilla.fenix.collections.SaveCollectionStep
|
||||
import org.mozilla.fenix.components.FenixSnackbar
|
||||
import org.mozilla.fenix.components.TabCollectionStorage
|
||||
import org.mozilla.fenix.components.accounts.AccountState
|
||||
import org.mozilla.fenix.components.metrics.Event
|
||||
import org.mozilla.fenix.components.metrics.MetricController
|
||||
import org.mozilla.fenix.ext.components
|
||||
|
@ -562,25 +563,36 @@ class DefaultBrowserToolbarMenuControllerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN sync sign in menu item is pressed AND account is signed out THEN navigate to sync sign in`() = runBlockingTest {
|
||||
val item = ToolbarMenu.Item.SyncAccount(false)
|
||||
val directions = BrowserFragmentDirections.actionGlobalTurnOnSync()
|
||||
|
||||
fun `GIVEN account exists and the user is signed in WHEN sign in to sync menu item is pressed THEN navigate to account settings`() = runBlockingTest {
|
||||
val item = ToolbarMenu.Item.SyncAccount(AccountState.AUTHENTICATED)
|
||||
val accountSettingsDirections = BrowserFragmentDirections.actionGlobalAccountSettingsFragment()
|
||||
val controller = createController(scope = this, store = browserStore)
|
||||
|
||||
controller.handleToolbarItemInteraction(item)
|
||||
|
||||
verify { navController.navigate(directions, null) }
|
||||
verify { navController.navigate(accountSettingsDirections, null) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN sync sign in menu item is pressed AND account is signed in THEN navigate to sync sign in`() = runBlockingTest {
|
||||
val item = ToolbarMenu.Item.SyncAccount(true)
|
||||
val directions = BrowserFragmentDirections.actionGlobalAccountSettingsFragment()
|
||||
|
||||
fun `GIVEN account exists and the user is not signed in WHEN sign in to sync menu item is pressed THEN navigate to account problem fragment`() = runBlockingTest {
|
||||
val item = ToolbarMenu.Item.SyncAccount(AccountState.NEEDS_REAUTHENTICATION)
|
||||
val accountProblemDirections = BrowserFragmentDirections.actionGlobalAccountProblemFragment()
|
||||
val controller = createController(scope = this, store = browserStore)
|
||||
|
||||
controller.handleToolbarItemInteraction(item)
|
||||
|
||||
verify { navController.navigate(directions, null) }
|
||||
verify { navController.navigate(accountProblemDirections, null) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN account doesn't exist WHEN sign in to sync menu item is pressed THEN navigate to sign in`() = runBlockingTest {
|
||||
val item = ToolbarMenu.Item.SyncAccount(AccountState.NO_ACCOUNT)
|
||||
val turnOnSyncDirections = BrowserFragmentDirections.actionGlobalTurnOnSync()
|
||||
val controller = createController(scope = this, store = browserStore)
|
||||
|
||||
controller.handleToolbarItemInteraction(item)
|
||||
|
||||
verify { navController.navigate(turnOnSyncDirections, null) }
|
||||
}
|
||||
|
||||
private fun createController(
|
||||
|
|
Loading…
Reference in New Issue
Block a user