Move ComposeContentTestRuleExt to SpaLibTestUtils

To use it in SpaTests in the future.

Bug: 259520506
Test: Unit test
Change-Id: Ic5ad78be4e04451cf317a70dfd615293565b488d
diff --git a/packages/SettingsLib/Spa/testutils/Android.bp b/packages/SettingsLib/Spa/testutils/Android.bp
index 68ad414..0f618fa 100644
--- a/packages/SettingsLib/Spa/testutils/Android.bp
+++ b/packages/SettingsLib/Spa/testutils/Android.bp
@@ -24,7 +24,10 @@
     srcs: ["src/**/*.kt"],
 
     static_libs: [
-        "mockito-target-minus-junit4",
+        "androidx.compose.ui_ui-test-junit4",
+        "androidx.compose.ui_ui-test-manifest",
+        "mockito",
+        "truth-prebuilt",
     ],
     kotlincflags: [
         "-Xjvm-default=all",
diff --git a/packages/SettingsLib/Spa/testutils/build.gradle b/packages/SettingsLib/Spa/testutils/build.gradle
index 3e50b29..58b4d42 100644
--- a/packages/SettingsLib/Spa/testutils/build.gradle
+++ b/packages/SettingsLib/Spa/testutils/build.gradle
@@ -47,5 +47,8 @@
 }
 
 dependencies {
-    api "org.mockito:mockito-android:3.4.6"
+    api "androidx.compose.ui:ui-test-junit4:$jetpack_compose_version"
+    api "com.google.truth:truth:1.1.3"
+    api "org.mockito:mockito-core:2.21.0"
+    debugApi "androidx.compose.ui:ui-test-manifest:$jetpack_compose_version"
 }
diff --git a/packages/SettingsLib/Spa/testutils/src/com/android/settingslib/spa/testutils/ComposeContentTestRuleExt.kt b/packages/SettingsLib/Spa/testutils/src/com/android/settingslib/spa/testutils/ComposeContentTestRuleExt.kt
new file mode 100644
index 0000000..a5d1f40
--- /dev/null
+++ b/packages/SettingsLib/Spa/testutils/src/com/android/settingslib/spa/testutils/ComposeContentTestRuleExt.kt
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 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 com.android.settingslib.spa.testutils
+
+import androidx.compose.ui.test.ComposeTimeoutException
+import androidx.compose.ui.test.SemanticsMatcher
+import androidx.compose.ui.test.SemanticsNodeInteraction
+import androidx.compose.ui.test.hasAnyAncestor
+import androidx.compose.ui.test.hasText
+import androidx.compose.ui.test.isDialog
+import androidx.compose.ui.test.junit4.ComposeContentTestRule
+
+/** Blocks until the found a semantics node that match the given condition. */
+fun ComposeContentTestRule.waitUntilExists(matcher: SemanticsMatcher) = waitUntil {
+    onAllNodes(matcher).fetchSemanticsNodes().isNotEmpty()
+}
+
+/** Blocks until the timeout is reached. */
+fun ComposeContentTestRule.delay(timeoutMillis: Long = 1_000) = try {
+    waitUntil(timeoutMillis) { false }
+} catch (_: ComposeTimeoutException) {
+    // Expected
+}
+
+/** Finds a text node that within dialog. */
+fun ComposeContentTestRule.onDialogText(text: String): SemanticsNodeInteraction =
+    onNode(hasAnyAncestor(isDialog()) and hasText(text))