@@ -4,12 +4,14 @@ import android.content.Context
44import androidx.annotation.StringRes
55import androidx.compose.ui.test.SemanticsNodeInteraction
66import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
7+ import androidx.compose.ui.test.onNodeWithContentDescription
78import androidx.compose.ui.test.onNodeWithText
89import androidx.preference.PreferenceManager
9- import androidx.test.core.app.ApplicationProvider
10+ import androidx.test.platform.app.InstrumentationRegistry
11+ import org.junit.Assert.fail
1012
1113val ctx: Context
12- get() = ApplicationProvider .getApplicationContext< Context >()
14+ get() = InstrumentationRegistry .getInstrumentation().targetContext
1315
1416fun 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