Add test for preferredWrapContent and BasicText
This is playing poorly with ellipsis
Bug: b/275369323
Test: is a test
Change-Id: I4dc0a71b9d6f3f181133ddfd2bccc2b4f76d4486
diff --git a/compose/foundation/foundation/build.gradle b/compose/foundation/foundation/build.gradle
index 6950856..6b0f5ef 100644
--- a/compose/foundation/foundation/build.gradle
+++ b/compose/foundation/foundation/build.gradle
@@ -23,6 +23,7 @@
id("AndroidXPlugin")
id("com.android.library")
id("AndroidXComposePlugin")
+ id("AndroidXPaparazziPlugin")
}
AndroidXComposePlugin.applyAndConfigureKotlinPlugin(project)
@@ -58,6 +59,8 @@
testImplementation(libs.kotlinReflect)
testImplementation(libs.mockitoKotlin4)
+ testImplementation(project(":constraintlayout:constraintlayout-compose"))
+
androidTestImplementation(project(":compose:test-utils"))
androidTestImplementation(project(":internal-testutils-fonts"))
androidTestImplementation(project(":test:screenshot:screenshot"))
diff --git a/compose/foundation/foundation/src/test/kotlin/androidx/compose/foundation/text/BasicTextPaparazziTest.kt b/compose/foundation/foundation/src/test/kotlin/androidx/compose/foundation/text/BasicTextPaparazziTest.kt
new file mode 100644
index 0000000..9988f80
--- /dev/null
+++ b/compose/foundation/foundation/src/test/kotlin/androidx/compose/foundation/text/BasicTextPaparazziTest.kt
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package androidx.compose.foundation.text
+
+import androidx.compose.foundation.background
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.size
+import androidx.compose.foundation.layout.width
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.text.style.TextOverflow
+import androidx.compose.ui.unit.dp
+import androidx.constraintlayout.compose.ConstraintLayout
+import androidx.constraintlayout.compose.Dimension
+import androidx.testutils.paparazzi.androidxPaparazzi
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+
+@RunWith(JUnit4::class)
+class BasicTextPaparazziTest {
+ @get:Rule
+ val paparazzi = androidxPaparazzi()
+
+ @Test
+ fun overflowEllipsis_doesEllipsis_whenInPreferredWrapContent() {
+ paparazzi.snapshot {
+ // b/275369323
+ ConstraintLayout(modifier = Modifier
+ .width(100.dp)
+ .background(Color.White)
+ .padding(8.dp)) {
+ val (thumbnail, textBox, actionButton) = createRefs()
+ Box(modifier = Modifier
+ .background(Color.Green)
+ .constrainAs(thumbnail) {
+ top.linkTo(parent.top)
+ start.linkTo(parent.start)
+ bottom.linkTo(parent.bottom)
+ }
+ .size(28.dp)
+ )
+ // Text region
+ Column(
+ modifier = Modifier
+ .constrainAs(textBox) {
+ top.linkTo(parent.top)
+ bottom.linkTo(parent.bottom)
+ start.linkTo(thumbnail.end)
+ end.linkTo(actionButton.start)
+ width = Dimension.preferredWrapContent
+ },
+ ) {
+ BasicText(
+ text = "ASome very long text that is sure to clip in this layout",
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis
+ )
+ }
+ Box(modifier = Modifier
+ .constrainAs(actionButton) {
+ top.linkTo(parent.top)
+ bottom.linkTo(parent.bottom)
+ end.linkTo(parent.end)
+ }
+ .background(Color.Blue.copy(alpha = 0.5f))
+ .size(28.dp)
+ )
+ }
+ }
+ }
+}