mirror of
https://github.com/bitwarden/android.git
synced 2024-11-23 01:46:00 +03:00
BIT-1973: Add test tags for account switcher (#1124)
This commit is contained in:
parent
4f89c697f9
commit
3e680b9703
3 changed files with 50 additions and 1 deletions
|
@ -52,6 +52,7 @@ import com.x8bit.bitwarden.ui.platform.components.dialog.row.BitwardenBasicDialo
|
|||
import com.x8bit.bitwarden.ui.platform.components.model.AccountSummary
|
||||
import com.x8bit.bitwarden.ui.platform.components.scrim.BitwardenAnimatedScrim
|
||||
import com.x8bit.bitwarden.ui.vault.feature.vault.util.iconRes
|
||||
import com.x8bit.bitwarden.ui.vault.feature.vault.util.iconTestTag
|
||||
import com.x8bit.bitwarden.ui.vault.feature.vault.util.initials
|
||||
import com.x8bit.bitwarden.ui.vault.feature.vault.util.supportingTextResOrNull
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
|
@ -216,7 +217,6 @@ private fun AnimatedAccountSwitcher(
|
|||
onSwitchAccountLongClick = onSwitchAccountLongClick,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.semantics { testTag = "AccountIconButton" }
|
||||
.padding(horizontal = 16.dp),
|
||||
)
|
||||
HorizontalDivider(
|
||||
|
@ -239,6 +239,7 @@ private fun AnimatedAccountSwitcher(
|
|||
}
|
||||
}
|
||||
|
||||
@Suppress("LongMethod")
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
private fun AccountSummaryItem(
|
||||
|
@ -251,6 +252,7 @@ private fun AccountSummaryItem(
|
|||
horizontalArrangement = Arrangement.Start,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier
|
||||
.semantics { testTag = "AccountCell" }
|
||||
.combinedClickable(
|
||||
interactionSource = remember { MutableInteractionSource() },
|
||||
indication = rememberRipple(color = MaterialTheme.colorScheme.primary),
|
||||
|
@ -288,6 +290,7 @@ private fun AccountSummaryItem(
|
|||
Text(
|
||||
text = accountSummary.email,
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
modifier = Modifier.semantics { testTag = "AccountEmailLabel" },
|
||||
)
|
||||
|
||||
accountSummary.supportingTextResOrNull?.let { supportingTextResId ->
|
||||
|
@ -295,6 +298,7 @@ private fun AccountSummaryItem(
|
|||
text = stringResource(id = supportingTextResId).lowercaseWithCurrentLocal(),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.semantics { testTag = "AccountStatusLabel" },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -306,6 +310,7 @@ private fun AccountSummaryItem(
|
|||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.onSurface,
|
||||
modifier = Modifier
|
||||
.semantics { testTag = accountSummary.iconTestTag }
|
||||
.size(24.dp),
|
||||
)
|
||||
|
||||
|
|
|
@ -41,6 +41,18 @@ val AccountSummary.iconRes: Int
|
|||
AccountSummary.Status.UNLOCKED -> R.drawable.ic_unlocked
|
||||
}
|
||||
|
||||
/**
|
||||
* Test tag to be used for the for the given [AccountSummary.iconRes].
|
||||
*/
|
||||
val AccountSummary.iconTestTag: String
|
||||
get() = when (this.status) {
|
||||
AccountSummary.Status.ACTIVE -> "ActiveVaultIcon"
|
||||
AccountSummary.Status.LOCKED,
|
||||
AccountSummary.Status.LOGGED_OUT,
|
||||
AccountSummary.Status.UNLOCKED,
|
||||
-> "InactiveVaultIcon"
|
||||
}
|
||||
|
||||
/**
|
||||
* String resource of a supporting text to display (or `null`) for the given [AccountSummary].
|
||||
*/
|
||||
|
|
|
@ -90,6 +90,38 @@ class AccountSummaryExtensionsTest {
|
|||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `iconTestTag returns ActiveVaultIcon for active account`() {
|
||||
val accountSummary = mockk<AccountSummary> {
|
||||
every { status } returns AccountSummary.Status.ACTIVE
|
||||
}
|
||||
assertEquals("ActiveVaultIcon", accountSummary.iconTestTag)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `iconTestTag returns InactiveVaultIcon for locked account`() {
|
||||
val accountSummary = mockk<AccountSummary> {
|
||||
every { status } returns AccountSummary.Status.LOCKED
|
||||
}
|
||||
assertEquals("InactiveVaultIcon", accountSummary.iconTestTag)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `iconTestTag returns InactiveVaultIcon for logged out account`() {
|
||||
val accountSummary = mockk<AccountSummary> {
|
||||
every { status } returns AccountSummary.Status.LOGGED_OUT
|
||||
}
|
||||
assertEquals("InactiveVaultIcon", accountSummary.iconTestTag)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `iconTestTag returns InactiveVaultIcon for unlocked account`() {
|
||||
val accountSummary = mockk<AccountSummary> {
|
||||
every { status } returns AccountSummary.Status.UNLOCKED
|
||||
}
|
||||
assertEquals("InactiveVaultIcon", accountSummary.iconTestTag)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `supportingTextResOrNull returns a null for active accounts`() {
|
||||
assertNull(
|
||||
|
|
Loading…
Reference in a new issue