-
-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathComposeDeeplinkTests.kt
88 lines (71 loc) · 2.7 KB
/
ComposeDeeplinkTests.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
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package com.inspiredandroid.linuxcommandbibliotheca
import android.content.Context
import android.content.Intent
import android.net.Uri
import androidx.compose.ui.test.assertTextEquals
import androidx.compose.ui.test.junit4.createEmptyComposeRule
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.performClick
import androidx.preference.PreferenceManager
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.linuxcommandlibrary.shared.initDatabase
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
/**
* Test if deeplinks from/to website open correct screens. If test started the first time
* "Always open urls with app" dialog has to be accepted. Or the app has to be signed with the
* release key for autoVerify to take effect.
*/
@RunWith(AndroidJUnit4::class)
class ComposeDeeplinkTests {
private lateinit var scenario: ActivityScenario<MainActivity>
@get:Rule
val composeTestRule = createEmptyComposeRule()
@Before
fun setUp() {
val context: Context = ApplicationProvider.getApplicationContext()
initDatabase(context)
// Clear bookmarks
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
prefs.edit().putString("KEY_BOOKMARKS", "").apply()
}
private fun openUrl(url: String) {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
scenario = ActivityScenario.launch(intent)
}
@Test
fun testBasicCategories() {
openUrl("https://linuxcommandlibrary.com/basics")
composeTestRule.onNodeWithContentDescription("TopAppBarTitle")
.assertTextEquals("Basics")
}
@Test
fun testBasicCategory() {
openUrl("https://linuxcommandlibrary.com/basic/usersgroups")
composeTestRule.onNodeWithContentDescription("TopAppBarTitle")
.assertTextEquals("Users & Groups")
}
@Test
fun testTips() {
openUrl("https://linuxcommandlibrary.com/tips")
composeTestRule.onNodeWithContentDescription("TopAppBarTitle")
.assertTextEquals("Tips")
}
@Test
fun testCommandList() {
openUrl("https://linuxcommandlibrary.com/")
composeTestRule.onNodeWithContentDescription("Back").performClick()
composeTestRule.onNodeWithContentDescription("TopAppBarTitle")
.assertTextEquals("Commands")
}
@Test
fun testCommandDetail() {
openUrl("https://linuxcommandlibrary.com/man/2048")
composeTestRule.onNodeWithContentDescription("TopAppBarTitle")
.assertTextEquals("2048")
}
}