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(),
cryptoDeviceInfo = verifiedCryptoDeviceInfo,
roomEncryptionTrustLevel = RoomEncryptionTrustLevel.Trusted,
isInactive = false
isInactive = false,
isCurrentDevice = true
)
val deviceFullInfo2 = DeviceFullInfo(
deviceInfo = mockk(),
cryptoDeviceInfo = unverifiedCryptoDeviceInfo,
roomEncryptionTrustLevel = RoomEncryptionTrustLevel.Warning,
isInactive = true
isInactive = true,
isCurrentDevice = false
)
val deviceFullInfoList = listOf(deviceFullInfo1, deviceFullInfo2)
val deviceFullInfoListFlow = flowOf(deviceFullInfoList)

View file

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

View file

@ -17,6 +17,7 @@
package im.vector.app.features.settings.devices.v2
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.overview.SessionOverviewActivity
import im.vector.app.test.fakes.FakeContext
@ -30,6 +31,8 @@ import org.junit.Before
import org.junit.Test
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 {
@ -61,10 +64,10 @@ class VectorSettingsDevicesViewNavigatorTest {
@Test
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)
vectorSettingsDevicesViewNavigator.navigateToOtherSessions(context.instance)
vectorSettingsDevicesViewNavigator.navigateToOtherSessions(context.instance, A_TITLE_RESOURCE_ID, A_DEFAULT_FILTER, true)
verify {
context.instance.startActivity(intent)
@ -77,9 +80,9 @@ class VectorSettingsDevicesViewNavigatorTest {
return intent
}
private fun givenIntentForOtherSessions(): Intent {
private fun givenIntentForOtherSessions(titleResourceId: Int, defaultFilter: DeviceManagerFilterType, includeCurrentSession: Boolean): Intent {
val intent = mockk<Intent>()
every { OtherSessionsActivity.newIntent(context.instance) } returns intent
every { OtherSessionsActivity.newIntent(context.instance, titleResourceId, defaultFilter, includeCurrentSession) } returns intent
return intent
}
}

View file

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

View file

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