mirror of
https://github.com/bitwarden/android.git
synced 2024-10-31 15:15:34 +03:00
BIT-1177: Added test tags for password history (#656)
This commit is contained in:
parent
840f675736
commit
514e9a79fd
2 changed files with 18 additions and 2 deletions
|
@ -18,6 +18,8 @@ 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.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
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.DpOffset
|
import androidx.compose.ui.unit.DpOffset
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
@ -63,6 +65,11 @@ fun BitwardenOverflowActionItem(
|
||||||
content = {
|
content = {
|
||||||
menuItemDataList.forEach { dropdownMenuItemData ->
|
menuItemDataList.forEach { dropdownMenuItemData ->
|
||||||
DropdownMenuItem(
|
DropdownMenuItem(
|
||||||
|
modifier = Modifier.semantics {
|
||||||
|
dropdownMenuItemData.testTag?.let {
|
||||||
|
testTag = it
|
||||||
|
}
|
||||||
|
},
|
||||||
text = {
|
text = {
|
||||||
Text(
|
Text(
|
||||||
text = dropdownMenuItemData.text,
|
text = dropdownMenuItemData.text,
|
||||||
|
@ -100,8 +107,10 @@ private fun BitwardenOverflowActionItem_preview() {
|
||||||
*
|
*
|
||||||
* @param text The text displayed for the item in the menu.
|
* @param text The text displayed for the item in the menu.
|
||||||
* @param onClick A callback for when the menu item is clicked.
|
* @param onClick A callback for when the menu item is clicked.
|
||||||
|
* @param testTag Optional test tag for the menu item.
|
||||||
*/
|
*/
|
||||||
data class OverflowMenuItemData(
|
data class OverflowMenuItemData(
|
||||||
val text: String,
|
val text: String,
|
||||||
val onClick: () -> Unit,
|
val onClick: () -> Unit,
|
||||||
|
val testTag: String? = null,
|
||||||
)
|
)
|
||||||
|
|
|
@ -23,11 +23,15 @@ import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
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.semantics.testTagsAsResourceId
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
|
@ -43,7 +47,7 @@ import kotlinx.collections.immutable.persistentListOf
|
||||||
* Displays the password history screen
|
* Displays the password history screen
|
||||||
*/
|
*/
|
||||||
@Suppress("LongMethod")
|
@Suppress("LongMethod")
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class, ExperimentalComposeUiApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun PasswordHistoryScreen(
|
fun PasswordHistoryScreen(
|
||||||
onNavigateBack: () -> Unit,
|
onNavigateBack: () -> Unit,
|
||||||
|
@ -66,6 +70,7 @@ fun PasswordHistoryScreen(
|
||||||
BitwardenScaffold(
|
BitwardenScaffold(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
|
.semantics { testTagsAsResourceId = true }
|
||||||
.nestedScroll(scrollBehavior.nestedScrollConnection),
|
.nestedScroll(scrollBehavior.nestedScrollConnection),
|
||||||
topBar = {
|
topBar = {
|
||||||
BitwardenTopAppBar(
|
BitwardenTopAppBar(
|
||||||
|
@ -80,6 +85,7 @@ fun PasswordHistoryScreen(
|
||||||
BitwardenOverflowActionItem(
|
BitwardenOverflowActionItem(
|
||||||
menuItemDataList = persistentListOf(
|
menuItemDataList = persistentListOf(
|
||||||
OverflowMenuItemData(
|
OverflowMenuItemData(
|
||||||
|
testTag = "ClearPasswordList",
|
||||||
text = stringResource(id = R.string.clear),
|
text = stringResource(id = R.string.clear),
|
||||||
onClick = remember(viewModel) {
|
onClick = remember(viewModel) {
|
||||||
{
|
{
|
||||||
|
@ -158,7 +164,7 @@ private fun PasswordHistoryContent(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
onPasswordCopyClick: (PasswordHistoryState.GeneratedPassword) -> Unit,
|
onPasswordCopyClick: (PasswordHistoryState.GeneratedPassword) -> Unit,
|
||||||
) {
|
) {
|
||||||
LazyColumn(modifier = modifier) {
|
LazyColumn(modifier = modifier.semantics { testTag = "GeneratedPasswordRow" }) {
|
||||||
items(state.passwords) { password ->
|
items(state.passwords) { password ->
|
||||||
PasswordHistoryListItem(
|
PasswordHistoryListItem(
|
||||||
label = password.password,
|
label = password.password,
|
||||||
|
@ -204,6 +210,7 @@ private fun PasswordHistoryEmpty(modifier: Modifier = Modifier) {
|
||||||
contentAlignment = Alignment.Center,
|
contentAlignment = Alignment.Center,
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
|
modifier = Modifier.semantics { testTag = "NoPasswordsDisplayedLabel" },
|
||||||
text = stringResource(id = R.string.no_passwords_to_list),
|
text = stringResource(id = R.string.no_passwords_to_list),
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue