From 84b3d5520c89a1f51156ea345bbf9b9c4eb810b6 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Mon, 30 May 2022 17:41:26 +0300 Subject: [PATCH] Fix unit tests. --- .../map/GetListOfUserLiveLocationUseCaseTest.kt | 13 +++++++++---- .../live/map/LocationLiveMapViewModelTest.kt | 12 +++++++++--- .../map/UserLiveLocationViewStateMapperTest.kt | 15 +++++++++++---- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/vector/src/test/java/im/vector/app/features/location/live/map/GetListOfUserLiveLocationUseCaseTest.kt b/vector/src/test/java/im/vector/app/features/location/live/map/GetListOfUserLiveLocationUseCaseTest.kt index 765eee4937..8a5a30e612 100644 --- a/vector/src/test/java/im/vector/app/features/location/live/map/GetListOfUserLiveLocationUseCaseTest.kt +++ b/vector/src/test/java/im/vector/app/features/location/live/map/GetListOfUserLiveLocationUseCaseTest.kt @@ -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 diff --git a/vector/src/test/java/im/vector/app/features/location/live/map/LocationLiveMapViewModelTest.kt b/vector/src/test/java/im/vector/app/features/location/live/map/LocationLiveMapViewModelTest.kt index 330cedf986..2a5fac4cdd 100644 --- a/vector/src/test/java/im/vector/app/features/location/live/map/LocationLiveMapViewModelTest.kt +++ b/vector/src/test/java/im/vector/app/features/location/live/map/LocationLiveMapViewModelTest.kt @@ -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() + private val locationServiceConnection = mockk() 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 ) ) diff --git a/vector/src/test/java/im/vector/app/features/location/live/map/UserLiveLocationViewStateMapperTest.kt b/vector/src/test/java/im/vector/app/features/location/live/map/UserLiveLocationViewStateMapperTest.kt index cd20e0f12e..88457d18b5 100644 --- a/vector/src/test/java/im/vector/app/features/location/live/map/UserLiveLocationViewStateMapperTest.kt +++ b/vector/src/test/java/im/vector/app/features/location/live/map/UserLiveLocationViewStateMapperTest.kt @@ -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 }