mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-12-24 16:51:07 +01:00
Fix unit tests.
This commit is contained in:
parent
04679ea21d
commit
84b3d5520c
@ -35,6 +35,7 @@ import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.matrix.android.sdk.api.session.room.model.livelocation.LiveLocationShareAggregatedSummary
|
||||
import org.matrix.android.sdk.api.session.room.model.message.MessageBeaconLocationDataContent
|
||||
import org.matrix.android.sdk.api.util.MatrixItem
|
||||
|
||||
class GetListOfUserLiveLocationUseCaseTest {
|
||||
|
||||
@ -88,16 +89,20 @@ class GetListOfUserLiveLocationUseCaseTest {
|
||||
every { liveData.asFlow() } returns flowOf(summaries)
|
||||
|
||||
val viewState1 = UserLiveLocationViewState(
|
||||
userId = "userId1",
|
||||
matrixItem = MatrixItem.UserItem(id = "@userId1:matrix.org", displayName = "User 1", avatarUrl = ""),
|
||||
pinDrawable = mockk(),
|
||||
locationData = LocationData(latitude = 1.0, longitude = 2.0, uncertainty = null),
|
||||
endOfLiveTimestampMillis = 123
|
||||
endOfLiveTimestampMillis = 123,
|
||||
locationTimestampMillis = 123,
|
||||
showStopSharingButton = false
|
||||
)
|
||||
val viewState2 = UserLiveLocationViewState(
|
||||
userId = "userId2",
|
||||
matrixItem = MatrixItem.UserItem(id = "@userId2:matrix.org", displayName = "User 2", avatarUrl = ""),
|
||||
pinDrawable = mockk(),
|
||||
locationData = LocationData(latitude = 1.0, longitude = 2.0, uncertainty = null),
|
||||
endOfLiveTimestampMillis = 1234
|
||||
endOfLiveTimestampMillis = 1234,
|
||||
locationTimestampMillis = 1234,
|
||||
showStopSharingButton = false
|
||||
)
|
||||
coEvery { viewStateMapper.map(summary1) } returns viewState1
|
||||
coEvery { viewStateMapper.map(summary2) } returns viewState2
|
||||
|
@ -18,6 +18,7 @@ package im.vector.app.features.location.live.map
|
||||
|
||||
import com.airbnb.mvrx.test.MvRxTestRule
|
||||
import im.vector.app.features.location.LocationData
|
||||
import im.vector.app.features.location.LocationSharingServiceConnection
|
||||
import im.vector.app.test.test
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
@ -25,6 +26,7 @@ import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.matrix.android.sdk.api.util.MatrixItem
|
||||
|
||||
class LocationLiveMapViewModelTest {
|
||||
|
||||
@ -36,11 +38,13 @@ class LocationLiveMapViewModelTest {
|
||||
private val args = LocationLiveMapViewArgs(roomId = fakeRoomId)
|
||||
|
||||
private val getListOfUserLiveLocationUseCase = mockk<GetListOfUserLiveLocationUseCase>()
|
||||
private val locationServiceConnection = mockk<LocationSharingServiceConnection>()
|
||||
|
||||
private fun createViewModel(): LocationLiveMapViewModel {
|
||||
return LocationLiveMapViewModel(
|
||||
LocationLiveMapViewState(args),
|
||||
getListOfUserLiveLocationUseCase
|
||||
getListOfUserLiveLocationUseCase,
|
||||
locationServiceConnection
|
||||
)
|
||||
}
|
||||
|
||||
@ -48,10 +52,12 @@ class LocationLiveMapViewModelTest {
|
||||
fun `given the viewModel has been initialized then viewState contains user locations list`() = runTest {
|
||||
val userLocations = listOf(
|
||||
UserLiveLocationViewState(
|
||||
userId = "",
|
||||
MatrixItem.UserItem(id = "@userId1:matrix.org", displayName = "User 1", avatarUrl = ""),
|
||||
pinDrawable = mockk(),
|
||||
locationData = LocationData(latitude = 1.0, longitude = 2.0, uncertainty = null),
|
||||
endOfLiveTimestampMillis = 123
|
||||
endOfLiveTimestampMillis = 123,
|
||||
locationTimestampMillis = 123,
|
||||
showStopSharingButton = false
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -18,7 +18,9 @@ package im.vector.app.features.location.live.map
|
||||
|
||||
import android.graphics.drawable.Drawable
|
||||
import im.vector.app.features.location.LocationData
|
||||
import im.vector.app.test.fakes.FakeActiveSessionHolder
|
||||
import im.vector.app.test.fakes.FakeLocationPinProvider
|
||||
import im.vector.app.test.fakes.FakeSession
|
||||
import io.mockk.mockk
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.amshove.kluent.shouldBeEqualTo
|
||||
@ -26,8 +28,9 @@ import org.junit.Test
|
||||
import org.matrix.android.sdk.api.session.room.model.livelocation.LiveLocationShareAggregatedSummary
|
||||
import org.matrix.android.sdk.api.session.room.model.message.LocationInfo
|
||||
import org.matrix.android.sdk.api.session.room.model.message.MessageBeaconLocationDataContent
|
||||
import org.matrix.android.sdk.api.util.MatrixItem
|
||||
|
||||
private const val A_USER_ID = "aUserId"
|
||||
private const val A_USER_ID = "@aUserId:matrix.org"
|
||||
private const val A_IS_ACTIVE = true
|
||||
private const val A_END_OF_LIVE_TIMESTAMP = 123L
|
||||
private const val A_LATITUDE = 40.05
|
||||
@ -38,8 +41,10 @@ private const val A_GEO_URI = "geo:$A_LATITUDE,$A_LONGITUDE;$A_UNCERTAINTY"
|
||||
class UserLiveLocationViewStateMapperTest {
|
||||
|
||||
private val locationPinProvider = FakeLocationPinProvider()
|
||||
private val fakeSession = FakeSession()
|
||||
private val fakeActiveSessionHolder = FakeActiveSessionHolder(fakeSession)
|
||||
|
||||
private val userLiveLocationViewStateMapper = UserLiveLocationViewStateMapper(locationPinProvider.instance)
|
||||
private val userLiveLocationViewStateMapper = UserLiveLocationViewStateMapper(locationPinProvider.instance, fakeActiveSessionHolder.instance)
|
||||
|
||||
@Test
|
||||
fun `given a summary with invalid data then result is null`() = runTest {
|
||||
@ -79,14 +84,16 @@ class UserLiveLocationViewStateMapperTest {
|
||||
val viewState = userLiveLocationViewStateMapper.map(summary)
|
||||
|
||||
val expectedViewState = UserLiveLocationViewState(
|
||||
userId = A_USER_ID,
|
||||
matrixItem = MatrixItem.UserItem(id = A_USER_ID, displayName = "User 2", avatarUrl = ""),
|
||||
pinDrawable = pinDrawable,
|
||||
locationData = LocationData(
|
||||
latitude = A_LATITUDE,
|
||||
longitude = A_LONGITUDE,
|
||||
uncertainty = A_UNCERTAINTY
|
||||
),
|
||||
endOfLiveTimestampMillis = A_END_OF_LIVE_TIMESTAMP
|
||||
endOfLiveTimestampMillis = A_END_OF_LIVE_TIMESTAMP,
|
||||
locationTimestampMillis = A_END_OF_LIVE_TIMESTAMP,
|
||||
showStopSharingButton = false
|
||||
)
|
||||
viewState shouldBeEqualTo expectedViewState
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user