From 3e680b970361482639f4066e2b0714db2c52b1fc Mon Sep 17 00:00:00 2001 From: David Perez Date: Tue, 12 Mar 2024 08:52:10 -0500 Subject: [PATCH] BIT-1973: Add test tags for account switcher (#1124) --- .../account/BitwardenAccountSwitcher.kt | 7 +++- .../vault/util/AccountSummaryExtensions.kt | 12 +++++++ .../util/AccountSummaryExtensionsTest.kt | 32 +++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/platform/components/account/BitwardenAccountSwitcher.kt b/app/src/main/java/com/x8bit/bitwarden/ui/platform/components/account/BitwardenAccountSwitcher.kt index ace0ca195..71ab24df4 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/platform/components/account/BitwardenAccountSwitcher.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/platform/components/account/BitwardenAccountSwitcher.kt @@ -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), ) diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/vault/util/AccountSummaryExtensions.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/vault/util/AccountSummaryExtensions.kt index d158d465a..ac53521c6 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/vault/util/AccountSummaryExtensions.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/vault/util/AccountSummaryExtensions.kt @@ -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]. */ diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/vault/util/AccountSummaryExtensionsTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/vault/util/AccountSummaryExtensionsTest.kt index 71f4f67d2..0f0344856 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/vault/util/AccountSummaryExtensionsTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/vault/util/AccountSummaryExtensionsTest.kt @@ -90,6 +90,38 @@ class AccountSummaryExtensionsTest { ) } + @Test + fun `iconTestTag returns ActiveVaultIcon for active account`() { + val accountSummary = mockk { + every { status } returns AccountSummary.Status.ACTIVE + } + assertEquals("ActiveVaultIcon", accountSummary.iconTestTag) + } + + @Test + fun `iconTestTag returns InactiveVaultIcon for locked account`() { + val accountSummary = mockk { + every { status } returns AccountSummary.Status.LOCKED + } + assertEquals("InactiveVaultIcon", accountSummary.iconTestTag) + } + + @Test + fun `iconTestTag returns InactiveVaultIcon for logged out account`() { + val accountSummary = mockk { + every { status } returns AccountSummary.Status.LOGGED_OUT + } + assertEquals("InactiveVaultIcon", accountSummary.iconTestTag) + } + + @Test + fun `iconTestTag returns InactiveVaultIcon for unlocked account`() { + val accountSummary = mockk { + every { status } returns AccountSummary.Status.UNLOCKED + } + assertEquals("InactiveVaultIcon", accountSummary.iconTestTag) + } + @Test fun `supportingTextResOrNull returns a null for active accounts`() { assertNull(