Fix unit tests.

This commit is contained in:
Onuray Sahin 2022-09-19 16:18:30 +03:00
parent ec9843fb53
commit 2ad0cd46bb
5 changed files with 28 additions and 13 deletions

View File

@ -171,13 +171,15 @@ class DevicesViewModelTest {
deviceInfo = mockk(), deviceInfo = mockk(),
cryptoDeviceInfo = verifiedCryptoDeviceInfo, cryptoDeviceInfo = verifiedCryptoDeviceInfo,
roomEncryptionTrustLevel = RoomEncryptionTrustLevel.Trusted, roomEncryptionTrustLevel = RoomEncryptionTrustLevel.Trusted,
isInactive = false isInactive = false,
isCurrentDevice = true
) )
val deviceFullInfo2 = DeviceFullInfo( val deviceFullInfo2 = DeviceFullInfo(
deviceInfo = mockk(), deviceInfo = mockk(),
cryptoDeviceInfo = unverifiedCryptoDeviceInfo, cryptoDeviceInfo = unverifiedCryptoDeviceInfo,
roomEncryptionTrustLevel = RoomEncryptionTrustLevel.Warning, roomEncryptionTrustLevel = RoomEncryptionTrustLevel.Warning,
isInactive = true isInactive = true,
isCurrentDevice = false
) )
val deviceFullInfoList = listOf(deviceFullInfo1, deviceFullInfo2) val deviceFullInfoList = listOf(deviceFullInfo1, deviceFullInfo2)
val deviceFullInfoListFlow = flowOf(deviceFullInfoList) val deviceFullInfoListFlow = flowOf(deviceFullInfoList)

View File

