Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

๐Ÿš€ 3๋‹จ๊ณ„ - GitHub(UI ์ƒํƒœ) #56

Merged
merged 22 commits into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c413ff0
refactor: ColorScheme ํŒŒ์ผ ์ถ”๊ฐ€ ๋ฐ topAppBarContainer ํ™•์žฅ ์†์„ฑ ์ถ”๊ฐ€
mogunjoa Mar 12, 2025
69441df
refactor: CenterAlignedTopAppBar containerColor White์—์„œ topAppBarContโ€ฆ
mogunjoa Mar 12, 2025
50fb69e
refactor: HorizontalDivider thickness 1.dp ์†์„ฑ ์ œ๊ฑฐ
mogunjoa Mar 12, 2025
42f3683
test(refactor): GithubScreenTest ํ™”๋ฉด ๊ฒ€์ฆ ๋กœ์ง ์ฝ”๋“œ ๊ฐ„๊ฒฐํ™”
mogunjoa Mar 12, 2025
c6cb41e
feat: UiState sealed class ์ถ”๊ฐ€
mogunjoa Mar 12, 2025
d477518
feat: RepositoryUiState ์ถ”๊ฐ€
mogunjoa Mar 12, 2025
776a425
feat: GithubViewModel์—์„œ repositoryUiState ์ถ”๊ฐ€ ๋ฐ ์ƒํƒœ ๊ด€๋ฆฌ ๊ฐœ์„ 
mogunjoa Mar 12, 2025
1eb875d
feat: CenteredContent ์ปดํฌ๋„ŒํŠธ ์ถ”๊ฐ€ ๋ฐ GithubScreen์—์„œ ์ƒํƒœ์— ๋”ฐ๋ฅธ UI ์ฒ˜๋ฆฌ ๊ฐœ์„ 
mogunjoa Mar 12, 2025
90b0c80
feat: GithubScreen์— ์Šค๋‚ต๋ฐ” ์˜ค๋ฅ˜ ์ฒ˜๋ฆฌ ๋ฐ ์žฌ์‹œ๋„ ๋กœ์ง ์ถ”๊ฐ€
mogunjoa Mar 12, 2025
911087d
feat: ํ•˜๋“œ์ฝ”ํŒ… text string resource๋กœ ๋Œ€์ฒด
mogunjoa Mar 12, 2025
6c1bfb2
feat: SnackbarHost, CircularProgressIndicator sementic ํƒœ๊ทธ ์ถ”๊ฐ€
mogunjoa Mar 12, 2025
c2444c3
refactor: ๋นˆ ํ™”๋ฉด ๋ฌธ๊ตฌ ์ˆ˜์ •
mogunjoa Mar 12, 2025
5ef8e7f
test: GithubScreen(Stateless) ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ž‘์„ฑ
mogunjoa Mar 12, 2025
8acb71d
feat: FakeGithubRepository ์ถ”๊ฐ€
mogunjoa Mar 12, 2025
17833de
test: GithubScreen(Stateful) ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ž‘์„ฑ
mogunjoa Mar 12, 2025
6091521
docs: 2๋‹จ๊ณ„ ๊ฐœ์„  ์‚ฌํ•ญ ์ •์˜
mogunjoa Mar 12, 2025
a36629c
docs: 3๋‹จ๊ณ„ ๊ธฐ๋Šฅ ์š”๊ตฌ ์‚ฌํ•ญ ์ •์˜
mogunjoa Mar 12, 2025
b9ccfa4
test(fix): repository.clearData() ์ œ๊ฑฐ
mogunjoa Mar 12, 2025
f3402a9
refactor: FakeGithubRepository clearData ํ•จ์ˆ˜ ์ œ๊ฑฐ
mogunjoa Mar 12, 2025
f609da7
test: StatelessGithubScreenTest ์Šค๋‚ต๋ฐ” ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ถ”๊ฐ€
mogunjoa Mar 14, 2025
563958b
refactor: LaunchedEffect viewModel key ์ง€์ •
mogunjoa Mar 14, 2025
5a1565e
refactor: _errorFlow emit > tryEmit ์œผ๋กœ ์ˆ˜์ •
mogunjoa Mar 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,19 @@
- ํžŒํŠธ ์ฝ”๋“œ๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ ViewModel Factory๋ฅผ ๊ตฌํ˜„ํ•œ๋‹ค. (Hilt์™€ ๊ฐ™์€ ๋ณ„๋„์˜ DI ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ํ™œ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค)
- ์ €์žฅ์†Œ ๋ชฉ๋ก์„ ๋…ธ์ถœํ•˜๋Š” UI์™€ ๊ด€๋ จ๋œ ๊ธฐ๋Šฅ์€ ui ํŒจํ‚ค์ง€์— ๊ตฌํ˜„๋˜์–ด์•ผ ํ•œ๋‹ค.
- UI ๋ ˆ์ด์–ด๋Š” ๋ฐ์ดํ„ฐ ๋ ˆ์ด์–ด๋ฅผ ์˜์กดํ•˜์ง€๋งŒ, ๋ฐ์ดํ„ฐ ๋ ˆ์ด์–ด๋Š” UI ๋ ˆ์ด์–ด๋ฅผ ์˜์กดํ•ด์„  ์•ˆ ๋œ๋‹ค.

