-
Notifications
You must be signed in to change notification settings - Fork 1
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
BookmarkViewModelTest #39
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package kr.co.bookmark | ||
|
||
import app.cash.turbine.test | ||
import io.mockk.MockKAnnotations | ||
import io.mockk.coEvery | ||
import io.mockk.impl.annotations.MockK | ||
import kotlinx.coroutines.flow.flowOf | ||
import kotlinx.coroutines.test.runTest | ||
import kr.co.data.repository.BookmarkRepository | ||
import kr.co.data.repository.RecentRepository | ||
import kr.co.model.BookmarkSideEffect | ||
import kr.co.model.BookmarkUiIntent | ||
import kr.co.model.FileInfo | ||
import kr.co.model.FileInfo.Type.PDF | ||
import kr.co.testing.rule.CoroutineTestRule | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import java.time.LocalDateTime | ||
import kotlin.test.assertEquals | ||
|
||
internal class BookmarkViewModelTest { | ||
|
||
@get: Rule | ||
val coroutineTestRule = CoroutineTestRule() | ||
|
||
@MockK | ||
private lateinit var bookmarkRepository: BookmarkRepository | ||
|
||
@MockK | ||
private lateinit var recentRepository: RecentRepository | ||
|
||
private lateinit var viewModel: BookmarkViewModel | ||
|
||
@Before | ||
fun setup() { | ||
MockKAnnotations.init(this) | ||
viewModel = BookmarkViewModel(bookmarkRepository,recentRepository) | ||
} | ||
|
||
@Test | ||
fun `Given a Unit when Init intent is handled then state is updated`() = runTest { | ||
val dummy = listOf(PDF_DUMMY, PDF_DUMMY) | ||
|
||
coEvery { bookmarkRepository.get() } returns flowOf(dummy) | ||
|
||
viewModel.handleIntent(BookmarkUiIntent.Init) | ||
|
||
viewModel.uiState.test { | ||
val state = awaitItem() | ||
assertEquals(state.files, dummy) | ||
} | ||
} | ||
|
||
@Test | ||
fun `Given a file when ClickFile intent is handled then navigate to pdf`() = runTest { | ||
val file = PDF_DUMMY | ||
|
||
viewModel.handleIntent(BookmarkUiIntent.ClickFile(file)) | ||
|
||
viewModel.sideEffect.test { | ||
awaitItem().also { | ||
assert(it is BookmarkSideEffect.NavigateToPdf) | ||
assert((it as BookmarkSideEffect.NavigateToPdf).path == file.path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. assertEqualsλ₯Ό μ¬μ©νλ©΄ μλ―Έλ₯Ό λ μ ννκ² ννν μ μμ΅λλ€. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. λ€μ PRμμ μμ νμ΅λλ€ |
||
} | ||
} | ||
} | ||
|
||
companion object { | ||
val PDF_DUMMY = FileInfo( | ||
name = "DUMMY.pdf", | ||
path = "", | ||
type = PDF, | ||
isDirectory = false, | ||
isHidden = false, | ||
size = 0, | ||
createdAt = LocalDateTime.now(), | ||
lastModified = LocalDateTime.now() | ||
) | ||
|
||
val FOLDER_DUMMY = FileInfo( | ||
name = "DUMMY", | ||
path = "", | ||
type = PDF, | ||
isDirectory = true, | ||
isHidden = false, | ||
size = 0, | ||
createdAt = LocalDateTime.now(), | ||
lastModified = LocalDateTime.now() | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,11 @@ import io.mockk.MockKAnnotations | |
import io.mockk.coEvery | ||
import io.mockk.impl.annotations.MockK | ||
import kotlinx.coroutines.test.runTest | ||
import kr.co.data.repository.RecentRepository | ||
import kr.co.model.ExploreSideEffect | ||
import kr.co.model.ExploreUiIntent | ||
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.util.FileManager | ||
import org.junit.Before | ||
|
@@ -26,7 +26,8 @@ class ExploreViewModelTest { | |
|
||
private lateinit var viewModel: ExploreViewModel | ||
|
||
private val recentRepository = TestRecentRepository() | ||
@MockK | ||
private lateinit var recentRepository: RecentRepository | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ν
μ€νΈ μ½λ μμ±μ κ΄νμ¬ κ³ μ νμ λ°λν λ κ°μ§μ ννκ° μμ΅λλ€. κ·Έλ¦¬κ³ Kotestμ κ²½μ°λ Mockkμ ν¨κ» μ¬μ©νλ©΄ μ±λ₯μ νκ° λ°μνκΈ°λ ν©λλ€. |
||
|
||
@MockK | ||
private lateinit var fileManager: FileManager | ||
|
@@ -93,7 +94,6 @@ class ExploreViewModelTest { | |
} | ||
} | ||
} | ||
|
||
companion object { | ||
val PDF_DUMMY = FileInfo( | ||
name = "DUMMY.pdf", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μλμ κ°μ΄ μμ±νλ©΄ μ€λ§νΈ μΊμ€ν μ νμ©ν μ μμ΅λλ€.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
requireλ₯Ό νμ©ν λ°©λ²μ μ΄λ€κ°μ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ν μ€νΈ μ½λμμ requireλ μ ν©νμ§ μμ΅λλ€.
requireμ μ©λλ μ λ ₯κ°μ λν μ¬μ 쑰건 νμΈμ μλ―Έν©λλ€. λ°λ©΄ assertλ μ€ν κ²°κ³Όκ° κΈ°λν λ°μ λ§λμ§μ λν κ²μ¦μ λλ€.
ν μ€νΈ μ½λλ λμν μ½λμ κ²°κ³Όλ¬Όμ λν "κ²μ¦" μ΄ λͺ©μ μ΄λ―λ‘ assertκ° μ¬μ©μ¬λ‘μ λ§μ΅λλ€.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ assertλ‘ μ μ€λ§νΈ μΊμ€ν μ΄ μλμ£ ,,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ? κ·ΈλΌ νΉμ assertTrue(effect is BookmarkSideEffect.NavigateToPdf) λ‘ ν΄λ³΄μκ² μ΄μ?
κ·Έλλ μΊμ€ν μ΄ μλλ€λ©΄ requireλ₯Ό μ¬μ©νμ§ μμ κΈ°μ‘΄μ ννλ‘ νμ λ λ©λλ€.