-
Notifications
You must be signed in to change notification settings - Fork 13
/
TodoComposeTest.kt
115 lines (94 loc) · 3.13 KB
/
TodoComposeTest.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package com.aseemwangoo.handsonkotlin.compose
import androidx.compose.ui.test.assertHasNoClickAction
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertTextEquals
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performTextInput
import androidx.test.espresso.Espresso
import com.aseemwangoo.handsonkotlin.ADD_TODO
import com.aseemwangoo.handsonkotlin.NavGraphs
import com.aseemwangoo.handsonkotlin.SAVE_TODO
import com.aseemwangoo.handsonkotlin.TEST_INPUT_TAG
import com.aseemwangoo.handsonkotlin.TITLE_MAIN
import com.aseemwangoo.handsonkotlin.addtodo.view.AddTodoView
import com.aseemwangoo.handsonkotlin.google.GoogleUserModel
import com.aseemwangoo.handsonkotlin.home.view.HomeView
import com.aseemwangoo.handsonkotlin.navigation.DestinationsNavigatorImpl
import com.ramcosta.composedestinations.DestinationsNavHost
import org.junit.Before
import org.junit.Rule
import org.junit.Test
class TodoComposeTest {
private var navController = DestinationsNavigatorImpl()
@get:Rule
val composeTestRule = createComposeRule()
@Before
fun setUp() {
}
@Test
fun testIfTitleExists() {
composeTestRule.setContent {
HomeView(
navController,
GoogleUserModel(
email = "email",
name = "name",
)
)
}
composeTestRule.onNodeWithText(TITLE_MAIN)
.assertIsDisplayed()
}
@Test
fun testIfTitleClicked() {
composeTestRule.setContent {
HomeView(
navController,
GoogleUserModel(
email = "email",
name = "name",
)
)
}
composeTestRule.onNodeWithText(TITLE_MAIN)
.assertHasNoClickAction()
}
@Test
fun testForAddTodoClick() {
composeTestRule.setContent {
DestinationsNavHost(navGraph = NavGraphs.root)
}
composeTestRule.onNodeWithText(ADD_TODO)
.performClick()
composeTestRule.onNodeWithText(
text = SAVE_TODO
).assertExists()
}
@Test
fun testForNotSavingTodo() {
composeTestRule.setContent {
DestinationsNavHost(navGraph = NavGraphs.root)
}
composeTestRule.onNodeWithText(ADD_TODO)
.performClick()
composeTestRule.onNodeWithText(
text = SAVE_TODO
).assertExists()
Espresso.pressBack()
composeTestRule.onNodeWithText(TITLE_MAIN)
.assertExists()
}
@Test
fun testForTodoInputField() {
composeTestRule.setContent {
DestinationsNavHost(navGraph = NavGraphs.root)
AddTodoView(navController)
}
val dummyText = "Dummy Text"
composeTestRule.onNodeWithTag(TEST_INPUT_TAG).performTextInput(dummyText)
composeTestRule.onNodeWithTag(TEST_INPUT_TAG).assertTextEquals(dummyText)
}
}