#### ๐Ÿš€ 2๋‹จ๊ณ„ - GitHub(UI ๋ ˆ์ด์–ด) ๊ฐœ์„  ์‚ฌํ•ญ
- GithubScreen(stateless) private ์ ‘๊ทผ ์ œ์–ด์ž ์ œ๊ฑฐ (ํ…Œ์ŠคํŠธ ์šฉ์ด์„ฑ)
- Text style ์ฝ”๋“œ ๊ฐ„์†Œํ™” (style ์ง€์ •ํ•˜๋ฉด ์ผ๊ด„ ์ ์šฉ)
- Color ์ง€์ •์„ MaterialTheme.colors ์‚ฌ์šฉํ•˜๋„๋ก ๋ณ€๊ฒฝ (ํ™•์žฅ ํ”„๋กœํผํ‹ฐ ํ™œ์šฉ)
- LazyColumn key ์ถ”๊ฐ€ (์„ฑ๋Šฅ ์ตœ์ ํ™”)
- viewModelScope Dispatchers.IO ์ œ๊ฑฐ(Retrofit ๋‚ด๋ถ€์ ์œผ๋กœ ์ ์ ˆํžˆ ์„ธํŒ…ํ•ด์คŒ)
- GithubScreen ๋‚ด๋ถ€ ์ปดํฌ๋„ŒํŠธ ๋ถ„๋ฆฌ
- GithubViewModel getRepositories > fetchRepositories๋กœ ํ•จ์ˆ˜๋ช… ๋ณ€๊ฒฝ(์˜๋„ ๋ช…ํ™•ํ™”)
- HorizontalDivider thickness 1dp ์ œ๊ฑฐ (๋‚ด๋ถ€ ๊ธฐ๋ณธ๊ฐ’์ด 1dp)

### ๐Ÿš€ 3๋‹จ๊ณ„ - GitHub(UI ์ƒํƒœ) ์š”๊ตฌ ์‚ฌํ•ญ
- ๋ชฉ๋ก์ด ๋กœ๋”ฉ๋˜๊ธฐ ์ „์—๋Š” ๋กœ๋”ฉ UI๋ฅผ ๋…ธ์ถœํ•œ๋‹ค.
- ๋ชฉ๋ก์ด ๋นˆ ๊ฒฝ์šฐ์—๋Š” ๋นˆ ํ™”๋ฉด UI๋ฅผ ๋…ธ์ถœํ•œ๋‹ค.
- ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•œ ๊ฒฝ์šฐ ์žฌ์‹œ๋„ ๊ฐ€๋Šฅํ•œ ์Šค๋‚ต๋ฐ”๋ฅผ ๋…ธ์ถœํ•œ๋‹ค.

48 changes: 0 additions & 48 deletions app/src/androidTest/java/GithubScreenTest.kt

This file was deleted.

141 changes: 141 additions & 0 deletions app/src/androidTest/java/StatefulGithubScreenTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import androidx.compose.ui.test.assertIsDisplayed
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 androidx.compose.ui.test.performClick
import kotlinx.coroutines.runBlocking
import nextstep.github.data.model.RepositoryModel
import nextstep.github.data.repository.FakeGithubRepository
import nextstep.github.ui.screen.github.GithubScreen
import nextstep.github.ui.screen.github.GithubViewModel
import org.junit.Before
import org.junit.Rule
import org.junit.Test