@ -106,19 +106,22 @@ class GetDeviceFullInfoListUseCaseTest {
deviceInfo = deviceInfo1, deviceInfo = deviceInfo1,
cryptoDeviceInfo = cryptoDeviceInfo1, cryptoDeviceInfo = cryptoDeviceInfo1,
roomEncryptionTrustLevel = RoomEncryptionTrustLevel.Trusted, roomEncryptionTrustLevel = RoomEncryptionTrustLevel.Trusted,
isInactive = true isInactive = true,
isCurrentDevice = true
) )
val expectedResult2 = DeviceFullInfo( val expectedResult2 = DeviceFullInfo(
deviceInfo = deviceInfo2, deviceInfo = deviceInfo2,
cryptoDeviceInfo = cryptoDeviceInfo2, cryptoDeviceInfo = cryptoDeviceInfo2,
roomEncryptionTrustLevel = RoomEncryptionTrustLevel.Trusted, roomEncryptionTrustLevel = RoomEncryptionTrustLevel.Trusted,
isInactive = false isInactive = false,
isCurrentDevice = false
) )
val expectedResult3 = DeviceFullInfo( val expectedResult3 = DeviceFullInfo(
deviceInfo = deviceInfo3, deviceInfo = deviceInfo3,
cryptoDeviceInfo = cryptoDeviceInfo3, cryptoDeviceInfo = cryptoDeviceInfo3,
roomEncryptionTrustLevel = RoomEncryptionTrustLevel.Warning, roomEncryptionTrustLevel = RoomEncryptionTrustLevel.Warning,
isInactive = false isInactive = false,
isCurrentDevice = false
) )
val expectedResult = listOf(expectedResult3, expectedResult2, expectedResult1) val expectedResult = listOf(expectedResult3, expectedResult2, expectedResult1)
every { filterDevicesUseCase.execute(any(), any()) } returns expectedResult every { filterDevicesUseCase.execute(any(), any()) } returns expectedResult
@ -160,6 +163,7 @@ class GetDeviceFullInfoListUseCaseTest {
private fun givenCurrentSessionCrossSigningInfo(): CurrentSessionCrossSigningInfo { private fun givenCurrentSessionCrossSigningInfo(): CurrentSessionCrossSigningInfo {
val currentSessionCrossSigningInfo = mockk<CurrentSessionCrossSigningInfo>() val currentSessionCrossSigningInfo = mockk<CurrentSessionCrossSigningInfo>()
every { getCurrentSessionCrossSigningInfoUseCase.execute() } returns flowOf(currentSessionCrossSigningInfo) every { getCurrentSessionCrossSigningInfoUseCase.execute() } returns flowOf(currentSessionCrossSigningInfo)
every { currentSessionCrossSigningInfo.deviceId } returns A_DEVICE_ID_1
return currentSessionCrossSigningInfo return currentSessionCrossSigningInfo
} }

View File

@ -17,6 +17,7 @@
package im.vector.app.features.settings.devices.v2 package im.vector.app.features.settings.devices.v2
import android.content.Intent import android.content.Intent
import im.vector.app.features.settings.devices.v2.filter.DeviceManagerFilterType
import im.vector.app.features.settings.devices.v2.othersessions.OtherSessionsActivity import im.vector.app.features.settings.devices.v2.othersessions.OtherSessionsActivity
import im.vector.app.features.settings.devices.v2.overview.SessionOverviewActivity import im.vector.app.features.settings.devices.v2.overview.SessionOverviewActivity
import im.vector.app.test.fakes.FakeContext import im.vector.app.test.fakes.FakeContext
@ -30,6 +31,8 @@ import org.junit.Before
import org.junit.Test import org.junit.Test
private const val A_SESSION_ID = "session_id" private const val A_SESSION_ID = "session_id"
private const val A_TITLE_RESOURCE_ID = 1234
private val A_DEFAULT_FILTER = DeviceManagerFilterType.INACTIVE
class VectorSettingsDevicesViewNavigatorTest { class VectorSettingsDevicesViewNavigatorTest {
@ -61,10 +64,10 @@ class VectorSettingsDevicesViewNavigatorTest {
@Test @Test
fun `given an intent when navigating to other sessions list then it starts the correct activity`() { fun `given an intent when navigating to other sessions list then it starts the correct activity`() {
val intent = givenIntentForOtherSessions() val intent = givenIntentForOtherSessions(A_TITLE_RESOURCE_ID, A_DEFAULT_FILTER, true)
context.givenStartActivity(intent) context.givenStartActivity(intent)
vectorSettingsDevicesViewNavigator.navigateToOtherSessions(context.instance) vectorSettingsDevicesViewNavigator.navigateToOtherSessions(context.instance, A_TITLE_RESOURCE_ID, A_DEFAULT_FILTER, true)
verify { verify {
context.instance.startActivity(intent) context.instance.startActivity(intent)
@ -77,9 +80,9 @@ class VectorSettingsDevicesViewNavigatorTest {
return intent return intent
} }
private fun givenIntentForOtherSessions(): Intent { private fun givenIntentForOtherSessions(titleResourceId: Int, defaultFilter: DeviceManagerFilterType, includeCurrentSession: Boolean): Intent {
val intent = mockk<Intent>() val intent = mockk<Intent>()
every { OtherSessionsActivity.newIntent(context.instance) } returns intent every { OtherSessionsActivity.newIntent(context.instance, titleResourceId, defaultFilter, includeCurrentSession) } returns intent
return intent return intent
} }
} }

View File

@ -33,7 +33,8 @@ private val activeVerifiedDevice = DeviceFullInfo(
trustLevel = DeviceTrustLevel(crossSigningVerified = true, locallyVerified = true) trustLevel = DeviceTrustLevel(crossSigningVerified = true, locallyVerified = true)
), ),
roomEncryptionTrustLevel = RoomEncryptionTrustLevel.Trusted, roomEncryptionTrustLevel = RoomEncryptionTrustLevel.Trusted,
isInactive = false isInactive = false,
isCurrentDevice = true
) )
private val inactiveVerifiedDevice = DeviceFullInfo( private val inactiveVerifiedDevice = DeviceFullInfo(
deviceInfo = DeviceInfo(deviceId = "INACTIVE_VERIFIED_DEVICE"), deviceInfo = DeviceInfo(deviceId = "INACTIVE_VERIFIED_DEVICE"),
@ -43,7 +44,8 @@ private val inactiveVerifiedDevice = DeviceFullInfo(
trustLevel = DeviceTrustLevel(crossSigningVerified = true, locallyVerified = true) trustLevel = DeviceTrustLevel(crossSigningVerified = true, locallyVerified = true)
), ),
roomEncryptionTrustLevel = RoomEncryptionTrustLevel.Trusted, roomEncryptionTrustLevel = RoomEncryptionTrustLevel.Trusted,
isInactive = true isInactive = true,
isCurrentDevice = false
) )
private val activeUnverifiedDevice = DeviceFullInfo( private val activeUnverifiedDevice = DeviceFullInfo(
deviceInfo = DeviceInfo(deviceId = "ACTIVE_UNVERIFIED_DEVICE"), deviceInfo = DeviceInfo(deviceId = "ACTIVE_UNVERIFIED_DEVICE"),
@ -53,7 +55,8 @@ private val activeUnverifiedDevice = DeviceFullInfo(
trustLevel = DeviceTrustLevel(crossSigningVerified = false, locallyVerified = false) trustLevel = DeviceTrustLevel(crossSigningVerified = false, locallyVerified = false)
), ),
roomEncryptionTrustLevel = RoomEncryptionTrustLevel.Warning, roomEncryptionTrustLevel = RoomEncryptionTrustLevel.Warning,
isInactive = false isInactive = false,
isCurrentDevice = false
) )
private val inactiveUnverifiedDevice = DeviceFullInfo( private val inactiveUnverifiedDevice = DeviceFullInfo(
deviceInfo = DeviceInfo(deviceId = "INACTIVE_UNVERIFIED_DEVICE"), deviceInfo = DeviceInfo(deviceId = "INACTIVE_UNVERIFIED_DEVICE"),
@ -63,7 +66,8 @@ private val inactiveUnverifiedDevice = DeviceFullInfo(
trustLevel = DeviceTrustLevel(crossSigningVerified = false, locallyVerified = false) trustLevel = DeviceTrustLevel(crossSigningVerified = false, locallyVerified = false)
), ),
roomEncryptionTrustLevel = RoomEncryptionTrustLevel.Warning, roomEncryptionTrustLevel = RoomEncryptionTrustLevel.Warning,
isInactive = true isInactive = true,
isCurrentDevice = false
) )
private val devices = listOf( private val devices = listOf(

View File

@ -85,6 +85,7 @@ class GetDeviceFullInfoUseCaseTest {
fakeActiveSessionHolder.fakeSession.fakeCryptoService.cryptoDeviceInfoWithIdLiveData.givenAsFlow() fakeActiveSessionHolder.fakeSession.fakeCryptoService.cryptoDeviceInfoWithIdLiveData.givenAsFlow()
val trustLevel = givenTrustLevel(currentSessionCrossSigningInfo, cryptoDeviceInfo) val trustLevel = givenTrustLevel(currentSessionCrossSigningInfo, cryptoDeviceInfo)
val isInactive = false val isInactive = false
val isCurrentDevice = true
every { checkIfSessionIsInactiveUseCase.execute(any()) } returns isInactive every { checkIfSessionIsInactiveUseCase.execute(any()) } returns isInactive
// When // When
@ -96,6 +97,7 @@ class GetDeviceFullInfoUseCaseTest {
cryptoDeviceInfo = cryptoDeviceInfo, cryptoDeviceInfo = cryptoDeviceInfo,
roomEncryptionTrustLevel = trustLevel, roomEncryptionTrustLevel = trustLevel,
isInactive = isInactive, isInactive = isInactive,
isCurrentDevice = isCurrentDevice
) )
verify { fakeActiveSessionHolder.instance.getSafeActiveSession() } verify { fakeActiveSessionHolder.instance.getSafeActiveSession() }
verify { getCurrentSessionCrossSigningInfoUseCase.execute() } verify { getCurrentSessionCrossSigningInfoUseCase.execute() }