Skip to content

Commit

Permalink
feat: Try testTagsAsResourceId to improve UI tests: RC [WPB-9284] (#3594
Browse files Browse the repository at this point in the history
)
  • Loading branch information
borichellow authored Nov 6, 2024
1 parent 0c4facf commit 5225e02
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 28 deletions.
76 changes: 48 additions & 28 deletions app/src/main/kotlin/com/wire/android/ui/WireActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.view.WindowCompat
import androidx.lifecycle.Lifecycle
Expand Down Expand Up @@ -71,6 +74,7 @@ import com.wire.android.ui.common.bottomsheet.rememberWireModalSheetState
import com.wire.android.ui.common.bottomsheet.show
import com.wire.android.ui.common.snackbar.LocalSnackbarHostState
import com.wire.android.ui.common.topappbar.CommonTopAppBar
import com.wire.android.ui.common.topappbar.CommonTopAppBarState
import com.wire.android.ui.common.topappbar.CommonTopAppBarViewModel
import com.wire.android.ui.common.visbility.rememberVisibilityState
import com.wire.android.ui.destinations.ConversationScreenDestination
Expand Down Expand Up @@ -120,6 +124,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import javax.inject.Inject

@OptIn(ExperimentalComposeUiApi::class)
@AndroidEntryPoint
@Suppress("TooManyFunctions")
class WireActivity : AppCompatActivity() {
Expand Down Expand Up @@ -220,36 +225,15 @@ class WireActivity : AppCompatActivity() {
LocalActivity provides this
) {
WireTheme {
Column(modifier = Modifier.statusBarsPadding()) {
Column(
modifier = Modifier
.statusBarsPadding()
.semantics { testTagsAsResourceId = true }
) {
val navigator = rememberNavigator(this@WireActivity::finish)
CommonTopAppBar(
WireTopAppBar(
themeOption = viewModel.globalAppState.themeOption,
commonTopAppBarState = commonTopAppBarViewModel.state,
onReturnToCallClick = { establishedCall ->
getOngoingCallIntent(
this@WireActivity,
establishedCall.conversationId.toString()
).run {
startActivity(this)
}
},
onReturnToIncomingCallClick = {
getIncomingCallIntent(
this@WireActivity,
it.conversationId.toString(),
null
).run {
startActivity(this)
}
},
onReturnToOutgoingCallClick = {
getOutgoingCallIntent(
this@WireActivity,
it.conversationId.toString()
).run {
startActivity(this)
}
}
commonTopAppBarState = commonTopAppBarViewModel.state
)
CompositionLocalProvider(LocalNavigator provides navigator) {
MainNavHost(
Expand All @@ -269,6 +253,42 @@ class WireActivity : AppCompatActivity() {
}
}

@Composable
private fun WireTopAppBar(
themeOption: ThemeOption,
commonTopAppBarState: CommonTopAppBarState
) {
CommonTopAppBar(
themeOption = themeOption,
commonTopAppBarState = commonTopAppBarState,
onReturnToCallClick = { establishedCall ->
getOngoingCallIntent(
this@WireActivity,
establishedCall.conversationId.toString()
).run {
startActivity(this)
}
},
onReturnToIncomingCallClick = {
getIncomingCallIntent(
this@WireActivity,
it.conversationId.toString(),
null
).run {
startActivity(this)
}
},
onReturnToOutgoingCallClick = {
getOutgoingCallIntent(
this@WireActivity,
it.conversationId.toString()
).run {
startActivity(this)
}
}
)
}

@Composable
private fun HandleThemeChanges(themeOption: ThemeOption) {
LaunchedEffect(themeOption) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
import androidx.core.view.WindowCompat
import com.wire.android.appLogger
import com.wire.android.navigation.style.TransitionAnimationType
Expand All @@ -52,6 +56,7 @@ import javax.inject.Inject
* @see IncomingCallScreen
* @see OutgoingCallScreen
*/
@OptIn(ExperimentalComposeUiApi::class)
@AndroidEntryPoint
class StartingCallActivity : CallActivity() {
@Inject
Expand Down Expand Up @@ -90,6 +95,7 @@ class StartingCallActivity : CallActivity() {
TransitionAnimationType.POP_UP.exitTransition
)
},
modifier = Modifier.semantics { testTagsAsResourceId = true },
label = currentScreenType.name
) { screenType ->
conversationId?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ import androidx.compose.animation.togetherWith
import androidx.compose.material3.SnackbarHostState
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.remember
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
import androidx.core.view.WindowCompat
import com.wire.android.R
import com.wire.android.appLogger
Expand All @@ -56,6 +60,7 @@ import javax.inject.Inject
*
* @see OngoingCallScreen
*/
@OptIn(ExperimentalComposeUiApi::class)
@AndroidEntryPoint
class OngoingCallActivity : CallActivity() {
@Inject
Expand Down Expand Up @@ -91,6 +96,7 @@ class OngoingCallActivity : CallActivity() {
TransitionAnimationType.POP_UP.exitTransition
)
},
modifier = Modifier.semantics { testTagsAsResourceId = true },
label = TAG
) { _ ->
OngoingCallScreen(
Expand Down

0 comments on commit 5225e02

Please sign in to comment.