[go: nahoru, domu]

Fix false positive of assertIsDisplayed

The value of isPlaced was only checked in the parents of the matching
node, but not in the matching node itself.

Fixes: 156232285
Test: ./gradlew ui:ui-test:cC \
        -Pandroid.testInstrumentationRunnerArguments.class=\
        androidx.ui.test.IsDisplayedTest

Change-Id: Ic9ed9a4822b7b3389ac8e0f3e50bbeb4ee900559
diff --git a/ui/ui-test/src/androidTest/java/androidx/ui/test/IsDisplayedTest.kt b/ui/ui-test/src/androidTest/java/androidx/ui/test/IsDisplayedTest.kt
index f285b86..728707c 100644
--- a/ui/ui-test/src/androidTest/java/androidx/ui/test/IsDisplayedTest.kt
+++ b/ui/ui-test/src/androidTest/java/androidx/ui/test/IsDisplayedTest.kt
@@ -63,6 +63,20 @@
         }
     }
 
+    @Composable
+    fun PlaceConditionally(place: Boolean, child: @Composable () -> Unit) {
+        Layout(children = child) { measurables, constraints, _ ->
+            if (place) {
+                val placeable = measurables[0].measure(constraints)
+                layout(placeable.width, placeable.height) {
+                    placeable.place(0.ipx, 0.ipx)
+                }
+            } else {
+                layout(0.ipx, 0.ipx) {}
+            }
+        }
+    }
+
     @Test
     fun componentInScrollable_isDisplayed() {
         composeTestRule.setContent {
@@ -92,25 +106,37 @@
     }
 
     @Test
-    fun toggleParentVisibility() {
+    fun togglePlacement() {
         var place by mutableStateOf(true)
 
-        // Place `Stack { Item(0) }` or not, based on the value of [place]
         composeTestRule.setContent {
-            Layout({
+            PlaceConditionally(place) {
+                // Item instead of BoundaryNode because we need non-zero size
+                Item(0)
+            }
+        }
+
+        findByTag("item0")
+            .assertIsDisplayed()
+
+        runOnIdleCompose {
+            place = false
+        }
+
+        findByTag("item0")
+            .assertIsNotDisplayed()
+    }
+
+    @Test
+    fun toggleParentPlacement() {
+        var place by mutableStateOf(true)
+
+        composeTestRule.setContent {
+            PlaceConditionally(place) {
                 Stack {
                     // Item instead of BoundaryNode because we need non-zero size
                     Item(0)
                 }
-            }) { measurables, constraints, _ ->
-                if (place) {
-                    val placeable = measurables[0].measure(constraints)
-                    layout(placeable.width, placeable.height) {
-                        placeable.place(0.ipx, 0.ipx)
-                    }
-                } else {
-                    layout(0.ipx, 0.ipx) {}
-                }
             }
         }