Skip to content

Commit

Permalink
fix: Address PR comments - 3
Browse files Browse the repository at this point in the history
  • Loading branch information
omerhabib26 committed Feb 12, 2024
1 parent 3abb651 commit 82b9973
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 53 deletions.
20 changes: 10 additions & 10 deletions auth/src/main/java/org/openedx/auth/presentation/ui/AuthUI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import org.openedx.auth.R
import org.openedx.core.domain.model.RegistrationField
import org.openedx.core.domain.model.RegistrationFieldType
import org.openedx.core.extension.TextConverter
import org.openedx.core.extension.withoutSpaces
import org.openedx.core.extension.tagId
import org.openedx.core.ui.HyperlinkText
import org.openedx.core.ui.SheetContent
import org.openedx.core.ui.noRippleClickable
Expand Down Expand Up @@ -87,7 +87,7 @@ fun RequiredFields(
val linkedText =
TextConverter.htmlTextToLinkedText(field.label)
HyperlinkText(
modifier = Modifier.testTag("txt_${field.name.withoutSpaces()}"),
modifier = Modifier.testTag("txt_${field.name.tagId()}"),
fullText = linkedText.text,
hyperLinks = linkedText.links,
linkTextColor = MaterialTheme.appColors.primary
Expand Down Expand Up @@ -309,7 +309,7 @@ fun InputRegistrationField(
Column {
Text(
modifier = Modifier
.testTag("txt_${registrationField.name.withoutSpaces()}_label")
.testTag("txt_${registrationField.name.tagId()}_label")
.fillMaxWidth(),
text = registrationField.label,
style = MaterialTheme.appTypography.labelLarge,
Expand All @@ -333,7 +333,7 @@ fun InputRegistrationField(
shape = MaterialTheme.appShapes.textFieldShape,
placeholder = {
Text(
modifier = modifier.testTag("txt_${registrationField.name.withoutSpaces()}_placeholder"),
modifier = modifier.testTag("txt_${registrationField.name.tagId()}_placeholder"),
text = registrationField.label,
color = MaterialTheme.appColors.textFieldHint,
style = MaterialTheme.appTypography.bodyMedium
Expand All @@ -349,11 +349,11 @@ fun InputRegistrationField(
},
textStyle = MaterialTheme.appTypography.bodyMedium,
singleLine = isSingleLine,
modifier = modifier.testTag("tf_${registrationField.name.withoutSpaces()}")
modifier = modifier.testTag("tf_${registrationField.name.tagId()}")
)
Spacer(modifier = Modifier.height(6.dp))
Text(
modifier = Modifier.testTag("txt_${registrationField.name.withoutSpaces()}_description"),
modifier = Modifier.testTag("txt_${registrationField.name.tagId()}_description"),
text = helperText,
style = MaterialTheme.appTypography.bodySmall,
color = helperTextColor
Expand Down Expand Up @@ -396,7 +396,7 @@ fun SelectableRegisterField(
) {
Text(
modifier = Modifier
.testTag("txt_${registrationField.name.withoutSpaces()}_label")
.testTag("txt_${registrationField.name.tagId()}_label")
.fillMaxWidth(),
text = registrationField.label,
style = MaterialTheme.appTypography.labelLarge,
Expand All @@ -418,14 +418,14 @@ fun SelectableRegisterField(
textStyle = MaterialTheme.appTypography.bodyMedium,
onValueChange = { },
modifier = Modifier
.testTag("tf_${registrationField.name.withoutSpaces()}")
.testTag("tf_${registrationField.name.tagId()}")
.fillMaxWidth()
.noRippleClickable {
onClick(registrationField.name, registrationField.options)
},
placeholder = {
Text(
modifier = Modifier.testTag("txt_${registrationField.name.withoutSpaces()}_placeholder"),
modifier = Modifier.testTag("txt_${registrationField.name.tagId()}_placeholder"),
text = registrationField.label,
color = MaterialTheme.appColors.textFieldHint,
style = MaterialTheme.appTypography.bodyMedium
Expand All @@ -441,7 +441,7 @@ fun SelectableRegisterField(
)
Spacer(modifier = Modifier.height(6.dp))
Text(
modifier = Modifier.testTag("txt_${registrationField.name.withoutSpaces()}_description"),
modifier = Modifier.testTag("txt_${registrationField.name.tagId()}_description"),
text = helperText,
style = MaterialTheme.appTypography.bodySmall,
color = helperTextColor
Expand Down
5 changes: 4 additions & 1 deletion core/src/main/java/org/openedx/core/extension/StringExt.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.openedx.core.extension

import android.util.Patterns
import java.util.Locale
import java.util.regex.Pattern


Expand Down Expand Up @@ -29,4 +30,6 @@ fun String.replaceLinkTags(isDarkTheme: Boolean): String {
return text
}

fun String.withoutSpaces(): String = this.replace(" ", "")
fun String.replaceSpaces(target: String = ""): String = this.replace(" ", target)

fun String.tagId(): String = this.replaceSpaces("_").lowercase(Locale.getDefault())
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import org.openedx.core.R
import org.openedx.core.extension.withoutSpaces
import org.openedx.core.ui.noRippleClickable
import org.openedx.core.ui.statusBarsInset
import org.openedx.core.ui.theme.OpenEdXTheme
Expand Down Expand Up @@ -265,7 +264,7 @@ fun TransparentTextButton(
) {
Button(
modifier = Modifier
.testTag("btn_upgrade_dialog_${text.withoutSpaces()}")
.testTag("btn_secondary")
.height(42.dp),
colors = ButtonDefaults.buttonColors(
backgroundColor = Color.Transparent
Expand All @@ -275,7 +274,7 @@ fun TransparentTextButton(
onClick = onClick
) {
Text(
modifier = Modifier.testTag("txt_app_upgrade_dialog_${text.withoutSpaces()}"),
modifier = Modifier.testTag("txt_secondary"),
color = MaterialTheme.appColors.textAccent,
style = MaterialTheme.appTypography.labelLarge,
text = text
Expand All @@ -290,7 +289,7 @@ fun DefaultTextButton(
) {
Button(
modifier = Modifier
.testTag("btn_upgrade_dialog_${text.withoutSpaces()}")
.testTag("btn_primary")
.height(42.dp),
colors = ButtonDefaults.buttonColors(
backgroundColor = MaterialTheme.appColors.buttonBackground
Expand All @@ -304,7 +303,7 @@ fun DefaultTextButton(
horizontalArrangement = Arrangement.Center
) {
Text(
modifier = Modifier.testTag("txt_app_upgrade_dialog_${text.withoutSpaces()}"),
modifier = Modifier.testTag("txt_primary"),
text = text,
color = MaterialTheme.appColors.buttonText,
style = MaterialTheme.appTypography.labelLarge
Expand Down
30 changes: 15 additions & 15 deletions core/src/main/java/org/openedx/core/ui/ComposeCommon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ import org.openedx.core.UIMessage
import org.openedx.core.domain.model.Course
import org.openedx.core.domain.model.RegistrationField
import org.openedx.core.extension.LinkedImageText
import org.openedx.core.extension.tagId
import org.openedx.core.extension.toastMessage
import org.openedx.core.extension.withoutSpaces
import org.openedx.core.ui.theme.OpenEdXTheme
import org.openedx.core.ui.theme.appColors
import org.openedx.core.ui.theme.appShapes
Expand Down Expand Up @@ -620,7 +620,7 @@ fun SheetContent(
}) { item ->
Text(
modifier = Modifier
.testTag("txt_${item.value.withoutSpaces()}_title")
.testTag("txt_${item.value.tagId()}_title")
.fillMaxWidth()
.padding(horizontal = 16.dp)
.clickable {
Expand Down Expand Up @@ -721,7 +721,7 @@ fun OpenEdXOutlinedTextField(
Column {
Text(
modifier = Modifier
.testTag("txt_${title.withoutSpaces()}_label")
.testTag("txt_${title.tagId()}_label")
.fillMaxWidth(),
text = buildAnnotatedString {
if (withRequiredMark) {
Expand Down Expand Up @@ -768,12 +768,12 @@ fun OpenEdXOutlinedTextField(
textStyle = MaterialTheme.appTypography.bodyMedium,
singleLine = isSingleLine,
isError = !errorText.isNullOrEmpty(),
modifier = modifier.testTag("tf_${title.withoutSpaces()}_input")
modifier = modifier.testTag("tf_${title.tagId()}_input")
)
if (!errorText.isNullOrEmpty()) {
Spacer(modifier = Modifier.height(6.dp))
Text(
modifier = Modifier.testTag("txt_${title.withoutSpaces()}_error"),
modifier = Modifier.testTag("txt_${title.tagId()}_error"),
text = errorText,
style = MaterialTheme.appTypography.bodySmall,
color = MaterialTheme.appColors.error
Expand Down Expand Up @@ -902,7 +902,7 @@ fun IconText(
Modifier
} else {
Modifier
.testTag("btn_${text.withoutSpaces()}")
.testTag("btn_${text.tagId()}")
.noRippleClickable { onClick.invoke() }
}
Row(
Expand All @@ -912,14 +912,14 @@ fun IconText(
) {
Icon(
modifier = Modifier
.testTag("ic_${text.withoutSpaces()}")
.testTag("ic_${text.tagId()}")
.size((textStyle.fontSize.value + 4).dp),
imageVector = icon,
contentDescription = null,
tint = color
)
Text(
modifier = Modifier.testTag("txt_${text.withoutSpaces()}"),
modifier = Modifier.testTag("txt_${text.tagId()}"),
text = text,
color = color,
style = textStyle
Expand All @@ -940,7 +940,7 @@ fun IconText(
Modifier
} else {
Modifier
.testTag("btn_${text.withoutSpaces()}")
.testTag("btn_${text.tagId()}")
.noRippleClickable { onClick.invoke() }
}
Row(
Expand All @@ -950,14 +950,14 @@ fun IconText(
) {
Icon(
modifier = Modifier
.testTag("ic_${text.withoutSpaces()}")
.testTag("ic_${text.tagId()}")
.size((textStyle.fontSize.value + 4).dp),
painter = painter,
contentDescription = null,
tint = color
)
Text(
modifier = Modifier.testTag("txt_${text.withoutSpaces()}"),
modifier = Modifier.testTag("txt_${text.tagId()}"),
text = text,
color = color,
style = textStyle
Expand Down Expand Up @@ -1080,7 +1080,7 @@ fun OpenEdXButton(
) {
Button(
modifier = Modifier
.testTag("btn_${text.withoutSpaces()}")
.testTag("btn_${text.tagId()}")
.then(width)
.height(42.dp),
shape = MaterialTheme.appShapes.buttonShape,
Expand All @@ -1092,7 +1092,7 @@ fun OpenEdXButton(
) {
if (content == null) {
Text(
modifier = Modifier.testTag("txt_${text.withoutSpaces()}"),
modifier = Modifier.testTag("txt_${text.tagId()}"),
text = text,
color = MaterialTheme.appColors.buttonText,
style = MaterialTheme.appTypography.labelLarge
Expand All @@ -1115,7 +1115,7 @@ fun OpenEdXOutlinedButton(
) {
OutlinedButton(
modifier = Modifier
.testTag("btn_${text.withoutSpaces()}")
.testTag("btn_${text.tagId()}")
.then(modifier)
.height(42.dp),
onClick = onClick,
Expand All @@ -1125,7 +1125,7 @@ fun OpenEdXOutlinedButton(
) {
if (content == null) {
Text(
modifier = Modifier.testTag("txt_${text.withoutSpaces()}"),
modifier = Modifier.testTag("txt_${text.tagId()}"),
text = text,
style = MaterialTheme.appTypography.labelLarge,
color = textColor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ import org.openedx.core.domain.model.ProfileImage
import org.openedx.core.domain.model.RegistrationField
import org.openedx.core.extension.getFileName
import org.openedx.core.extension.parcelable
import org.openedx.core.extension.withoutSpaces
import org.openedx.core.extension.tagId
import org.openedx.core.ui.AutoSizeText
import org.openedx.core.ui.BackBtn
import org.openedx.core.ui.HandleUIMessage
Expand Down Expand Up @@ -982,7 +982,7 @@ private fun SelectableField(
Column {
Text(
modifier = Modifier
.testTag("txt_edit_profile_field_label_${name.withoutSpaces()}")
.testTag("txt_label_${name.tagId()}")
.fillMaxWidth(),
text = name,
style = MaterialTheme.appTypography.labelLarge,
Expand All @@ -1005,14 +1005,14 @@ private fun SelectableField(
)
},
modifier = Modifier
.testTag("tf_edit_profile_field_select_${name.withoutSpaces()}")
.testTag("tf_select_${name.tagId()}")
.fillMaxWidth()
.noRippleClickable {
onClick()
},
placeholder = {
Text(
modifier = Modifier.testTag("txt_edit_profile_field_placeholder_${name.withoutSpaces()}"),
modifier = Modifier.testTag("txt_placeholder_${name.tagId()}"),
text = name,
color = MaterialTheme.appColors.textFieldHint,
style = MaterialTheme.appTypography.bodyMedium
Expand All @@ -1038,7 +1038,7 @@ private fun InputEditField(
Column {
Text(
modifier = Modifier
.testTag("txt_edit_profile_field_label_${name.withoutSpaces()}")
.testTag("txt_label_${name.tagId()}")
.fillMaxWidth(),
text = name,
style = MaterialTheme.appTypography.labelLarge,
Expand All @@ -1058,7 +1058,7 @@ private fun InputEditField(
shape = MaterialTheme.appShapes.textFieldShape,
placeholder = {
Text(
modifier = Modifier.testTag("txt_edit_profile_field_${name.withoutSpaces()}_placeholder"),
modifier = Modifier.testTag("txt_placeholder_${name.tagId()}"),
text = name,
color = MaterialTheme.appColors.textFieldHint,
style = MaterialTheme.appTypography.bodyMedium
Expand All @@ -1074,7 +1074,7 @@ private fun InputEditField(
onDoneClick()
},
textStyle = MaterialTheme.appTypography.bodyMedium,
modifier = modifier.testTag("tf_edit_profile_field_input_${name.withoutSpaces()}")
modifier = modifier.testTag("tf_input_${name.tagId()}")
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import org.openedx.core.R
import org.openedx.core.UIMessage
import org.openedx.core.domain.model.AgreementUrls
import org.openedx.core.domain.model.ProfileImage
import org.openedx.core.extension.withoutSpaces
import org.openedx.core.extension.tagId
import org.openedx.core.presentation.global.AppData
import org.openedx.core.system.notifier.AppUpgradeEvent
import org.openedx.core.ui.HandleUIMessage
Expand Down Expand Up @@ -516,7 +516,7 @@ private fun ProfileInfoItem(
}
Row(
Modifier
.testTag("btn_profile_info_item_${text.withoutSpaces()}")
.testTag("btn_${text.tagId()}")
.fillMaxWidth()
.clickable { onClick() }
.padding(20.dp),
Expand All @@ -525,7 +525,7 @@ private fun ProfileInfoItem(
) {
Text(
modifier = Modifier
.testTag("txt_profile_info_item_title_${text.withoutSpaces()}")
.testTag("txt_${text.tagId()}")
.weight(1f),
text = text,
maxLines = 1,
Expand Down
Loading

0 comments on commit 82b9973

Please sign in to comment.