1*21373fa4SWill Schurman package host.exp.exponent.utils
2*21373fa4SWill Schurman 
3*21373fa4SWill Schurman import androidx.test.uiautomator.UiDevice
4*21373fa4SWill Schurman import com.azimolabs.conditionwatcher.ConditionWatcher
5*21373fa4SWill Schurman import androidx.test.uiautomator.UiSelector
6*21373fa4SWill Schurman import androidx.test.espresso.Espresso
7*21373fa4SWill Schurman import androidx.test.espresso.matcher.ViewMatchers
8*21373fa4SWill Schurman import androidx.test.espresso.assertion.ViewAssertions
9*21373fa4SWill Schurman import androidx.test.uiautomator.Configurator
10*21373fa4SWill Schurman import com.azimolabs.conditionwatcher.Instruction
11*21373fa4SWill Schurman import java.lang.Exception
12*21373fa4SWill Schurman 
13*21373fa4SWill Schurman object ExpoConditionWatcher {
14*21373fa4SWill Schurman   @Throws(Exception::class)
waitForTextnull15*21373fa4SWill Schurman   fun waitForText(device: UiDevice, text: String) {
16*21373fa4SWill Schurman     ConditionWatcher.waitForCondition(object : Instruction() {
17*21373fa4SWill Schurman       override fun getDescription(): String {
18*21373fa4SWill Schurman         return "$text text should exist"
19*21373fa4SWill Schurman       }
20*21373fa4SWill Schurman 
21*21373fa4SWill Schurman       override fun checkCondition(): Boolean {
22*21373fa4SWill Schurman         Configurator.getInstance().waitForSelectorTimeout = 1000
23*21373fa4SWill Schurman         val selector = UiSelector().text(text)
24*21373fa4SWill Schurman         return device.findObject(selector).exists()
25*21373fa4SWill Schurman       }
26*21373fa4SWill Schurman     })
27*21373fa4SWill Schurman     Espresso.onView(ViewMatchers.withText(text))
28*21373fa4SWill Schurman       .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
29*21373fa4SWill Schurman   }
30*21373fa4SWill Schurman }
31