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

Refactor/Export test #40

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions core/testing/src/main/java/kr/co/testing/util/assertUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package kr.co.testing.util

import junit.framework.TestCase.assertEquals

fun asserts(vararg value: Boolean) =
value.forEach {
assert(it)
}

fun assertsEquals(vararg value: Pair<Any?, Any?>) =
value.forEach { (a, b) ->
assertEquals(a, b)
}
17 changes: 17 additions & 0 deletions core/testing/src/main/java/kr/co/testing/util/testWithItem.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package kr.co.testing.util

import app.cash.turbine.test
import kotlinx.coroutines.flow.Flow
import kotlin.time.Duration

suspend fun <T> Flow<T>.testWithItem(
timeout: Duration? = null,
name: String? = null,
action: suspend T.() -> Unit,
) =
test(timeout, name) {
awaitItem().also {
action(it)
cancelAndConsumeRemainingEvents()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ import kr.co.model.FileInfo
import kr.co.model.FileInfo.Type.PDF
import kr.co.testing.repository.TestRecentRepository
import kr.co.testing.rule.CoroutineTestRule
import kr.co.testing.util.asserts
import kr.co.testing.util.testWithItem
import kr.co.util.FileManager
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import java.time.LocalDateTime
import kotlin.test.assertEquals


class ExploreViewModelTest {
internal class ExploreViewModelTest {

@get: Rule
val coroutineTestRule = CoroutineTestRule()
Expand Down Expand Up @@ -54,11 +55,14 @@ class ExploreViewModelTest {

viewModel.uiState.test {
val state = awaitItem()
assert(state.path == path)
assertEquals(state.files.size, files.size)
assertEquals(state.folders.size, folders.size)
assert(state.folders == folders)
assert(state.files == files)

asserts(
state.path == path,
state.files == files,
state.folders == folders,
state.files.size == files.size,
state.folders.size == folders.size
)
}
}

Expand All @@ -72,11 +76,9 @@ class ExploreViewModelTest {

recentRepository.insert(file)

viewModel.sideEffect.test {
awaitItem().also {
assert(it is ExploreSideEffect.NavigateToPdf)
assert((it as ExploreSideEffect.NavigateToPdf).path == file.path)
}
viewModel.sideEffect.testWithItem {
require(this is ExploreSideEffect.NavigateToPdf)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด์ „ PR์—์„œ ์ฝ”๋ฉ˜ํŠธ ๋“œ๋ ธ๋“ฏ์ด require๋ฅผ ์ œ๊ฑฐํ•ด์ฃผ์„ธ์š”.

assert(path == file.path)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertEquals ํ™œ์šฉ์„ ์ถ”์ฒœ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

}
}

Expand All @@ -86,11 +88,9 @@ class ExploreViewModelTest {

viewModel.handleIntent(ExploreUiIntent.ClickFolder(folder))

viewModel.sideEffect.test {
awaitItem().also {
assert(it is ExploreSideEffect.NavigateToFolder)
assert((it as ExploreSideEffect.NavigateToFolder).path == folder.path)
}
viewModel.sideEffect.testWithItem {
require(this is ExploreSideEffect.NavigateToFolder)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

assert(path == folder.path)
}
}

Expand Down
Loading