-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextViewMatchers.kt
35 lines (32 loc) · 1.33 KB
/
TextViewMatchers.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.tazkiyatech.utils.espresso
import android.content.Context
import android.view.View
import android.widget.TextView
import androidx.annotation.StringRes
import androidx.core.text.HtmlCompat
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.matcher.BoundedMatcher
import androidx.test.espresso.matcher.ViewMatchers
import org.hamcrest.Description
import org.hamcrest.Matcher
object TextViewMatchers {
/**
* Creates a matcher that matches a descendant of [android.widget.TextView]
* which fully or partially contains the string associated with the given resource id.
*
* Usage example:
* ```
* onView(withId(R.id.someTextView)).check(matches(withSubstring(R.string.someString)))
* ```
*
* @param resourceId The identifier of the [String] resource
* which the [android.widget.TextView] is expected to contain.
* @return A matcher that matches a descendant of [android.widget.TextView]
* which fully or partially contains the string associated with the given resource id.
*/
fun withSubstring(@StringRes resourceId: Int): Matcher<View> {
val applicationContext = ApplicationProvider.getApplicationContext<Context>()
val substring = applicationContext.getString(resourceId)
return ViewMatchers.withSubstring(substring)
}
}