BIT-2120: Add ElementID's to Add/Edit views (Login) (#1202)

This commit is contained in:
Ramsey Smith 2024-04-01 15:13:25 -06:00 committed by Álison Fernandes
parent 11d862664d
commit de1c76d772
3 changed files with 31 additions and 4 deletions

View file

@ -12,6 +12,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.semantics.semantics import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTag
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import com.x8bit.bitwarden.R import com.x8bit.bitwarden.R
@ -48,6 +49,8 @@ fun BitwardenPasswordFieldWithActions(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
readOnly: Boolean = false, readOnly: Boolean = false,
singleLine: Boolean = false, singleLine: Boolean = false,
showPasswordTestTag: String? = null,
passwordFieldTestTag: String? = null,
actions: @Composable RowScope.() -> Unit = {}, actions: @Composable RowScope.() -> Unit = {},
) { ) {
Row( Row(
@ -63,8 +66,10 @@ fun BitwardenPasswordFieldWithActions(
readOnly = readOnly, readOnly = readOnly,
singleLine = singleLine, singleLine = singleLine,
modifier = Modifier modifier = Modifier
.semantics { passwordFieldTestTag?.let { testTag = it } }
.weight(1f) .weight(1f)
.padding(end = 8.dp), .padding(end = 8.dp),
showPasswordTestTag = showPasswordTestTag,
) )
actions() actions()
} }
@ -98,6 +103,8 @@ fun BitwardenPasswordFieldWithActions(
readOnly: Boolean = false, readOnly: Boolean = false,
singleLine: Boolean = false, singleLine: Boolean = false,
initialShowPassword: Boolean = false, initialShowPassword: Boolean = false,
showPasswordTestTag: String? = null,
passwordFieldTestTag: String? = null,
actions: @Composable RowScope.() -> Unit = {}, actions: @Composable RowScope.() -> Unit = {},
) { ) {
var shouldShowPassword by remember { mutableStateOf(initialShowPassword) } var shouldShowPassword by remember { mutableStateOf(initialShowPassword) }
@ -110,6 +117,8 @@ fun BitwardenPasswordFieldWithActions(
modifier = modifier, modifier = modifier,
readOnly = readOnly, readOnly = readOnly,
singleLine = singleLine, singleLine = singleLine,
showPasswordTestTag = showPasswordTestTag,
passwordFieldTestTag = passwordFieldTestTag,
actions = actions, actions = actions,
) )
} }

View file

@ -61,6 +61,7 @@ fun LazyListScope.vaultAddEditLoginItems(
value = commonState.name, value = commonState.name,
onValueChange = commonActionHandler.onNameTextChange, onValueChange = commonActionHandler.onNameTextChange,
modifier = Modifier modifier = Modifier
.semantics { testTag = "ItemNameEntry" }
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = 16.dp), .padding(horizontal = 16.dp),
) )
@ -109,7 +110,8 @@ fun LazyListScope.vaultAddEditLoginItems(
BitwardenTextFieldWithActions( BitwardenTextFieldWithActions(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = 16.dp), .padding(horizontal = 16.dp)
.semantics { testTag = "LoginTotpEntry" },
label = stringResource(id = R.string.totp), label = stringResource(id = R.string.totp),
value = loginState.totp, value = loginState.totp,
trailingIconContent = { trailingIconContent = {
@ -153,6 +155,7 @@ fun LazyListScope.vaultAddEditLoginItems(
icon = painterResource(id = R.drawable.ic_light_bulb), icon = painterResource(id = R.drawable.ic_light_bulb),
onClick = onTotpSetupClick, onClick = onTotpSetupClick,
modifier = Modifier modifier = Modifier
.semantics { testTag = "SetupTotpButton" }
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = 16.dp), .padding(horizontal = 16.dp),
) )
@ -184,6 +187,7 @@ fun LazyListScope.vaultAddEditLoginItems(
label = stringResource(id = R.string.new_uri), label = stringResource(id = R.string.new_uri),
onClick = loginItemTypeHandlers.onAddNewUriClick, onClick = loginItemTypeHandlers.onAddNewUriClick,
modifier = Modifier modifier = Modifier
.semantics { testTag = "LoginAddNewUriButton" }
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = 16.dp), .padding(horizontal = 16.dp),
) )
@ -393,7 +397,9 @@ private fun UsernameRow(
modifier = Modifier.semantics { testTag = "GenerateUsernameButton" }, modifier = Modifier.semantics { testTag = "GenerateUsernameButton" },
) )
}, },
modifier = Modifier.padding(horizontal = 16.dp), modifier = Modifier
.semantics { testTag = "LoginUsernameEntry" }
.padding(horizontal = 16.dp),
) )
if (shouldShowDialog) { if (shouldShowDialog) {
@ -432,6 +438,8 @@ private fun PasswordRow(
label = stringResource(id = R.string.password), label = stringResource(id = R.string.password),
value = loginState.password, value = loginState.password,
onValueChange = loginItemTypeHandlers.onPasswordTextChange, onValueChange = loginItemTypeHandlers.onPasswordTextChange,
showPasswordTestTag = "ViewPasswordButton",
passwordFieldTestTag = "LoginPasswordEntry",
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = 16.dp), .padding(horizontal = 16.dp),
@ -442,6 +450,8 @@ private fun PasswordRow(
contentDescription = stringResource(id = R.string.check_password), contentDescription = stringResource(id = R.string.check_password),
), ),
onClick = loginItemTypeHandlers.onPasswordCheckerClick, onClick = loginItemTypeHandlers.onPasswordCheckerClick,
modifier = Modifier
.semantics { testTag = "CheckPasswordButton" },
) )
BitwardenIconButtonWithResource( BitwardenIconButtonWithResource(
iconRes = IconResource( iconRes = IconResource(
@ -455,6 +465,8 @@ private fun PasswordRow(
shouldShowDialog = true shouldShowDialog = true
} }
}, },
modifier = Modifier
.semantics { testTag = "RegeneratePasswordButton" },
) )
if (shouldShowDialog) { if (shouldShowDialog) {
@ -485,7 +497,8 @@ private fun PasswordRow(
value = loginState.password, value = loginState.password,
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = 16.dp), .padding(horizontal = 16.dp)
.semantics { testTag = "LoginPasswordEntry" },
) )
} }
} }

View file

@ -9,6 +9,8 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTag
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import com.x8bit.bitwarden.R import com.x8bit.bitwarden.R
import com.x8bit.bitwarden.ui.platform.components.dialog.BitwardenSelectionDialog import com.x8bit.bitwarden.ui.platform.components.dialog.BitwardenSelectionDialog
@ -46,9 +48,12 @@ fun VaultAddEditUriItem(
contentDescription = stringResource(id = R.string.options), contentDescription = stringResource(id = R.string.options),
), ),
onClick = { shouldShowOptionsDialog = true }, onClick = { shouldShowOptionsDialog = true },
modifier = Modifier.semantics { testTag = "LoginUriOptionsButton" },
) )
}, },
modifier = Modifier.padding(horizontal = 16.dp), modifier = Modifier
.semantics { testTag = "LoginUriEntry" }
.padding(horizontal = 16.dp),
) )
if (shouldShowOptionsDialog) { if (shouldShowOptionsDialog) {