Skip to content

Commit

Permalink
Bug 1810631 - Display name instead of e-mail in menu (#920)
Browse files Browse the repository at this point in the history
* 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>
(cherry picked from commit 1d4dbc3)
  • Loading branch information
gitstart authored and mergify[bot] committed Mar 27, 2023
1 parent e53c1e6 commit 6ddd50e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Expand Up @@ -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:
Expand All @@ -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)
}
Expand Down
Expand Up @@ -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"
}

Expand All @@ -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
Expand Down

0 comments on commit 6ddd50e

Please sign in to comment.