Increase coverage of devices view model.

This commit is contained in:
Onuray Sahin 2022-12-21 14:30:32 +03:00
parent 50466792c6
commit 73e2f02c48
1 changed files with 18 additions and 0 deletions

View File

@ -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<ToggleIpAddressVisibilityUseCase>()
private val verifiedTransaction = mockk<VerificationTransaction>().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<CurrentSessionCrossSigningInfo>()
every { currentSessionCrossSigningInfo.deviceId } returns A_CURRENT_DEVICE_ID