-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathMainActivityTest.kt
More file actions
66 lines (56 loc) · 2.46 KB
/
MainActivityTest.kt
File metadata and controls
66 lines (56 loc) · 2.46 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package ai.liquid.leapchat
import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertTextContains
import androidx.compose.ui.test.hasTestTag
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.isDisplayed
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onAllNodesWithTag
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performTextInput
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class MainActivityE2EAssetTests {
@get:Rule
val composeTestRule = createAndroidComposeRule<MainActivity>()
@OptIn(ExperimentalTestApi::class)
@Test
fun testEndToEndChat() {
val modelLoadingIndicatorMatcher = hasTestTag("ModelLoadingIndicator")
val inputBoxMatcher = hasTestTag("InputBox")
val sendButtonMatcher = hasText("Send")
// Wait for the model to be downloaded and loaded
composeTestRule.onNode(modelLoadingIndicatorMatcher).assertIsDisplayed()
composeTestRule.waitUntilDoesNotExist(
modelLoadingIndicatorMatcher,
timeoutMillis = MODEL_LOADING_TIMEOUT
)
composeTestRule.waitUntilAtLeastOneExists(sendButtonMatcher, timeoutMillis = 5000L)
// Send an input to the model
composeTestRule.onNode(inputBoxMatcher)
.performTextInput("How many 'r' are there in the word 'strawberry'?")
composeTestRule.onNode(sendButtonMatcher).performClick()
composeTestRule.waitUntilAtLeastOneExists(
hasTestTag("AssistantMessageView"),
timeoutMillis = 5000L
)
composeTestRule.waitUntil(timeoutMillis = 5000L) {
composeTestRule.onNode(hasTestTag("AssistantMessageViewText").and(hasText("strawberry", substring = true)))
.isDisplayed()
}
// Continue the chat with a second prompt
composeTestRule.onNode(inputBoxMatcher).performTextInput("What about letter 'a'?")
composeTestRule.onNode(sendButtonMatcher).performClick()
composeTestRule.waitUntil(timeoutMillis = 5000L) {
composeTestRule.onAllNodesWithTag("AssistantMessageView")
.fetchSemanticsNodes().size == 2
}
}
companion object {
const val MODEL_LOADING_TIMEOUT = 5L * 60L * 1000L
}
}