Fix unit tests.

This commit is contained in:
Onuray Sahin 2022-11-09 16:57:16 +03:00
parent e888c11747
commit 46c60f5897
4 changed files with 17 additions and 0 deletions

View file

@ -28,6 +28,7 @@ import im.vector.app.features.settings.devices.v2.verification.CurrentSessionCro
import im.vector.app.features.settings.devices.v2.verification.GetCurrentSessionCrossSigningInfoUseCase
import im.vector.app.test.fakes.FakeActiveSessionHolder
import im.vector.app.test.fakes.FakePendingAuthHandler
import im.vector.app.test.fakes.FakeSharedPreferences
import im.vector.app.test.fakes.FakeSignoutSessionsUseCase
import im.vector.app.test.fakes.FakeVerificationService
import im.vector.app.test.test
@ -72,6 +73,7 @@ class DevicesViewModelTest {
private val fakeInterceptSignoutFlowResponseUseCase = mockk<InterceptSignoutFlowResponseUseCase>()
private val fakePendingAuthHandler = FakePendingAuthHandler()
private val fakeRefreshDevicesUseCase = mockk<RefreshDevicesUseCase>(relaxUnitFun = true)
private val fakeSharedPreferences = FakeSharedPreferences()
private fun createViewModel(): DevicesViewModel {
return DevicesViewModel(
@ -85,6 +87,7 @@ class DevicesViewModelTest {
interceptSignoutFlowResponseUseCase = fakeInterceptSignoutFlowResponseUseCase,
pendingAuthHandler = fakePendingAuthHandler.instance,
refreshDevicesUseCase = fakeRefreshDevicesUseCase,
sharedPreferences = fakeSharedPreferences,
)
}
@ -97,6 +100,7 @@ class DevicesViewModelTest {
givenVerificationService()
givenCurrentSessionCrossSigningInfo()
givenDeviceFullInfoList(deviceId1 = A_DEVICE_ID_1, deviceId2 = A_DEVICE_ID_2)
fakeSharedPreferences.givenSessionManagerShowIpAddress(false)
}
private fun givenVerificationService(): FakeVerificationService {

View file

@ -26,6 +26,7 @@ import im.vector.app.features.settings.devices.v2.filter.DeviceManagerFilterType
import im.vector.app.features.settings.devices.v2.signout.InterceptSignoutFlowResponseUseCase
import im.vector.app.test.fakes.FakeActiveSessionHolder
import im.vector.app.test.fakes.FakePendingAuthHandler
import im.vector.app.test.fakes.FakeSharedPreferences
import im.vector.app.test.fakes.FakeSignoutSessionsUseCase
import im.vector.app.test.fakes.FakeVerificationService
import im.vector.app.test.fixtures.aDeviceFullInfo
@ -68,6 +69,7 @@ class OtherSessionsViewModelTest {
private val fakeSignoutSessionsUseCase = FakeSignoutSessionsUseCase()
private val fakeInterceptSignoutFlowResponseUseCase = mockk<InterceptSignoutFlowResponseUseCase>()
private val fakePendingAuthHandler = FakePendingAuthHandler()
private val fakeSharedPreferences = FakeSharedPreferences()
private fun createViewModel(viewState: OtherSessionsViewState = OtherSessionsViewState(defaultArgs)) =
OtherSessionsViewModel(
@ -78,6 +80,7 @@ class OtherSessionsViewModelTest {
interceptSignoutFlowResponseUseCase = fakeInterceptSignoutFlowResponseUseCase,
pendingAuthHandler = fakePendingAuthHandler.instance,
refreshDevicesUseCase = fakeRefreshDevicesUseCase,
sharedPreferences = fakeSharedPreferences,
)
@Before
@ -87,6 +90,7 @@ class OtherSessionsViewModelTest {
every { SystemClock.elapsedRealtime() } returns 1234
givenVerificationService()
fakeSharedPreferences.givenSessionManagerShowIpAddress(false)
}
private fun givenVerificationService(): FakeVerificationService {

View file

@ -28,6 +28,7 @@ import im.vector.app.features.settings.devices.v2.signout.InterceptSignoutFlowRe
import im.vector.app.features.settings.devices.v2.verification.CheckIfCurrentSessionCanBeVerifiedUseCase
import im.vector.app.test.fakes.FakeActiveSessionHolder
import im.vector.app.test.fakes.FakePendingAuthHandler
import im.vector.app.test.fakes.FakeSharedPreferences
import im.vector.app.test.fakes.FakeSignoutSessionUseCase
import im.vector.app.test.fakes.FakeTogglePushNotificationUseCase
import im.vector.app.test.fakes.FakeVerificationService
@ -77,6 +78,7 @@ class SessionOverviewViewModelTest {
private val togglePushNotificationUseCase = FakeTogglePushNotificationUseCase()
private val fakeGetNotificationsStatusUseCase = mockk<GetNotificationsStatusUseCase>()
private val notificationsStatus = NotificationsStatus.ENABLED
private val fakeSharedPreferences = FakeSharedPreferences()
private fun createViewModel() = SessionOverviewViewModel(
initialState = SessionOverviewViewState(args),
@ -89,6 +91,7 @@ class SessionOverviewViewModelTest {
refreshDevicesUseCase = refreshDevicesUseCase,
togglePushNotificationUseCase = togglePushNotificationUseCase.instance,
getNotificationsStatusUseCase = fakeGetNotificationsStatusUseCase,
sharedPreferences = fakeSharedPreferences,
)
@Before
@ -99,6 +102,7 @@ class SessionOverviewViewModelTest {
givenVerificationService()
every { fakeGetNotificationsStatusUseCase.execute(A_SESSION_ID_1) } returns flowOf(notificationsStatus)
fakeSharedPreferences.givenSessionManagerShowIpAddress(false)
}
private fun givenVerificationService(): FakeVerificationService {

View file

@ -18,6 +18,7 @@ package im.vector.app.test.fakes
import android.content.SharedPreferences
import im.vector.app.features.settings.FontScaleValue
import im.vector.app.features.settings.VectorPreferences.Companion.SETTINGS_SESSION_MANAGER_SHOW_IP_ADDRESS
import io.mockk.every
import io.mockk.mockk
@ -32,4 +33,8 @@ class FakeSharedPreferences : SharedPreferences by mockk() {
every { contains("APPLICATION_USE_SYSTEM_FONT_SCALE_KEY") } returns true
every { getBoolean("APPLICATION_USE_SYSTEM_FONT_SCALE_KEY", any()) } returns useSystemScale
}
fun givenSessionManagerShowIpAddress(showIpAddress: Boolean) {
every { getBoolean(SETTINGS_SESSION_MANAGER_SHOW_IP_ADDRESS, any()) } returns showIpAddress
}
}