Remove Rx from EventHub and TimelineCases (#3446)
* remove Rx from EventHub and TimelineCases * fix tests * fix AccountViewModel.unblockDomain * remove debug logging
This commit is contained in:
parent
66eadabd44
commit
321d17f5de
25 changed files with 264 additions and 330 deletions
|
@ -18,10 +18,10 @@
|
|||
package com.keylesspalace.tusky.components.notifications
|
||||
|
||||
import app.cash.turbine.test
|
||||
import at.connyduck.calladapter.networkresult.NetworkResult
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import com.keylesspalace.tusky.FilterV1Test.Companion.mockStatus
|
||||
import com.keylesspalace.tusky.viewdata.StatusViewData
|
||||
import io.reactivex.rxjava3.core.Single
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Test
|
||||
|
@ -73,7 +73,7 @@ class NotificationsViewModelTestStatusAction : NotificationsViewModelTestBase()
|
|||
@Test
|
||||
fun `bookmark succeeds && emits UiSuccess`() = runTest {
|
||||
// Given
|
||||
timelineCases.stub { onBlocking { bookmark(any(), any()) } doReturn Single.just(status) }
|
||||
timelineCases.stub { onBlocking { bookmark(any(), any()) } doReturn NetworkResult.success(status) }
|
||||
|
||||
viewModel.uiSuccess.test {
|
||||
// When
|
||||
|
@ -111,7 +111,7 @@ class NotificationsViewModelTestStatusAction : NotificationsViewModelTestBase()
|
|||
fun `favourite succeeds && emits UiSuccess`() = runTest {
|
||||
// Given
|
||||
timelineCases.stub {
|
||||
onBlocking { favourite(any(), any()) } doReturn Single.just(status)
|
||||
onBlocking { favourite(any(), any()) } doReturn NetworkResult.success(status)
|
||||
}
|
||||
|
||||
viewModel.uiSuccess.test {
|
||||
|
@ -149,7 +149,7 @@ class NotificationsViewModelTestStatusAction : NotificationsViewModelTestBase()
|
|||
@Test
|
||||
fun `reblog succeeds && emits UiSuccess`() = runTest {
|
||||
// Given
|
||||
timelineCases.stub { onBlocking { reblog(any(), any()) } doReturn Single.just(status) }
|
||||
timelineCases.stub { onBlocking { reblog(any(), any()) } doReturn NetworkResult.success(status) }
|
||||
|
||||
viewModel.uiSuccess.test {
|
||||
// When
|
||||
|
@ -187,7 +187,7 @@ class NotificationsViewModelTestStatusAction : NotificationsViewModelTestBase()
|
|||
fun `voteinpoll succeeds && emits UiSuccess`() = runTest {
|
||||
// Given
|
||||
timelineCases.stub {
|
||||
onBlocking { voteInPoll(any(), any(), any()) } doReturn Single.just(status.poll!!)
|
||||
onBlocking { voteInPoll(any(), any(), any()) } doReturn NetworkResult.success(status.poll!!)
|
||||
}
|
||||
|
||||
viewModel.uiSuccess.test {
|
||||
|
|
|
@ -221,9 +221,9 @@ class ViewThreadViewModelTest {
|
|||
|
||||
viewModel.loadThread(threadId)
|
||||
|
||||
eventHub.dispatch(FavoriteEvent(statusId = "1", false))
|
||||
|
||||
runBlocking {
|
||||
eventHub.dispatch(FavoriteEvent(statusId = "1", false))
|
||||
|
||||
assertEquals(
|
||||
ThreadUiState.Success(
|
||||
statusViewData = listOf(
|
||||
|
@ -245,9 +245,9 @@ class ViewThreadViewModelTest {
|
|||
|
||||
viewModel.loadThread(threadId)
|
||||
|
||||
eventHub.dispatch(ReblogEvent(statusId = "2", true))
|
||||
|
||||
runBlocking {
|
||||
eventHub.dispatch(ReblogEvent(statusId = "2", true))
|
||||
|
||||
assertEquals(
|
||||
ThreadUiState.Success(
|
||||
statusViewData = listOf(
|
||||
|
@ -269,9 +269,9 @@ class ViewThreadViewModelTest {
|
|||
|
||||
viewModel.loadThread(threadId)
|
||||
|
||||
eventHub.dispatch(BookmarkEvent(statusId = "3", false))
|
||||
|
||||
runBlocking {
|
||||
eventHub.dispatch(BookmarkEvent(statusId = "3", false))
|
||||
|
||||
assertEquals(
|
||||
ThreadUiState.Success(
|
||||
statusViewData = listOf(
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
package com.keylesspalace.tusky.usecase
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import app.cash.turbine.test
|
||||
import at.connyduck.calladapter.networkresult.NetworkResult
|
||||
import com.keylesspalace.tusky.appstore.EventHub
|
||||
import com.keylesspalace.tusky.appstore.PinEvent
|
||||
import com.keylesspalace.tusky.entity.Status
|
||||
import com.keylesspalace.tusky.network.MastodonApi
|
||||
import io.reactivex.rxjava3.core.Single
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import okhttp3.ResponseBody.Companion.toResponseBody
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
@ -16,7 +19,7 @@ import org.mockito.kotlin.stub
|
|||
import org.robolectric.annotation.Config
|
||||
import retrofit2.HttpException
|
||||
import retrofit2.Response
|
||||
import java.util.Date
|
||||
import java.util.*
|
||||
|
||||
@Config(sdk = [28])
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
|
@ -38,21 +41,21 @@ class TimelineCasesTest {
|
|||
@Test
|
||||
fun `pin success emits PinEvent`() {
|
||||
api.stub {
|
||||
onBlocking { pinStatus(statusId) } doReturn Single.just(mockStatus(pinned = true))
|
||||
onBlocking { pinStatus(statusId) } doReturn NetworkResult.success(mockStatus(pinned = true))
|
||||
}
|
||||
|
||||
val events = eventHub.events.test()
|
||||
timelineCases.pin(statusId, true)
|
||||
.test()
|
||||
.assertComplete()
|
||||
|
||||
events.assertValue(PinEvent(statusId, true))
|
||||
runBlocking {
|
||||
eventHub.events.test {
|
||||
timelineCases.pin(statusId, true)
|
||||
assertEquals(PinEvent(statusId, true), awaitItem())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `pin failure with server error throws TimelineError with server message`() {
|
||||
api.stub {
|
||||
onBlocking { pinStatus(statusId) } doReturn Single.error(
|
||||
onBlocking { pinStatus(statusId) } doReturn NetworkResult.failure(
|
||||
HttpException(
|
||||
Response.error<Status>(
|
||||
422,
|
||||
|
@ -61,9 +64,12 @@ class TimelineCasesTest {
|
|||
)
|
||||
)
|
||||
}
|
||||
timelineCases.pin(statusId, true)
|
||||
.test()
|
||||
.assertError { it.message == "Validation Failed: You have already pinned the maximum number of toots" }
|
||||
runBlocking {
|
||||
assertEquals(
|
||||
"Validation Failed: You have already pinned the maximum number of toots",
|
||||
timelineCases.pin(statusId, true).exceptionOrNull()?.message
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun mockStatus(pinned: Boolean = false): Status {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue