Repository navigation
Expand file tree
/
Copy pathCode__android__app__src__androidTest__java__com__safarsaathi__rides__M01LaunchTest.kt
More file actions
64 lines (58 loc) · 2.69 KB
/
Copy pathCode__android__app__src__androidTest__java__com__safarsaathi__rides__M01LaunchTest.kt
File metadata and controls
64 lines (58 loc) · 2.69 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
package com.safarsaathi.rides
import android.content.Intent
import android.net.Uri
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onAllNodesWithText
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.performTextInput
import androidx.compose.ui.test.performTextReplacement
import androidx.compose.ui.semantics.SemanticsProperties
import androidx.compose.ui.test.performClick
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.safarsaathi.rides.m01.LanguageStore
import com.safarsaathi.rides.m01.M01ViewModel
import androidx.lifecycle.ViewModelProvider
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.Assert.assertEquals
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class M01LaunchTest {
@get:Rule val rule = createAndroidComposeRule<MainActivity>()
@Before fun useEnglish() {
rule.runOnUiThread {
ViewModelProvider(rule.activity)[M01ViewModel::class.java].signOut()
LanguageStore.save(rule.activity, "en")
rule.activity.recreate()
}
rule.waitUntil(10_000) {
rule.onAllNodesWithText("Welcome to\nSafarSaathi").fetchSemanticsNodes().isNotEmpty()
}
}
@Test fun signedOutLaunchOpensPhoneEntry() {
rule.onNodeWithText("Welcome to\nSafarSaathi").assertExists()
rule.onNodeWithText("Continue").performClick()
rule.onNodeWithText("Sign in with\nyour phone").assertExists()
rule.onNodeWithContentDescription("10-digit Indian mobile number").assertExists()
}
@Test fun phoneEntryLimitsDigitsAndValidatesLength() {
rule.onNodeWithText("Continue").performClick()
val phoneField = rule.onNodeWithContentDescription("10-digit Indian mobile number")
rule.onNodeWithText("+91", useUnmergedTree = true).assertExists()
phoneField.performTextInput("987654321012")
assertEquals("9876543210", phoneField.fetchSemanticsNode().config[SemanticsProperties.EditableText].text)
phoneField.performTextReplacement("987654321")
rule.onNodeWithText("Send code").performClick()
rule.onNodeWithText("Enter a 10-digit Indian mobile number.").assertExists()
}
@Test fun protectedApplicationLinkRequiresSignIn() {
rule.runOnUiThread {
rule.activity.handleExternalIntent(Intent(Intent.ACTION_VIEW,
Uri.parse("safarsaathi://app/driver-application/some-owner")))
}
rule.onNodeWithText("Sign in with\nyour phone").assertExists()
rule.onNodeWithContentDescription("10-digit Indian mobile number").assertExists()
}
}