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

[Contributor] ContributorViewModel 테스트 코드 작성 #153

Merged
merged 2 commits into from
Jul 31, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ internal class DefaultContributorRepositoryTest : BehaviorSpec() {
)

init {
Given("기여자가 존재한다") {
Given("컨트리뷰터가 존재한다") {
val expected = contributors

When("기여자를 조회한다") {
When("컨트리뷰터를 조회한다") {
val contributors: List<Contributor> = repository.getContributors(
owner = "droidknights",
name = "app2023"
)
Then("기여자를 반환한다") {
Then("컨트리뷰터를 반환한다") {
contributors.size shouldBe 1
contributors.all {
it.name == expected[0].name
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.droidknights.app2023.feature.contributor

import app.cash.turbine.test
import com.droidknights.app2023.core.domain.usecase.GetContributorsUseCase
import com.droidknights.app2023.core.model.Contributor
import com.droidknights.app2023.core.testing.rule.MainDispatcherRule
import io.mockk.coEvery
import io.mockk.mockk
import kotlinx.coroutines.test.runTest
import org.junit.Rule
import org.junit.Test
import kotlin.test.assertIs

internal class ContributorViewModelTest {
@get:Rule
val dispatcherRule = MainDispatcherRule()

private val getContributorsUseCase: GetContributorsUseCase = mockk()
private lateinit var viewModel: ContributorViewModel

@Test
fun `컨트리뷰터 데이터를 확인할 수 있다`() = runTest {
// given
coEvery { getContributorsUseCase() } returns fakeContributors
viewModel = ContributorViewModel(getContributorsUseCase)

// when & then
viewModel.uiState.test {
val actual: ContributorsUiState = awaitItem()
assertIs<ContributorsUiState.Contributors>(actual)
}
}

companion object {
private val fakeContributors = listOf(
Contributor(
name = "test name",
imageUrl = "test image url"
)
)
}
}