class StatefulGithubScreenTest {

@get:Rule
val composeTestRule = createComposeRule()

private lateinit var fakeViewModel: GithubViewModel
private lateinit var repository: FakeGithubRepository
private val data = listOf(
RepositoryModel(
id = 1,
fullName = "next-step/nextstep-docs",
description = "nextstep ๋งค๋‰ด์–ผ ๋ฐ ๋ฌธ์„œ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ์ €์žฅ์†Œ",
),
RepositoryModel(
id = 2,
fullName = "next-step/holy-moly",
description = "nextstep ํ™€๋ฆฌ๋ชฐ๋ฆฌํ•œ ์ €์žฅ์†Œ",
),
RepositoryModel(
id = 3,
fullName = "next-step/haly-galy",
description = "nextstep ํ• ๋ฆฌ๊ฐˆ๋ฆฌํ•œ ์ €์žฅ์†Œ",
),
)

@Before
fun setUp() {
// FakeGithubRepository ์ƒ์„ฑ
repository = FakeGithubRepository()

// GithubViewModel FakeGithubRepository ์ฃผ์ž… ๋ฐ ์ƒ์„ฑ
fakeViewModel = GithubViewModel(repository)
}

@Test
fun Github_๋ฐ์ดํ„ฐ๋ฅผ_์ •์ƒ์ ์œผ๋กœ_๋ถˆ๋Ÿฌ์™”์„๋–„_๋ฐ์ดํ„ฐ๊ฐ€_ํ™”๋ฉด์—_ํ‘œ์‹œ๋œ๋‹ค() {
// ๋ฐ์ดํ„ฐ ์„ธํŒ…
repository.setFakeData(data)

composeTestRule.setContent {
GithubScreen(viewModel = fakeViewModel)
}

// ๋ฐ์ดํ„ฐ ๋กœ๋“œ
runBlocking {
fakeViewModel.fetchRepositories("next-step")
}

// ๋ฐ์ดํ„ฐ ์ถœ๋ ฅ ๊ฒ€์ฆ
data.forEach {
composeTestRule.onNodeWithText(it.fullName)
.assertExists()
}
}

@Test
fun Github_๋ฐ์ดํ„ฐ๊ฐ€_๋น„์–ด์žˆ์„๋•Œ_ํ™”๋ฉด์—_๋ฉ”์‹œ์ง€๊ฐ€_์ถœ๋ ฅ๋œ๋‹ค() {
composeTestRule.setContent {
GithubScreen(viewModel = fakeViewModel)
}

// ๋ฐ์ดํ„ฐ ๋กœ๋“œ
runBlocking {
fakeViewModel.fetchRepositories("next-step")
}

// ๋นˆ ๋ฐ์ดํ„ฐ ๋ฉ”์‹œ์ง€ ์ถœ๋ ฅ ๊ฒ€์ฆ
composeTestRule.onAllNodesWithText("๋ชฉ๋ก์ด ๋น„์—ˆ์Šต๋‹ˆ๋‹ค.")
.onFirst()
.assertExists()
}

@Test
fun Github_๋ฐ์ดํ„ฐ๋ฅผ_๋กœ๋“œ์ค‘_์—๋Ÿฌ_๋ฐœ์ƒ์‹œ_์—๋Ÿฌ_์Šค๋‚ต๋ฐ”๋ฅผ_ํ˜ธ์ถœํ•œ๋‹ค() {
// ๋ฐ์ดํ„ฐ ๋กœ๋“œ ์‹คํŒจ ์„ธํŒ…
repository.setFailureMode(true)

composeTestRule.setContent {
GithubScreen(viewModel = fakeViewModel)
}

// ๋ฐ์ดํ„ฐ ๋กœ๋“œ
runBlocking {
fakeViewModel.fetchRepositories("next-step")
}

// ์—๋Ÿฌ ๋ฐœ์ƒ ์Šค๋‚ต๋ฐ” ํ˜ธ์ถœ ๊ฒ€์ฆ
composeTestRule.onNodeWithContentDescription("Snackbar")
.assertIsDisplayed()

composeTestRule.onNodeWithText("์˜ˆ์ƒ์น˜ ๋ชปํ•œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.")
.assertIsDisplayed()

composeTestRule.onNodeWithText("์žฌ์‹œ๋„")
.assertIsDisplayed()
}

@Test
fun Github_์—๋Ÿฌ_์Šค๋‚ต๋ฐ”_์žฌ์‹œ๋„_ํด๋ฆญ์‹œ_๋ฐ์ดํ„ฐ๋ฅผ_๋กœ๋“œ๋ฅผ_๋‹ค์‹œ_์‹œ๋„ํ•œ๋‹ค() {
// ๋ฐ์ดํ„ฐ ๋กœ๋“œ ์‹คํŒจ ์„ธํŒ…
repository.setFailureMode(true)

composeTestRule.setContent {
GithubScreen(viewModel = fakeViewModel)
}

runBlocking {
fakeViewModel.fetchRepositories("next-step")
}

// ๋ฐ์ดํ„ฐ ๋กœ๋“œ ์„ฑ๊ณต ์„ธํŒ…
repository.setFailureMode(false)
repository.setFakeData(data)

// ์—๋Ÿฌ ๋ฐœ์ƒ ํ›„ ์žฌ์‹œ๋„ ํด๋ฆญ
composeTestRule.onNodeWithText("์žฌ์‹œ๋„")
.performClick()

// ๋ฐ์ดํ„ฐ ๋กœ๋“œ ์„ฑ๊ณต ๊ฒ€์ฆ
data.forEach {
composeTestRule.onNodeWithText(it.fullName)
.assertExists()
}
}
}
152 changes: 152 additions & 0 deletions app/src/androidTest/java/StatelessGithubScreenTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,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()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package nextstep.github.data.repository

import nextstep.github.data.model.RepositoryModel

class FakeGithubRepository : GithubRepository {

private var shouldFail = false
private var fakeData: List<RepositoryModel> = emptyList()

fun setFakeData(data: List<RepositoryModel>) {
shouldFail = false
fakeData = data
}

fun setFailureMode(isFail: Boolean) {
shouldFail = isFail
}

override suspend fun getRepositories(organization: String): Result<List<RepositoryModel>> {
return if (shouldFail) {
Result.failure(Exception("Fake network error"))
} else {
Result.success(fakeData)
}
}
}
Loading