mirror of
https://github.com/bitwarden/android.git
synced 2024-11-23 09:56:11 +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.model.AccountSummary
|
||||||
import com.x8bit.bitwarden.ui.platform.components.scrim.BitwardenAnimatedScrim
|
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.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.initials
|
||||||
import com.x8bit.bitwarden.ui.vault.feature.vault.util.supportingTextResOrNull
|
import com.x8bit.bitwarden.ui.vault.feature.vault.util.supportingTextResOrNull
|
||||||
import kotlinx.collections.immutable.ImmutableList
|
import kotlinx.collections.immutable.ImmutableList
|
||||||
|
@ -216,7 +217,6 @@ private fun AnimatedAccountSwitcher(
|
||||||
onSwitchAccountLongClick = onSwitchAccountLongClick,
|
onSwitchAccountLongClick = onSwitchAccountLongClick,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.semantics { testTag = "AccountIconButton" }
|
|
||||||
.padding(horizontal = 16.dp),
|
.padding(horizontal = 16.dp),
|
||||||
)
|
)
|
||||||
HorizontalDivider(
|
HorizontalDivider(
|
||||||
|
@ -239,6 +239,7 @@ private fun AnimatedAccountSwitcher(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("LongMethod")
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
private fun AccountSummaryItem(
|
private fun AccountSummaryItem(
|
||||||
|
@ -251,6 +252,7 @@ private fun AccountSummaryItem(
|
||||||
horizontalArrangement = Arrangement.Start,
|
horizontalArrangement = Arrangement.Start,
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
|
.semantics { testTag = "AccountCell" }
|
||||||
.combinedClickable(
|
.combinedClickable(
|
||||||
interactionSource = remember { MutableInteractionSource() },
|
interactionSource = remember { MutableInteractionSource() },
|
||||||
indication = rememberRipple(color = MaterialTheme.colorScheme.primary),
|
indication = rememberRipple(color = MaterialTheme.colorScheme.primary),
|
||||||
|
@ -288,6 +290,7 @@ private fun AccountSummaryItem(
|
||||||
Text(
|
Text(
|
||||||
text = accountSummary.email,
|
text = accountSummary.email,
|
||||||
style = MaterialTheme.typography.bodyLarge,
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
modifier = Modifier.semantics { testTag = "AccountEmailLabel" },
|
||||||
)
|
)
|
||||||
|
|
||||||
accountSummary.supportingTextResOrNull?.let { supportingTextResId ->
|
accountSummary.supportingTextResOrNull?.let { supportingTextResId ->
|
||||||
|
@ -295,6 +298,7 @@ private fun AccountSummaryItem(
|
||||||
text = stringResource(id = supportingTextResId).lowercaseWithCurrentLocal(),
|
text = stringResource(id = supportingTextResId).lowercaseWithCurrentLocal(),
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
modifier = Modifier.semantics { testTag = "AccountStatusLabel" },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -306,6 +310,7 @@ private fun AccountSummaryItem(
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
tint = MaterialTheme.colorScheme.onSurface,
|
tint = MaterialTheme.colorScheme.onSurface,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
|
.semantics { testTag = accountSummary.iconTestTag }
|
||||||
.size(24.dp),
|
.size(24.dp),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,18 @@ val AccountSummary.iconRes: Int
|
||||||
AccountSummary.Status.UNLOCKED -> R.drawable.ic_unlocked
|
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].
|
* 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
|
@Test
|
||||||
fun `supportingTextResOrNull returns a null for active accounts`() {
|
fun `supportingTextResOrNull returns a null for active accounts`() {
|
||||||
assertNull(
|
assertNull(
|
||||||
|
|
Loading…
Reference in a new issue