test(home): 팔로잉 테스트 상태를 격리한다
This commit is contained in:
@@ -17,7 +17,8 @@ import kr.co.vividnext.sodalive.v2.main.home.model.toUiState
|
||||
|
||||
class HomeFollowingViewModel(
|
||||
private val repository: HomeFollowingRepository,
|
||||
private val relativeTimeTextFormatter: UtcRelativeTimeTextFormatter
|
||||
private val relativeTimeTextFormatter: UtcRelativeTimeTextFormatter,
|
||||
private val tokenProvider: () -> String = { SharedPreferenceManager.token }
|
||||
) : BaseViewModel() {
|
||||
|
||||
private val _followingStateLiveData = MutableLiveData<HomeFollowingUiState>()
|
||||
@@ -64,5 +65,5 @@ class HomeFollowingViewModel(
|
||||
_toastLiveData.value = ToastMessage(resId = R.string.common_error_unknown)
|
||||
}
|
||||
|
||||
private fun authHeader(): String? = homeFollowingAuthHeader(SharedPreferenceManager.token)
|
||||
private fun authHeader(): String? = homeFollowingAuthHeader(tokenProvider())
|
||||
}
|
||||
|
||||
@@ -40,7 +40,8 @@ class HomeFollowingFragmentSourceTest {
|
||||
@Test
|
||||
fun `following tab branch shows following content and hides other home surfaces`() {
|
||||
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 }")
|
||||
|
||||
assertTrue(branch.contains("binding.nsvHomeFollowingContent.visibility = View.VISIBLE"))
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package kr.co.vividnext.sodalive.v2.main.home
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import io.reactivex.rxjava3.android.plugins.RxAndroidPlugins
|
||||
import io.reactivex.rxjava3.core.Scheduler
|
||||
import io.reactivex.rxjava3.core.Single
|
||||
@@ -12,7 +10,6 @@ import io.reactivex.rxjava3.plugins.RxJavaPlugins
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||
import kr.co.vividnext.sodalive.R
|
||||
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.v2.main.home.data.FollowingCreatorResponse
|
||||
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)
|
||||
class HomeFollowingViewModelTest {
|
||||
|
||||
private val context: Context = ApplicationProvider.getApplicationContext()
|
||||
private val formatter = UtcRelativeTimeTextFormatter { "relative:$it" }
|
||||
private var token: String = ""
|
||||
private lateinit var api: FakeHomeFollowingApi
|
||||
private lateinit var viewModel: HomeFollowingViewModel
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
setImmediateRxSchedulers()
|
||||
SharedPreferenceManager.resetForTest()
|
||||
SharedPreferenceManager.init(context)
|
||||
SharedPreferenceManager.token = ""
|
||||
token = ""
|
||||
api = FakeHomeFollowingApi()
|
||||
viewModel = HomeFollowingViewModel(
|
||||
repository = HomeFollowingRepository(api),
|
||||
relativeTimeTextFormatter = formatter
|
||||
relativeTimeTextFormatter = formatter,
|
||||
tokenProvider = { token }
|
||||
)
|
||||
}
|
||||
|
||||
@@ -55,7 +51,6 @@ class HomeFollowingViewModelTest {
|
||||
fun tearDown() {
|
||||
RxJavaPlugins.reset()
|
||||
RxAndroidPlugins.reset()
|
||||
SharedPreferenceManager.resetForTest()
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,7 +66,7 @@ class HomeFollowingViewModelTest {
|
||||
|
||||
@Test
|
||||
fun `blank token이면 repository에 null auth header를 전달한다`() {
|
||||
SharedPreferenceManager.token = " "
|
||||
token = " "
|
||||
api.enqueueSuccess(response(followingCreators = listOf(creator())))
|
||||
|
||||
viewModel.loadFollowing()
|
||||
@@ -81,7 +76,7 @@ class HomeFollowingViewModelTest {
|
||||
|
||||
@Test
|
||||
fun `token이 있으면 repository에 Bearer auth header를 전달한다`() {
|
||||
SharedPreferenceManager.token = "test-token"
|
||||
token = "test-token"
|
||||
api.enqueueSuccess(response(followingCreators = listOf(creator())))
|
||||
|
||||
viewModel.loadFollowing()
|
||||
|
||||
Reference in New Issue
Block a user