Creating a custom qaTag modifier

This commit is contained in:
ThomasSession 2024-08-21 14:43:54 +10:00
parent dc0b782f99
commit 79665ad475
2 changed files with 19 additions and 1 deletions

View File

@ -3,7 +3,12 @@ package org.thoughtcrime.securesms.ui
import android.app.Activity import android.app.Activity
import android.content.Context import android.content.Context
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import org.thoughtcrime.securesms.ui.theme.SessionMaterialTheme import org.thoughtcrime.securesms.ui.theme.SessionMaterialTheme
@ -23,3 +28,15 @@ fun ComposeView.setThemedContent(content: @Composable () -> Unit) = setContent {
content() content()
} }
} }
/**
* This is used to set the test tag that the QA team can use to retrieve an element in appium
* In order to do so we need to set the testTagsAsResourceId to true, which ideally should be done only once
* in the root composable, but our app is currently made up of multiple isolated composables
* set up in the old activity/fragment view system
* As such we need to repeat it for every component that wants to use testTag, until such
* a time as we have one root composable
*/
@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun Modifier.qaTag(tag: String) = semantics { testTagsAsResourceId = true }.testTag(tag)

View File

@ -35,6 +35,7 @@ import network.loki.messenger.libsession_util.util.ExpiryMode
import org.thoughtcrime.securesms.conversation.disappearingmessages.ExpiryType import org.thoughtcrime.securesms.conversation.disappearingmessages.ExpiryType
import org.thoughtcrime.securesms.ui.GetString import org.thoughtcrime.securesms.ui.GetString
import org.thoughtcrime.securesms.ui.RadioOption import org.thoughtcrime.securesms.ui.RadioOption
import org.thoughtcrime.securesms.ui.qaTag
import org.thoughtcrime.securesms.ui.theme.LocalColors import org.thoughtcrime.securesms.ui.theme.LocalColors
import org.thoughtcrime.securesms.ui.theme.LocalDimensions import org.thoughtcrime.securesms.ui.theme.LocalDimensions
import org.thoughtcrime.securesms.ui.theme.LocalType import org.thoughtcrime.securesms.ui.theme.LocalType
@ -122,7 +123,7 @@ fun <T> TitledRadioButton(
RadioButton( RadioButton(
modifier = modifier modifier = modifier
.heightIn(min = 60.dp) .heightIn(min = 60.dp)
.testTag(option.contentDescription.string()), .qaTag(option.contentDescription.string()),
onClick = onClick, onClick = onClick,
selected = option.selected, selected = option.selected,
enabled = option.enabled, enabled = option.enabled,