Skip to content

Commit

Permalink
Merge "Fix Wear Compose tests for cuttlefish_wear" into androidx-main
Browse files Browse the repository at this point in the history
  • Loading branch information
Ankit authored and Gerrit Code Review committed Mar 16, 2024
2 parents e0de80c + b9ba8a1 commit 824114c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import androidx.activity.OnBackPressedDispatcher
import androidx.activity.OnBackPressedDispatcherOwner
import androidx.activity.compose.LocalOnBackPressedDispatcherOwner
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
Expand Down Expand Up @@ -94,7 +95,7 @@ class SwipeDismissableNavHostTest {

// Click to move to next destination then swipe to dismiss.
rule.onNodeWithText(START).performClick()
rule.onNodeWithTag(TEST_TAG).performTouchInput({ swipeRight() })
rule.onNodeWithTag(TEST_TAG).performTouchInput { swipeRight() }

// Should now display "start".
rule.onNodeWithText(START).assertExists()
Expand Down Expand Up @@ -195,23 +196,28 @@ class SwipeDismissableNavHostTest {
composable(START) {
screenId.value = START
var toggle by rememberSaveable { mutableStateOf(false) }
Column {
ToggleButton(
checked = toggle,
onCheckedChange = {
toggle = !toggle
},
content = { Text(text = if (toggle) "On" else "Off") },
modifier = Modifier.testTag("ToggleButton"),
)
Button(
onClick = { navController.navigate(NEXT) },
) {
Text("Go")
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
) {
Column {
ToggleButton(
checked = toggle,
onCheckedChange = {
toggle = !toggle
},
content = { Text(text = if (toggle) "On" else "Off") },
modifier = Modifier.testTag("ToggleButton"),
)
Button(
onClick = { navController.navigate(NEXT) },
) {
Text("Go")
}
}
}
}
composable("next") {
composable(NEXT) {
screenId.value = NEXT
CompactChip(
onClick = {},
Expand Down Expand Up @@ -246,7 +252,9 @@ class SwipeDismissableNavHostTest {
holder.SaveableStateProvider(START) {
var toggle by rememberSaveable { mutableStateOf(false) }
Column(
modifier = Modifier.fillMaxSize().padding(horizontal = 20.dp),
modifier = Modifier
.fillMaxSize()
.padding(horizontal = 20.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Expand All @@ -271,7 +279,9 @@ class SwipeDismissableNavHostTest {
holder.SaveableStateProvider(NEXT) {
var counter by rememberSaveable { mutableStateOf(0) }
Column(
modifier = Modifier.fillMaxSize().padding(horizontal = 20.dp),
modifier = Modifier
.fillMaxSize()
.padding(horizontal = 20.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Expand Down Expand Up @@ -448,13 +458,23 @@ class SwipeDismissableNavHostTest {
userSwipeEnabled = userSwipeEnabled
) {
composable(START) {
CompactChip(
onClick = { navController.navigate(NEXT) },
label = { Text(text = START) }
)
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
) {
CompactChip(
onClick = { navController.navigate(NEXT) },
label = { Text(text = START) }
)
}
}
composable("next") {
Text(NEXT)
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
) {
Text(NEXT)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ class SwipeBenchmark(
// Setting a gesture margin is important otherwise gesture nav is triggered.
swipeToDismissBox.setGestureMargin(device.displayWidth / 5)
repeat(3) {
swipeToDismissBox.swipe(Direction.RIGHT, 0.75f, SWIPE_SPEED)
swipeToDismissBox.swipe(Direction.RIGHT, 1f, SWIPE_SPEED)
// Sleeping the current thread for sometime before swiping again. This is required
// for cuttlefish_wear emulator as swipes are not completed when performed
// repeatedly. See b/328016250 for more details.
// TODO(b/329837878): Remove the sleep once infra improves
Thread.sleep(500)
device.waitForIdle()
}
}
Expand Down

0 comments on commit 824114c

Please sign in to comment.