From 73e2f02c4897b6995e7d350f7604f6f878f6cf50 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Wed, 21 Dec 2022 14:30:32 +0300 Subject: [PATCH] Increase coverage of devices view model. --- .../devices/v2/DevicesViewModelTest.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/vector/src/test/java/im/vector/app/features/settings/devices/v2/DevicesViewModelTest.kt b/vector/src/test/java/im/vector/app/features/settings/devices/v2/DevicesViewModelTest.kt index 4bfd5c4496..524858da77 100644 --- a/vector/src/test/java/im/vector/app/features/settings/devices/v2/DevicesViewModelTest.kt +++ b/vector/src/test/java/im/vector/app/features/settings/devices/v2/DevicesViewModelTest.kt @@ -53,6 +53,8 @@ import org.matrix.android.sdk.api.session.crypto.crosssigning.DeviceTrustLevel import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo import org.matrix.android.sdk.api.session.crypto.model.DeviceInfo import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel +import org.matrix.android.sdk.api.session.crypto.verification.VerificationTransaction +import org.matrix.android.sdk.api.session.crypto.verification.VerificationTxState import org.matrix.android.sdk.api.session.uia.DefaultBaseAuth private const val A_CURRENT_DEVICE_ID = "current-device-id" @@ -76,6 +78,10 @@ class DevicesViewModelTest { private val fakeVectorPreferences = FakeVectorPreferences() private val toggleIpAddressVisibilityUseCase = mockk() + private val verifiedTransaction = mockk().apply { + every { state } returns VerificationTxState.Verified + } + private fun createViewModel(): DevicesViewModel { return DevicesViewModel( initialState = DevicesViewState(), @@ -375,6 +381,18 @@ class DevicesViewModelTest { viewModelTest.finish() } + @Test + fun `given the view model when a verified transaction is updated then device list is refreshed`() { + // Given + val viewModel = createViewModel() + + // When + viewModel.transactionUpdated(verifiedTransaction) + + // Then + verify { viewModel.refreshDeviceList() } + } + private fun givenCurrentSessionCrossSigningInfo(): CurrentSessionCrossSigningInfo { val currentSessionCrossSigningInfo = mockk() every { currentSessionCrossSigningInfo.deviceId } returns A_CURRENT_DEVICE_ID