Display environment label in account switcher (#1179)

This commit is contained in:
Patrick Honkonen 2024-03-28 16:44:08 -04:00 committed by Álison Fernandes
parent 323f79d984
commit b13c89b688
3 changed files with 37 additions and 2 deletions

View file

@ -73,6 +73,8 @@ val EnvironmentUrlDataJson.baseIconUrl: String
/**
* Returns the appropriate pre-defined labels for environments matching the known US/EU values.
* Otherwise returns the host of the custom base URL.
*
* @see getSelfHostedUrlOrNull
*/
val EnvironmentUrlDataJson.labelOrBaseUrlHost: String
get() = when (this) {
@ -83,12 +85,27 @@ val EnvironmentUrlDataJson.labelOrBaseUrlHost: String
// Ex:
// - "https://www.abc.com/path-1/path-1" -> "www.abc.com"
URI
.create(this.base)
.create(getSelfHostedUrlOrNull().orEmpty())
.host
.orEmpty()
}
}
/**
* Returns the first self-hosted environment URL from
* [EnvironmentUrlDataJson.webVault], [EnvironmentUrlDataJson.base],
* [EnvironmentUrlDataJson.api], and finally [EnvironmentUrlDataJson.identity]. Returns `null` if
* all self-host environment URLs are null.
*/
private fun EnvironmentUrlDataJson.getSelfHostedUrlOrNull(): String? =
webVault.takeIf { !it.isNullOrBlank() }
?: base
.takeIf { it.isNotBlank() }
?: api
.takeIf { !it.isNullOrBlank() }
?: identity
.takeIf { !it.isNullOrBlank() }
/**
* Converts a raw [EnvironmentUrlDataJson] to an externally-consumable [Environment].
*/

View file

@ -293,6 +293,13 @@ private fun AccountSummaryItem(
modifier = Modifier.semantics { testTag = "AccountEmailLabel" },
)
Text(
text = accountSummary.environmentLabel,
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.semantics { testTag = "AccountEnvironmentLabel" },
)
accountSummary.supportingTextResOrNull?.let { supportingTextResId ->
Text(
text = stringResource(id = supportingTextResId).lowercaseWithCurrentLocal(),

View file

@ -3,6 +3,7 @@ package com.x8bit.bitwarden.ui.util
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.filterToOne
import androidx.compose.ui.test.hasAnyAncestor
import androidx.compose.ui.test.hasTextExactly
import androidx.compose.ui.test.isDialog
import androidx.compose.ui.test.junit4.ComposeContentTestRule
import androidx.compose.ui.test.longClick
@ -26,7 +27,17 @@ fun ComposeContentTestRule.assertSwitcherIsDisplayed(
isAddAccountButtonVisible: Boolean = true,
) {
accountSummaries.forEach { accountSummary ->
this.onNodeWithText(accountSummary.email).assertIsDisplayed()
this.onNode(
hasTextExactly(
*listOfNotNull(
accountSummary.email,
accountSummary.environmentLabel,
"locked".takeUnless { accountSummary.isVaultUnlocked },
)
.toTypedArray(),
),
)
.assertIsDisplayed()
}
if (isAddAccountButtonVisible) {