Skip to content

Commit 6bd966b

Browse files
committed
Add 38 UI tests for LongPressMenu
1 parent 16a09b2 commit 6bd966b

4 files changed

Lines changed: 703 additions & 3 deletions

File tree

app/src/androidTest/java/org/schabi/newpipe/InstrumentedTestUtil.kt

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import android.content.Context
44
import androidx.annotation.StringRes
55
import androidx.compose.ui.test.SemanticsNodeInteraction
66
import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
7+
import androidx.compose.ui.test.onNodeWithContentDescription
78
import androidx.compose.ui.test.onNodeWithText
89
import androidx.preference.PreferenceManager
9-
import androidx.test.core.app.ApplicationProvider
10+
import androidx.test.platform.app.InstrumentationRegistry
11+
import org.junit.Assert.fail
1012

1113
val ctx: Context
12-
get() = ApplicationProvider.getApplicationContext<Context>()
14+
get() = InstrumentationRegistry.getInstrumentation().targetContext
1315

1416
fun putBooleanInPrefs(@StringRes key: Int, value: Boolean) {
1517
PreferenceManager.getDefaultSharedPreferences(ctx)
@@ -37,3 +39,33 @@ fun SemanticsNodeInteractionsProvider.onNodeWithText(
3739
): SemanticsNodeInteraction {
3840
return this.onNodeWithText(ctx.getString(text), substring, ignoreCase, useUnmergedTree)
3941
}
42+
43+
/**
44+
* Same as the original `onNodeWithContentDescription` except that this takes a [StringRes] instead of a [String].
45+
*/
46+
fun SemanticsNodeInteractionsProvider.onNodeWithContentDescription(
47+
@StringRes text: Int,
48+
substring: Boolean = false,
49+
ignoreCase: Boolean = false,
50+
useUnmergedTree: Boolean = false
51+
): SemanticsNodeInteraction {
52+
return this.onNodeWithContentDescription(ctx.getString(text), substring, ignoreCase, useUnmergedTree)
53+
}
54+
55+
fun <T : Comparable<T>> assertInRange(l: T, r: T, value: T) {
56+
if (l > r) {
57+
fail("Invalid range passed to `assertInRange`: [$l, $r]")
58+
}
59+
if (value !in l..r) {
60+
fail("Expected $value to be in range [$l, $r]")
61+
}
62+
}
63+
64+
fun <T : Comparable<T>> assertNotInRange(l: T, r: T, value: T) {
65+
if (l > r) {
66+
fail("Invalid range passed to `assertInRange`: [$l, $r]")
67+
}
68+
if (value in l..r) {
69+
fail("Expected $value to NOT be in range [$l, $r]")
70+
}
71+
}

0 commit comments

Comments
 (0)