Skip to content

Commit

Permalink
fix: Added element IDs for automation (openedx#214)
Browse files Browse the repository at this point in the history
- Added Element IDs for automation to Views
  • Loading branch information
omerhabib26 authored Feb 15, 2024
1 parent f4731df commit dedb010
Show file tree
Hide file tree
Showing 22 changed files with 750 additions and 370 deletions.
14 changes: 12 additions & 2 deletions app/src/main/java/org/openedx/app/InDevelopmentFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,32 @@ import androidx.compose.material.MaterialTheme
import androidx.compose.material.Scaffold
import androidx.compose.material.Text
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
import androidx.fragment.app.Fragment
import org.openedx.core.ui.theme.appColors
import org.openedx.core.ui.theme.appTypography

class InDevelopmentFragment : Fragment() {

@OptIn(ExperimentalComposeUiApi::class)
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
) = ComposeView(requireContext()).apply {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
setContent {
Scaffold {
Scaffold(
modifier = Modifier.semantics {
testTagsAsResourceId = true
},
) {
Box(
modifier = Modifier
.fillMaxSize()
Expand All @@ -36,11 +45,12 @@ class InDevelopmentFragment : Fragment() {
contentAlignment = Alignment.Center
) {
Text(
modifier = Modifier.testTag("txt_in_development"),
text = "Will be available soon",
style = MaterialTheme.appTypography.headlineMedium
)
}
}
}
}
}
}
19 changes: 10 additions & 9 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,6 +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.tagId
import org.openedx.core.ui.HyperlinkText
import org.openedx.core.ui.SheetContent
import org.openedx.core.ui.noRippleClickable
Expand Down Expand Up @@ -86,7 +87,7 @@ fun RequiredFields(
val linkedText =
TextConverter.htmlTextToLinkedText(field.label)
HyperlinkText(
modifier = Modifier.testTag("txt_${field.name}"),
modifier = Modifier.testTag("txt_${field.name.tagId()}"),
fullText = linkedText.text,
hyperLinks = linkedText.links,
linkTextColor = MaterialTheme.appColors.primary
Expand Down Expand Up @@ -305,7 +306,7 @@ fun InputRegistrationField(
Column {
Text(
modifier = Modifier
.testTag("txt_${registrationField.name}_label")
.testTag("txt_${registrationField.name.tagId()}_label")
.fillMaxWidth(),
text = registrationField.label,
style = MaterialTheme.appTypography.labelLarge,
Expand All @@ -329,7 +330,7 @@ fun InputRegistrationField(
shape = MaterialTheme.appShapes.textFieldShape,
placeholder = {
Text(
modifier = modifier.testTag("txt_${registrationField.name}_placeholder"),
modifier = modifier.testTag("txt_${registrationField.name.tagId()}_placeholder"),
text = registrationField.label,
color = MaterialTheme.appColors.textFieldHint,
style = MaterialTheme.appTypography.bodyMedium
Expand All @@ -345,11 +346,11 @@ fun InputRegistrationField(
},
textStyle = MaterialTheme.appTypography.bodyMedium,
singleLine = isSingleLine,
modifier = modifier.testTag("tf_${registrationField.name}")
modifier = modifier.testTag("tf_${registrationField.name.tagId()}")
)
Spacer(modifier = Modifier.height(6.dp))
Text(
modifier = Modifier.testTag("txt_${registrationField.name}_description"),
modifier = Modifier.testTag("txt_${registrationField.name.tagId()}_description"),
text = helperText,
style = MaterialTheme.appTypography.bodySmall,
color = helperTextColor
Expand Down Expand Up @@ -392,7 +393,7 @@ fun SelectableRegisterField(
) {
Text(
modifier = Modifier
.testTag("txt_${registrationField.name}_label")
.testTag("txt_${registrationField.name.tagId()}_label")
.fillMaxWidth(),
text = registrationField.label,
style = MaterialTheme.appTypography.labelLarge,
Expand All @@ -414,14 +415,14 @@ fun SelectableRegisterField(
textStyle = MaterialTheme.appTypography.bodyMedium,
onValueChange = { },
modifier = Modifier
.testTag("tf_${registrationField.name}")
.testTag("tf_${registrationField.name.tagId()}")
.fillMaxWidth()
.noRippleClickable {
onClick(registrationField.name, registrationField.options)
},
placeholder = {
Text(
modifier = Modifier.testTag("txt_${registrationField.name}_placeholder"),
modifier = Modifier.testTag("txt_${registrationField.name.tagId()}_placeholder"),
text = registrationField.label,
color = MaterialTheme.appColors.textFieldHint,
style = MaterialTheme.appTypography.bodyMedium
Expand All @@ -437,7 +438,7 @@ fun SelectableRegisterField(
)
Spacer(modifier = Modifier.height(6.dp))
Text(
modifier = Modifier.testTag("txt_${registrationField.name}_description"),
modifier = Modifier.testTag("txt_${registrationField.name.tagId()}_description"),
text = helperText,
style = MaterialTheme.appTypography.bodySmall,
color = helperTextColor
Expand Down
37 changes: 30 additions & 7 deletions core/src/main/java/org/openedx/core/domain/model/VideoSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,34 @@ data class VideoSettings(
}
}

enum class VideoQuality(val titleResId: Int, val width: Int, val height: Int) {
AUTO(R.string.auto_recommended_text, 0, 0),
OPTION_360P(R.string.video_quality_p360, 640, 360),
OPTION_540P(R.string.video_quality_p540, 960, 540),
OPTION_720P(R.string.video_quality_p720, 1280, 720);

val value: String = this.name.replace("OPTION_", "").lowercase()
enum class VideoQuality(
val titleResId: Int,
val desResId: Int = 0,
val width: Int,
val height: Int
) {
AUTO(
titleResId = R.string.core_video_quality_auto,
desResId = R.string.core_video_quality_auto_description,
width = 0,
height = 0
),
OPTION_360P(
titleResId = R.string.core_video_quality_p360,
desResId = R.string.core_video_quality_p360_description,
width = 640,
height = 360
),
OPTION_540P(
titleResId = R.string.core_video_quality_p540,
desResId = 0,
width = 960,
height = 540
),
OPTION_720P(
titleResId = R.string.core_video_quality_p720,
desResId = R.string.core_video_quality_p720_description,
width = 1280,
height = 720
);
}
5 changes: 5 additions & 0 deletions 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 @@ -28,3 +29,7 @@ fun String.replaceLinkTags(isDarkTheme: Boolean): String {
}
return text
}

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

fun String.tagId(): String = this.replaceSpace("_").lowercase(Locale.getDefault())
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
Expand All @@ -55,6 +59,7 @@ fun AppUpgradeRequiredScreen(
)
}

@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun AppUpgradeRequiredScreen(
modifier: Modifier = Modifier,
Expand All @@ -66,11 +71,13 @@ fun AppUpgradeRequiredScreen(
modifier = modifier
.fillMaxSize()
.background(color = MaterialTheme.appColors.background)
.statusBarsInset(),
.statusBarsInset()
.semantics { testTagsAsResourceId = true },
contentAlignment = Alignment.TopCenter
) {
Text(
modifier = Modifier
.testTag("txt_app_upgrade_deprecated")
.fillMaxWidth()
.padding(top = 10.dp, bottom = 12.dp),
text = stringResource(id = R.string.core_deprecated_app_version),
Expand All @@ -92,6 +99,7 @@ fun AppUpgradeRequiredScreen(
}
}

@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun AppUpgradeRecommendDialog(
modifier: Modifier = Modifier,
Expand All @@ -106,11 +114,12 @@ fun AppUpgradeRecommendDialog(
}

Surface(
modifier = modifier,
modifier = modifier.semantics { testTagsAsResourceId = true },
color = Color.Transparent
) {
Box(
modifier = modifier
.testTag("btn_upgrade_dialog_not_now")
.fillMaxSize()
.padding(horizontal = 4.dp)
.noRippleClickable {
Expand Down Expand Up @@ -142,11 +151,13 @@ fun AppUpgradeRecommendDialog(
contentDescription = null
)
Text(
modifier = Modifier.testTag("txt_app_upgrade_title"),
text = stringResource(id = R.string.core_app_upgrade_title),
color = MaterialTheme.appColors.textPrimary,
style = MaterialTheme.appTypography.titleMedium
)
Text(
modifier = Modifier.testTag("txt_app_upgrade_description"),
text = stringResource(id = R.string.core_app_upgrade_dialog_description),
color = MaterialTheme.appColors.textPrimary,
textAlign = TextAlign.Center,
Expand All @@ -162,6 +173,7 @@ fun AppUpgradeRecommendDialog(
}
}

@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun AppUpgradeRequiredContent(
modifier: Modifier = Modifier,
Expand All @@ -170,7 +182,7 @@ fun AppUpgradeRequiredContent(
onUpdateClick: () -> Unit
) {
Column(
modifier = modifier,
modifier = modifier.semantics { testTagsAsResourceId = true },
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(32.dp)
) {
Expand All @@ -183,11 +195,13 @@ fun AppUpgradeRequiredContent(
verticalArrangement = Arrangement.spacedBy(12.dp)
) {
Text(
modifier = Modifier.testTag("txt_app_upgrade_required_title"),
text = stringResource(id = R.string.core_app_update_required_title),
color = MaterialTheme.appColors.textPrimary,
style = MaterialTheme.appTypography.titleMedium
)
Text(
modifier = Modifier.testTag("txt_app_upgrade_required_description"),
text = stringResource(id = R.string.core_app_update_required_description),
color = MaterialTheme.appColors.textPrimary,
textAlign = TextAlign.Center,
Expand Down Expand Up @@ -250,6 +264,7 @@ fun TransparentTextButton(
) {
Button(
modifier = Modifier
.testTag("btn_secondary")
.height(42.dp),
colors = ButtonDefaults.buttonColors(
backgroundColor = Color.Transparent
Expand All @@ -259,6 +274,7 @@ fun TransparentTextButton(
onClick = onClick
) {
Text(
modifier = Modifier.testTag("txt_secondary"),
color = MaterialTheme.appColors.textAccent,
style = MaterialTheme.appTypography.labelLarge,
text = text
Expand All @@ -273,6 +289,7 @@ fun DefaultTextButton(
) {
Button(
modifier = Modifier
.testTag("btn_primary")
.height(42.dp),
colors = ButtonDefaults.buttonColors(
backgroundColor = MaterialTheme.appColors.buttonBackground
Expand All @@ -286,6 +303,7 @@ fun DefaultTextButton(
horizontalArrangement = Arrangement.Center
) {
Text(
modifier = Modifier.testTag("txt_primary"),
text = text,
color = MaterialTheme.appColors.buttonText,
style = MaterialTheme.appTypography.labelLarge
Expand All @@ -301,6 +319,7 @@ fun AppUpgradeRecommendedBox(
) {
Card(
modifier = modifier
.testTag("btn_upgrade_box")
.fillMaxWidth()
.padding(20.dp)
.clickable {
Expand All @@ -322,11 +341,13 @@ fun AppUpgradeRecommendedBox(
)
Column {
Text(
modifier = Modifier.testTag("txt_app_upgrade_title"),
text = stringResource(id = R.string.core_app_upgrade_title),
color = Color.White,
style = MaterialTheme.appTypography.titleMedium
)
Text(
modifier = Modifier.testTag("txt_app_upgrade_description"),
text = stringResource(id = R.string.core_app_upgrade_box_description),
color = Color.White,
style = MaterialTheme.appTypography.bodyMedium
Expand Down
Loading

0 comments on commit dedb010

Please sign in to comment.