test(home): 팔로잉 테스트 상태를 격리한다

This commit is contained in:
2026-06-27 03:55:10 +09:00
parent a91ec763e1
commit 4a45f9699c
3 changed files with 11 additions and 14 deletions

View File

@@ -17,7 +17,8 @@ import kr.co.vividnext.sodalive.v2.main.home.model.toUiState
class HomeFollowingViewModel( class HomeFollowingViewModel(
private val repository: HomeFollowingRepository, private val repository: HomeFollowingRepository,
private val relativeTimeTextFormatter: UtcRelativeTimeTextFormatter private val relativeTimeTextFormatter: UtcRelativeTimeTextFormatter,
private val tokenProvider: () -> String = { SharedPreferenceManager.token }
) : BaseViewModel() { ) : BaseViewModel() {
private val _followingStateLiveData = MutableLiveData<HomeFollowingUiState>() private val _followingStateLiveData = MutableLiveData<HomeFollowingUiState>()
@@ -64,5 +65,5 @@ class HomeFollowingViewModel(
_toastLiveData.value = ToastMessage(resId = R.string.common_error_unknown) _toastLiveData.value = ToastMessage(resId = R.string.common_error_unknown)
} }
private fun authHeader(): String? = homeFollowingAuthHeader(SharedPreferenceManager.token) private fun authHeader(): String? = homeFollowingAuthHeader(tokenProvider())
} }

View File

@@ -40,7 +40,8 @@ class HomeFollowingFragmentSourceTest {
@Test @Test
fun `following tab branch shows following content and hides other home surfaces`() { fun `following tab branch shows following content and hides other home surfaces`() {
val source = homeMainFragmentSource() val source = homeMainFragmentSource()
val branch = source.substringAfter("HOME_TAB_FOLLOWING ->") val branch = source.substringAfter("private fun showHomeTab(index: Int)")
.substringAfter("HOME_TAB_FOLLOWING ->")
.substringBefore("}\n }") .substringBefore("}\n }")
assertTrue(branch.contains("binding.nsvHomeFollowingContent.visibility = View.VISIBLE")) assertTrue(branch.contains("binding.nsvHomeFollowingContent.visibility = View.VISIBLE"))

View File

@@ -1,10 +1,8 @@
package kr.co.vividnext.sodalive.v2.main.home package kr.co.vividnext.sodalive.v2.main.home
import android.app.Application import android.app.Application
import android.content.Context
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
import androidx.test.core.app.ApplicationProvider
import io.reactivex.rxjava3.android.plugins.RxAndroidPlugins import io.reactivex.rxjava3.android.plugins.RxAndroidPlugins
import io.reactivex.rxjava3.core.Scheduler import io.reactivex.rxjava3.core.Scheduler
import io.reactivex.rxjava3.core.Single import io.reactivex.rxjava3.core.Single
@@ -12,7 +10,6 @@ import io.reactivex.rxjava3.plugins.RxJavaPlugins
import io.reactivex.rxjava3.schedulers.Schedulers import io.reactivex.rxjava3.schedulers.Schedulers
import kr.co.vividnext.sodalive.R import kr.co.vividnext.sodalive.R
import kr.co.vividnext.sodalive.common.ApiResponse import kr.co.vividnext.sodalive.common.ApiResponse
import kr.co.vividnext.sodalive.common.SharedPreferenceManager
import kr.co.vividnext.sodalive.common.UtcRelativeTimeTextFormatter import kr.co.vividnext.sodalive.common.UtcRelativeTimeTextFormatter
import kr.co.vividnext.sodalive.v2.main.home.data.FollowingCreatorResponse import kr.co.vividnext.sodalive.v2.main.home.data.FollowingCreatorResponse
import kr.co.vividnext.sodalive.v2.main.home.data.HomeFollowingApi import kr.co.vividnext.sodalive.v2.main.home.data.HomeFollowingApi
@@ -33,21 +30,20 @@ import org.robolectric.annotation.Config
@Config(sdk = [28], application = Application::class) @Config(sdk = [28], application = Application::class)
class HomeFollowingViewModelTest { class HomeFollowingViewModelTest {
private val context: Context = ApplicationProvider.getApplicationContext()
private val formatter = UtcRelativeTimeTextFormatter { "relative:$it" } private val formatter = UtcRelativeTimeTextFormatter { "relative:$it" }
private var token: String = ""
private lateinit var api: FakeHomeFollowingApi private lateinit var api: FakeHomeFollowingApi
private lateinit var viewModel: HomeFollowingViewModel private lateinit var viewModel: HomeFollowingViewModel
@Before @Before
fun setUp() { fun setUp() {
setImmediateRxSchedulers() setImmediateRxSchedulers()
SharedPreferenceManager.resetForTest() token = ""
SharedPreferenceManager.init(context)
SharedPreferenceManager.token = ""
api = FakeHomeFollowingApi() api = FakeHomeFollowingApi()
viewModel = HomeFollowingViewModel( viewModel = HomeFollowingViewModel(
repository = HomeFollowingRepository(api), repository = HomeFollowingRepository(api),
relativeTimeTextFormatter = formatter relativeTimeTextFormatter = formatter,
tokenProvider = { token }
) )
} }
@@ -55,7 +51,6 @@ class HomeFollowingViewModelTest {
fun tearDown() { fun tearDown() {
RxJavaPlugins.reset() RxJavaPlugins.reset()
RxAndroidPlugins.reset() RxAndroidPlugins.reset()
SharedPreferenceManager.resetForTest()
} }
@Test @Test
@@ -71,7 +66,7 @@ class HomeFollowingViewModelTest {
@Test @Test
fun `blank token이면 repository에 null auth header를 전달한다`() { fun `blank token이면 repository에 null auth header를 전달한다`() {
SharedPreferenceManager.token = " " token = " "
api.enqueueSuccess(response(followingCreators = listOf(creator()))) api.enqueueSuccess(response(followingCreators = listOf(creator())))
viewModel.loadFollowing() viewModel.loadFollowing()
@@ -81,7 +76,7 @@ class HomeFollowingViewModelTest {
@Test @Test
fun `token이 있으면 repository에 Bearer auth header를 전달한다`() { fun `token이 있으면 repository에 Bearer auth header를 전달한다`() {
SharedPreferenceManager.token = "test-token" token = "test-token"
api.enqueueSuccess(response(followingCreators = listOf(creator()))) api.enqueueSuccess(response(followingCreators = listOf(creator())))
viewModel.loadFollowing() viewModel.loadFollowing()