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

ANDROID-15325 Compose Input test ids #396

Merged
merged 4 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -3,6 +3,7 @@ package com.telefonica.mistica.compose.input
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.style.TextAlign
import com.telefonica.mistica.compose.theme.MisticaTheme

Expand All @@ -18,7 +19,7 @@ internal fun CharsCounter(
color = if (isError) MisticaTheme.colors.error else MisticaTheme.colors.textSecondary,
textAlign = TextAlign.End,
style = MisticaTheme.typography.preset1,
modifier = modifier,
modifier = modifier.testTag(TextInputTestTags.END_HELPER_TEXT),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.telefonica.mistica.compose.input

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.VisualTransformation

Expand All @@ -23,7 +24,7 @@ fun EmailInput(
keyboardOptions: KeyboardOptions = KeyboardOptions.Default
) {
TextInputImpl(
modifier = modifier,
modifier = modifier.testTag(TextInputTestTags.EMAIL_INPUT),
value = value,
onValueChange = onValueChange,
label = label,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.telefonica.mistica.compose.input

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.VisualTransformation

Expand All @@ -24,7 +25,7 @@ fun NumberInput(
) {

TextInputImpl(
modifier = modifier,
modifier = modifier.testTag(TextInputTestTags.DECIMAL_INPUT),
value = value,
onValueChange = onValueChange,
label = label,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fun PasswordInput(
}

TextInputImpl(
modifier = modifier,
modifier = modifier.testTag(TextInputTestTags.PASSWORD_INPUT),
value = value,
onValueChange = onValueChange,
label = label,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.telefonica.mistica.compose.input

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.VisualTransformation

Expand All @@ -23,7 +24,7 @@ fun PhoneInput(
keyboardOptions: KeyboardOptions = KeyboardOptions.Default
) {
TextInputImpl(
modifier = modifier,
modifier = modifier.testTag(TextInputTestTags.PHONE_NUMBER_INPUT),
value = value,
onValueChange = onValueChange,
label = label,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fun SearchInput(
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
) {
TextInputImpl(
modifier = modifier,
modifier = modifier.testTag(TextInputTestTags.SEARCH_INPUT),
value = value,
onValueChange = onValueChange,
label = label,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.VisualTransformation
Expand Down Expand Up @@ -34,7 +35,7 @@ fun TextAreaInput(
}

TextInputImpl(
modifier = modifier,
modifier = modifier.testTag(TextInputTestTags.TEXT_INPUT),
value = value,
onValueChange = { newValue ->
currentChars = doOnValueChange(maxChars, newValue, onValueChange)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import androidx.compose.foundation.border
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsFocusedAsState
import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Text
import androidx.compose.material.TextField
Expand Down Expand Up @@ -105,7 +107,6 @@ private fun TextBox(

TextField(
modifier = modifier
.testTag(TextInputTestTags.TEXT_INPUT)
.fillMaxWidth()
.border(
width = 1.dp,
Expand All @@ -122,6 +123,7 @@ private fun TextBox(
visualTransformation.filter(AnnotatedString(value))
}
TextInputLabel(
modifier = Modifier.testTag(TextInputTestTags.LABEL),
text = it,
inputIsNotEmpty = transformedText.text.isNotEmpty(),
isFocused = interactionSource.collectIsFocusedAsState().value,
Expand All @@ -132,8 +134,28 @@ private fun TextBox(
interactionSource = interactionSource,
keyboardOptions = keyboardOptions,
isError = isError,
leadingIcon = leadingIcon,
trailingIcon = trailingIcon,
leadingIcon = leadingIcon?.let { icon ->
{
Box(
modifier = Modifier
.wrapContentSize()
.testTag(TextInputTestTags.START_ICON)
) {
icon()
}
}
},
trailingIcon = trailingIcon?.let { icon ->
{
Box(
modifier = Modifier
.wrapContentSize()
.testTag(TextInputTestTags.END_ICON)
) {
icon()
}
}
},
shape = RoundedCornerShape(MisticaTheme.radius.inputBorderRadius),
colors = TextFieldDefaults.textFieldColors(
backgroundColor = MisticaTheme.colors.backgroundContainer,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
package com.telefonica.mistica.compose.input

object TextInputTestTags {
const val TEXT_INPUT = "text_input"
const val TEXT_INPUT = "TextField"
yamal-alm marked this conversation as resolved.
Show resolved Hide resolved
const val PASSWORD_INPUT = "PasswordField"
const val SEARCH_INPUT = "SearchField"
const val PHONE_NUMBER_INPUT = "PhoneNumberField"
const val EMAIL_INPUT = "EmailField"
const val DECIMAL_INPUT = "DecimalField"
const val LABEL = "label"
const val HELPER_TEXT = "helperText"
const val END_HELPER_TEXT = "endHelperText"
const val ERROR_TEXT = "errorText"
const val START_ICON = "startIcon"
const val END_ICON = "endIcon"

const val PASSWORD_VISIBILITY_TOGGLE = "password_visibility_toggle"
const val CLEAR_SEARCH_BUTTON = "clear_search_button"
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.telefonica.mistica.compose.theme.MisticaTheme
Expand Down Expand Up @@ -43,11 +44,13 @@ internal fun Underline(
Row(modifier = Modifier.fillMaxWidth()) {
Box {
UnderlineTextAnimatedVisibility(
isError = isError,
visible = !isError && helperText != null,
text = helperText,
color = LocalUnderlineTextColors.current.helperTextColor,
)
UnderlineTextAnimatedVisibility(
isError = isError,
visible = isError && errorText != null,
text = errorText,
color = LocalUnderlineTextColors.current.errorTextColor,
Expand All @@ -65,6 +68,7 @@ internal fun Underline(

@Composable
private fun UnderlineTextAnimatedVisibility(
isError: Boolean,
visible: Boolean,
text: String?,
color: Color,
Expand All @@ -75,18 +79,29 @@ private fun UnderlineTextAnimatedVisibility(
exit = fadeOut(animationSpec = tween(0)),
) {
if (text != null) {
UnderlineText(text = text, color = color)
UnderlineText(
modifier = Modifier.testTag(
if (isError) {
TextInputTestTags.ERROR_TEXT
} else {
TextInputTestTags.HELPER_TEXT
}
),
text = text,
color = color,
)
}
}
}

@Composable
private fun UnderlineText(
modifier: Modifier,
text: String,
color: Color,
) {
Text(
modifier = Modifier.padding(top = 4.dp, start = 14.dp, end = 14.dp),
modifier = modifier.padding(top = 4.dp, start = 14.dp, end = 14.dp),
text = text,
style = MisticaTheme.typography.preset1,
color = color,
Expand Down
Loading