Skip to content

Commit

Permalink
Merge pull request #55 from f-lab-edu/feature/explore-ui-test
Browse files Browse the repository at this point in the history
explore ui test
  • Loading branch information
Guri999 authored Jan 31, 2025
2 parents d3d9c24 + e9989ca commit 74a6f72
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 14 deletions.
19 changes: 6 additions & 13 deletions core/ui/src/main/java/kr/co/ui/widget/FileBox.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,36 +38,29 @@ fun FileBox(
.padding(
vertical = 12.dp,
horizontal = 8.dp
)
.semantics {
contentDescription = name
},
),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(24.dp)
) {
Icon(
modifier = Modifier.size(32.dp)
.clearAndSetSemantics { },
modifier = Modifier.size(32.dp),
imageVector = SeeDocsIcon.PDF,
contentDescription = null,
contentDescription = "pdf",
tint = Color.Unspecified
)

Column(
modifier = Modifier
.clearAndSetSemantics { },
modifier = Modifier,
verticalArrangement = Arrangement.spacedBy(4.dp)
) {
Text(
modifier = Modifier
.clearAndSetSemantics { },
modifier = Modifier,
text = name,
style = Theme.typography.body2sb,
color = Theme.colors.text
)
Text(
modifier = Modifier
.clearAndSetSemantics { },
modifier = Modifier,
text = dateTime.format(DateTimeFormatter.ofPattern("yyyy.MM.dd")),
style = Theme.typography.caption1r,
color = Theme.colors.grayText
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package kr.co.explore

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import kr.co.model.ExploreUiIntent
import kr.co.model.ExploreUiState
import kr.co.model.FileInfo
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import kotlin.test.assertEquals

class ExploreScreenTest {

@get: Rule
val composeTestRule = createComposeRule()
private val fakeUiState: MutableState<ExploreUiState> =
mutableStateOf(ExploreUiState.INIT)

private val fakeHandleIntent: MutableState<(ExploreUiIntent) -> Unit> =
mutableStateOf({})

@Before
fun setup() {
composeTestRule.setContent {
ExploreScreen(
state = fakeUiState.value,
padding = PaddingValues(),
handleIntent = fakeHandleIntent.value
)
}
}

@Test
fun given_path_when_init_then_show_path() {
fakeUiState.value = ExploreUiState.INIT.copy(path = "/local/storage")

composeTestRule
.onNode(hasText("> /local/storage"))
.assertExists()
}

@Test
fun when_state_contains_files_then_show_files() {
fakeUiState.value = ExploreUiState(
path = "/local/storage",
folders = folders,
files = files,
)

composeTestRule
.onNodeWithText("Documents")
.assertExists()
composeTestRule
.onNodeWithText("Downloads")
.assertExists()
composeTestRule
.onNodeWithText("File1.pdf")
.assertExists()
}

@Test
fun when_file_click_then_handle_intent() {
var clickedFile: FileInfo? = null

fakeUiState.value = ExploreUiState(
path = "/local/storage",
folders = emptyList(),
files = files
)

fakeHandleIntent.value = { intent ->
if (intent is ExploreUiIntent.ClickFile) {
clickedFile = intent.file
}
}

composeTestRule
.onNodeWithText("File1.pdf")
.performClick()

assertEquals(clickedFile, files.first())
}

companion object {
private val folders = listOf(
FileInfo.INIT.copy(
name = "Documents",
path = "/local/storage",
isDirectory = true,
),
FileInfo.INIT.copy(
name = "Downloads",
path = "/local/storage",
isDirectory = true,
)
)

private val files = listOf(
FileInfo.INIT.copy(
name = "File1.pdf",
path = "/local/storage",
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ internal fun ExploreRoute(
}

@Composable
private fun ExploreScreen(
internal fun ExploreScreen(
state: ExploreUiState = ExploreUiState.INIT,
padding: PaddingValues,
handleIntent: (ExploreUiIntent) -> Unit = {},
Expand Down

0 comments on commit 74a6f72

Please sign in to comment.