Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PM-14179: Update generator screen copy button #4530

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ import kotlinx.collections.immutable.toImmutableList
* @param keyboardType the preferred type of keyboard input.
* @param textToolbarType The type of [TextToolbar] to use on the text field.
*/
@Suppress("LongMethod")
@Suppress("LongMethod", "CyclomaticComplexMethod")
@Composable
fun BitwardenTextField(
label: String,
label: String?,
value: String,
onValueChange: (String) -> Unit,
modifier: Modifier = Modifier,
Expand Down Expand Up @@ -136,7 +136,7 @@ fun BitwardenTextField(
.focusRequester(focusRequester)
.fillMaxWidth(),
enabled = enabled,
label = { Text(text = label) },
label = label?.let { { Text(text = it) } },
value = textFieldValue,
leadingIcon = leadingIconResource?.let { iconResource ->
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.TextToolbar
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTag
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.VisualTransformation
Expand Down Expand Up @@ -48,7 +47,7 @@ import com.x8bit.bitwarden.ui.platform.theme.BitwardenTheme
*/
@Composable
fun BitwardenTextFieldWithActions(
label: String,
label: String?,
value: String,
onValueChange: (String) -> Unit,
modifier: Modifier = Modifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import com.x8bit.bitwarden.ui.platform.components.appbar.BitwardenMediumTopAppBa
import com.x8bit.bitwarden.ui.platform.components.appbar.BitwardenTopAppBar
import com.x8bit.bitwarden.ui.platform.components.appbar.action.BitwardenOverflowActionItem
import com.x8bit.bitwarden.ui.platform.components.appbar.action.OverflowMenuItemData
import com.x8bit.bitwarden.ui.platform.components.button.BitwardenFilledButton
import com.x8bit.bitwarden.ui.platform.components.button.BitwardenTextButton
import com.x8bit.bitwarden.ui.platform.components.button.BitwardenTonalIconButton
import com.x8bit.bitwarden.ui.platform.components.card.BitwardenInfoCalloutCard
Expand Down Expand Up @@ -302,8 +303,8 @@ private fun ScrollContent(
.fillMaxHeight()
.verticalScroll(rememberScrollState()),
) {
Spacer(modifier = Modifier.height(12.dp))
if (state.isUnderPolicy) {
Spacer(modifier = Modifier.height(8.dp))
BitwardenInfoCalloutCard(
text = stringResource(id = R.string.password_generator_policy_in_effect),
modifier = Modifier
Expand All @@ -312,16 +313,29 @@ private fun ScrollContent(
.fillMaxWidth(),
)

Spacer(modifier = Modifier.height(8.dp))
Spacer(modifier = Modifier.height(12.dp))
}

GeneratedStringItem(
generatedText = state.generatedText,
onCopyClick = onCopyClick,
onRegenerateClick = onRegenerateClick,
modifier = Modifier
.padding(horizontal = 16.dp)
.fillMaxWidth(),
)

Spacer(modifier = Modifier.height(12.dp))

BitwardenFilledButton(
label = stringResource(id = R.string.copy),
onClick = onCopyClick,
modifier = Modifier
.testTag(tag = "CopyValueButton")
.fillMaxWidth()
.padding(horizontal = 16.dp),
)

Spacer(modifier = Modifier.height(16.dp))
Spacer(modifier = Modifier.height(24.dp))

BitwardenListHeaderText(
label = stringResource(id = R.string.options),
Expand Down Expand Up @@ -365,22 +379,15 @@ private fun ScrollContent(
@Composable
private fun GeneratedStringItem(
generatedText: String,
onCopyClick: () -> Unit,
onRegenerateClick: () -> Unit,
modifier: Modifier = Modifier,
) {
BitwardenTextFieldWithActions(
label = "",
label = null,
textFieldTestTag = "GeneratedPasswordLabel",
value = generatedText,
singleLine = false,
actions = {
BitwardenTonalIconButton(
vectorIconRes = R.drawable.ic_copy,
contentDescription = stringResource(id = R.string.copy),
onClick = onCopyClick,
modifier = Modifier.testTag("CopyValueButton"),
)
BitwardenTonalIconButton(
vectorIconRes = R.drawable.ic_generate,
contentDescription = stringResource(id = R.string.generate_password),
Expand All @@ -393,7 +400,7 @@ private fun GeneratedStringItem(
textStyle = BitwardenTheme.typography.sensitiveInfoSmall,
shouldAddCustomLineBreaks = true,
visualTransformation = nonLetterColorVisualTransformation(),
modifier = modifier.padding(horizontal = 16.dp),
modifier = modifier,
textToolbarType = TextToolbarType.NONE,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class GeneratorScreenTest : BaseComposeTest() {
@Test
fun `clicking the Copy button should send CopyClick action`() {
composeTestRule
.onNodeWithContentDescription(label = "Copy")
.onNodeWithText(text = "Copy")
.performClick()

verify {
Expand Down