Merge pull request #7836 from vector-im/feature/ons/increase_dm_test_coverage

Increase session manager test coverage
This commit is contained in:
Onuray Sahin 2022-12-23 14:36:26 +03:00 committed by GitHub
commit 9dec346cdc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 91 additions and 0 deletions

1
changelog.d/7836.misc Normal file
View File

@ -0,0 +1 @@
Increase session manager test coverage

View File

@ -63,6 +63,11 @@ class DeleteMatrixClientInfoUseCaseTest {
// Given
val error = Exception()
givenSetMatrixClientInfoFails(error)
val expectedClientInfoToBeSet = MatrixClientInfoContent(
name = "",
version = "",
url = "",
)
// When
val result = deleteMatrixClientInfoUseCase.execute()
@ -70,6 +75,12 @@ class DeleteMatrixClientInfoUseCaseTest {
// Then
result.isFailure shouldBe true
result.exceptionOrNull() shouldBeEqualTo error
coVerify {
fakeSetMatrixClientInfoUseCase.execute(
fakeActiveSessionHolder.fakeSession,
expectedClientInfoToBeSet
)
}
}
private fun givenSetMatrixClientInfoSucceeds() {

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

View File

@ -0,0 +1,53 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.app.features.settings.devices.v2
import im.vector.app.test.fakes.FakeVectorPreferences
import org.junit.Test
class ToggleIpAddressVisibilityUseCaseTest {
private val fakeVectorPreferences = FakeVectorPreferences()
private val toggleIpAddressVisibilityUseCase = ToggleIpAddressVisibilityUseCase(
vectorPreferences = fakeVectorPreferences.instance,
)
@Test
fun `given ip addresses are currently visible then then visibility is set as false`() {
// Given
fakeVectorPreferences.givenShowIpAddressInSessionManagerScreens(true)
// When
toggleIpAddressVisibilityUseCase.execute()
// Then
fakeVectorPreferences.verifySetIpAddressVisibilityInDeviceManagerScreens(false)
}
@Test
fun `given ip addresses are currently not visible then then visibility is set as true`() {
// Given
fakeVectorPreferences.givenShowIpAddressInSessionManagerScreens(false)
// When
toggleIpAddressVisibilityUseCase.execute()
// Then
fakeVectorPreferences.verifySetIpAddressVisibilityInDeviceManagerScreens(true)
}
}

View File

@ -77,4 +77,12 @@ class FakeVectorPreferences {
fun givenIsBackgroundSyncEnabled(isEnabled: Boolean) {
every { instance.isBackgroundSyncEnabled() } returns isEnabled
}
fun givenShowIpAddressInSessionManagerScreens(show: Boolean) {
every { instance.showIpAddressInSessionManagerScreens() } returns show
}
fun verifySetIpAddressVisibilityInDeviceManagerScreens(isVisible: Boolean) {
verify { instance.setIpAddressVisibilityInDeviceManagerScreens(isVisible) }
}
}