Bug 1810631 - Display name instead of e-mail in menu (#920)

* Bug 1810631 - Display name instead of e-mail in menu.

* Bug 1810631 - Display name instead of e-mail in menu

---------

Co-authored-by: gitstart <gitstart@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
fenix/112.0
GitStart 1 year ago committed by GitHub
parent 110d24a4a8
commit f8476e24bc

@ -45,7 +45,8 @@ class BrowserMenuSignIn(
* Return the proper label for the sign in button.
*
* There are 3 states that the account state could be in:
* 1) If the user is signed in and the account information is known, display the account email.
* 1) If the user is signed in and the account information is known and a display name is set
* display the account display name else display the account email.
* 2) The user is not signed in.
* 3) Display an account info placeholder string if the user is signed in, but the account state
* is unknown or being checked. Could by improved by using:
@ -55,9 +56,10 @@ class BrowserMenuSignIn(
internal fun getLabel(context: Context): String = with(context) {
val isSignedIn = components.settings.signedInFxaAccount
val email = components.backgroundServices.syncStore.state.account?.email
val displayName = components.backgroundServices.syncStore.state.account?.displayName
if (isSignedIn) {
email ?: resources.getString(R.string.browser_menu_account_settings)
displayName ?: email ?: resources.getString(R.string.browser_menu_account_settings)
} else {
resources.getString(R.string.sync_menu_sync_and_save_data)
}

@ -24,6 +24,12 @@ class BrowserMenuSignInTest {
private lateinit var context: Context
private lateinit var components: Components
private val account: Account = mockk {
every { displayName } returns "bugzilla"
every { email } returns "bugzilla@mozilla.com"
}
private val accountWithNoDisplayName: Account = mockk {
every { displayName } returns null
every { email } returns "bugzilla@mozilla.com"
}
@ -37,11 +43,19 @@ class BrowserMenuSignInTest {
}
@Test
fun `WHEN signed in and has profile data, THEN show email`() {
fun `WHEN signed in and has profile data, THEN show display name`() {
every { components.backgroundServices.syncStore.state.account } returns account
every { components.settings.signedInFxaAccount } returns true
assertEquals(account.email, BrowserMenuSignIn(R.color.black).getLabel(context))
assertEquals(account.displayName, BrowserMenuSignIn(R.color.black).getLabel(context))
}
@Test
fun `WHEN signed in and has profile data but the display name is not set, THEN show email`() {
every { components.backgroundServices.syncStore.state.account } returns accountWithNoDisplayName
every { components.settings.signedInFxaAccount } returns true
assertEquals(accountWithNoDisplayName.email, BrowserMenuSignIn(R.color.black).getLabel(context))
}
@Test

Loading…
Cancel
Save