forked from next-step/android-github-compose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStatelessGithubScreenTest.kt
152 lines (127 loc) · 4.64 KB
/
StatelessGithubScreenTest.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.SnackbarResult
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertIsNotDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onAllNodesWithText
import androidx.compose.ui.test.onFirst
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithText
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.advanceUntilIdle
import kotlinx.coroutines.test.runTest
import nextstep.github.ui.screen.github.GithubScreen
import nextstep.github.ui.screen.github.RepositoryUiState
import nextstep.github.ui.uistate.UiState
import org.junit.Rule
import org.junit.Test
class StatelessGithubScreenTest {
@get:Rule
val composeTestRule = createComposeRule()
val uiState = UiState.Success(
data = listOf(
RepositoryUiState(
id = 1,
fullName = "next-step/nextstep-docs",
description = "nextstep 매뉴얼 및 문서를 관리하는 저장소",
),
RepositoryUiState(
id = 2,
fullName = "next-step/holy-moly",
description = "nextstep 홀리몰리한 저장소",
),
RepositoryUiState(
id = 3,
fullName = "next-step/haly-galy",
description = "nextstep 할리갈리한 저장소",
),
)
)
@Test
fun Github_레포지토리_데이터가_정상적으로_화면에_출력된다() {
composeTestRule.setContent {
GithubScreen(
repositoryUiState = uiState,
snackbarHostState = SnackbarHostState()
)
}
uiState.data.forEach {
composeTestRule.onNodeWithText(it.fullName)
.assertExists()
}
}
@Test
fun Github_레포지토리_데이터가_빈값일시_화면에_메시지가_출력된다() {
composeTestRule.setContent {
GithubScreen(
repositoryUiState = UiState.Empty,
snackbarHostState = SnackbarHostState()
)
}
composeTestRule.onAllNodesWithText("목록이 비었습니다.")
.onFirst()
.assertExists()
}
@Test
fun Github_레포지토리_데이터가_로딩일시_로딩바가_화면에_출력된다() {
composeTestRule.setContent {
GithubScreen(
repositoryUiState = UiState.Loading,
snackbarHostState = SnackbarHostState()
)
}
composeTestRule.onNodeWithContentDescription("LoadingProgressBar")
.assertIsDisplayed()
}
@OptIn(ExperimentalCoroutinesApi::class)
@Test
fun 오류_발생시_화면에_스낵바가_호출된다() = runTest {
val snackbarHostState = SnackbarHostState()
composeTestRule.setContent {
GithubScreen(
repositoryUiState = UiState.Empty,
snackbarHostState = snackbarHostState
)
}
launch {
snackbarHostState.showSnackbar(
message = "예상치 못한 오류가 발생했습니다.",
actionLabel = "재시도",
)
}
advanceUntilIdle()
composeTestRule.onNodeWithContentDescription("Snackbar")
.assertIsDisplayed()
composeTestRule.onNodeWithText("예상치 못한 오류가 발생했습니다.")
.assertIsDisplayed()
snackbarHostState.currentSnackbarData?.dismiss()
}
@OptIn(ExperimentalCoroutinesApi::class)
@Test
fun 스낵바_재시도_버튼을_클릭하면_스낵바가_사라진다() = runTest {
val snackbarHostState = SnackbarHostState()
composeTestRule.setContent {
GithubScreen(
repositoryUiState = UiState.Empty,
snackbarHostState = snackbarHostState
)
}
launch {
when (snackbarHostState.showSnackbar(
message = "예기치 못한 오류",
actionLabel = "재시도"
)) {
SnackbarResult.ActionPerformed -> {
snackbarHostState.currentSnackbarData?.dismiss()
}
else -> {}
}
}
advanceUntilIdle()
snackbarHostState.currentSnackbarData?.performAction()
advanceUntilIdle()
composeTestRule.onNodeWithContentDescription("Snackbar")
.assertIsNotDisplayed()
}
}