Skip to content

Commit 8d21c75

Browse files
author
Haoyu Zhang
committed
Update tap anywhere to cancel selection test
Focus system removed the feature that tapping anywhere will clear focus. And after this change, the SelectionContainer only cancels the selection when user click inside the SelectionContainer. This CL updates the test case so that it matches the current behavior. Bug: 179770443 Test: ./gradlew compose:foundation:foundation:connectedAndroidTest Change-Id: I8247fda1acb54c72685eee60e010ce47712c007f
1 parent 89d390f commit 8d21c75

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/text/selection/SelectionContainerFocusTest.kt

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import androidx.compose.ui.platform.LocalHapticFeedback
3636
import androidx.compose.ui.platform.LocalLayoutDirection
3737
import androidx.compose.ui.platform.LocalTextToolbar
3838
import androidx.compose.ui.platform.testTag
39+
import androidx.compose.ui.test.center
3940
import androidx.compose.ui.test.click
4041
import androidx.compose.ui.test.hasTestTag
4142
import androidx.compose.ui.test.junit4.createAndroidComposeRule
@@ -49,7 +50,6 @@ import androidx.compose.ui.unit.LayoutDirection
4950
import androidx.compose.ui.unit.dp
5051
import androidx.compose.ui.unit.sp
5152
import androidx.test.ext.junit.runners.AndroidJUnit4
52-
import androidx.test.filters.FlakyTest
5353
import androidx.test.filters.LargeTest
5454
import com.google.common.truth.Truth.assertThat
5555
import com.nhaarman.mockitokotlin2.mock
@@ -78,11 +78,9 @@ class SelectionContainerFocusTest {
7878

7979
private val hapticFeedback = mock<HapticFeedback>()
8080

81-
@FlakyTest(bugId = 179770443)
8281
@Test
83-
fun click_anywhere_to_cancel() {
82+
fun tap_to_cancel() {
8483
// Setup. Long press to create a selection.
85-
// A reasonable number.
8684
createSelectionContainer()
8785
// Touch position. In this test, each character's width and height equal to fontSize.
8886
// Position is computed so that (position, position) is the center of the first character.
@@ -95,14 +93,9 @@ class SelectionContainerFocusTest {
9593
assertThat(selection1.value).isNotNull()
9694
}
9795

98-
// Touch position. In this test, each character's width and height equal to fontSize.
99-
// Position is computed so that (position, position) is the center of the first character.
100-
val positionInBox = with(Density(view.context)) {
101-
boxSize.toPx() / 2
102-
}
10396
// Act.
10497
rule.onNode(hasTestTag("box"))
105-
.performGesture { click(Offset(x = positionInBox, y = positionInBox)) }
98+
.performGesture { click(center) }
10699

107100
// Assert.
108101
rule.runOnIdle {
@@ -118,7 +111,6 @@ class SelectionContainerFocusTest {
118111
@Test
119112
fun select_anotherContainer_cancelOld() {
120113
// Setup. Long press to create a selection.
121-
// A reasonable number.
122114
createSelectionContainer()
123115
// Touch position. In this test, each character's width and height equal to fontSize.
124116
// Position is computed so that (position, position) is the center of the first character.
@@ -168,16 +160,19 @@ class SelectionContainerFocusTest {
168160
selection1.value = it
169161
}
170162
) {
171-
CoreText(
172-
AnnotatedString(textContent),
173-
Modifier.fillMaxWidth(),
174-
style = TextStyle(fontFamily = fontFamily, fontSize = fontSize),
175-
softWrap = true,
176-
overflow = TextOverflow.Clip,
177-
maxLines = Int.MAX_VALUE,
178-
inlineContent = mapOf(),
179-
onTextLayout = {}
180-
)
163+
Column {
164+
CoreText(
165+
AnnotatedString(textContent),
166+
Modifier.fillMaxWidth(),
167+
style = TextStyle(fontFamily = fontFamily, fontSize = fontSize),
168+
softWrap = true,
169+
overflow = TextOverflow.Clip,
170+
maxLines = Int.MAX_VALUE,
171+
inlineContent = mapOf(),
172+
onTextLayout = {}
173+
)
174+
Box(Modifier.size(boxSize, boxSize).testTag("box"))
175+
}
181176
}
182177

183178
SelectionContainer(
@@ -200,8 +195,6 @@ class SelectionContainerFocusTest {
200195
onTextLayout = {}
201196
)
202197
}
203-
204-
Box(Modifier.size(boxSize, boxSize).testTag("box"))
205198
}
206199
}
207200
}

0 commit comments

Comments
 (0)