Merge pull request #7836 from vector-im/feature/ons/increase_dm_test_coverage
Increase session manager test coverage
This commit is contained in:
commit
9dec346cdc
|
@ -0,0 +1 @@
|
||||||
|
Increase session manager test coverage
|
|
@ -63,6 +63,11 @@ class DeleteMatrixClientInfoUseCaseTest {
|
||||||
// Given
|
// Given
|
||||||
val error = Exception()
|
val error = Exception()
|
||||||
givenSetMatrixClientInfoFails(error)
|
givenSetMatrixClientInfoFails(error)
|
||||||
|
val expectedClientInfoToBeSet = MatrixClientInfoContent(
|
||||||
|
name = "",
|
||||||
|
version = "",
|
||||||
|
url = "",
|
||||||
|
)
|
||||||
|
|
||||||
// When
|
// When
|
||||||
val result = deleteMatrixClientInfoUseCase.execute()
|
val result = deleteMatrixClientInfoUseCase.execute()
|
||||||
|
@ -70,6 +75,12 @@ class DeleteMatrixClientInfoUseCaseTest {
|
||||||
// Then
|
// Then
|
||||||
result.isFailure shouldBe true
|
result.isFailure shouldBe true
|
||||||
result.exceptionOrNull() shouldBeEqualTo error
|
result.exceptionOrNull() shouldBeEqualTo error
|
||||||
|
coVerify {
|
||||||
|
fakeSetMatrixClientInfoUseCase.execute(
|
||||||
|
fakeActiveSessionHolder.fakeSession,
|
||||||
|
expectedClientInfoToBeSet
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun givenSetMatrixClientInfoSucceeds() {
|
private fun givenSetMatrixClientInfoSucceeds() {
|
||||||
|
|
|
@ -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.CryptoDeviceInfo
|
||||||
import org.matrix.android.sdk.api.session.crypto.model.DeviceInfo
|
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.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
|
import org.matrix.android.sdk.api.session.uia.DefaultBaseAuth
|
||||||
|
|
||||||
private const val A_CURRENT_DEVICE_ID = "current-device-id"
|
private const val A_CURRENT_DEVICE_ID = "current-device-id"
|
||||||
|
@ -76,6 +78,10 @@ class DevicesViewModelTest {
|
||||||
private val fakeVectorPreferences = FakeVectorPreferences()
|
private val fakeVectorPreferences = FakeVectorPreferences()
|
||||||
private val toggleIpAddressVisibilityUseCase = mockk<ToggleIpAddressVisibilityUseCase>()
|
private val toggleIpAddressVisibilityUseCase = mockk<ToggleIpAddressVisibilityUseCase>()
|
||||||
|
|
||||||
|
private val verifiedTransaction = mockk<VerificationTransaction>().apply {
|
||||||
|
every { state } returns VerificationTxState.Verified
|
||||||
|
}
|
||||||
|
|
||||||
private fun createViewModel(): DevicesViewModel {
|
private fun createViewModel(): DevicesViewModel {
|
||||||
return DevicesViewModel(
|
return DevicesViewModel(
|
||||||
initialState = DevicesViewState(),
|
initialState = DevicesViewState(),
|
||||||
|
@ -375,6 +381,18 @@ class DevicesViewModelTest {
|
||||||
viewModelTest.finish()
|
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 {
|
private fun givenCurrentSessionCrossSigningInfo(): CurrentSessionCrossSigningInfo {
|
||||||
val currentSessionCrossSigningInfo = mockk<CurrentSessionCrossSigningInfo>()
|
val currentSessionCrossSigningInfo = mockk<CurrentSessionCrossSigningInfo>()
|
||||||
every { currentSessionCrossSigningInfo.deviceId } returns A_CURRENT_DEVICE_ID
|
every { currentSessionCrossSigningInfo.deviceId } returns A_CURRENT_DEVICE_ID
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
|
@ -77,4 +77,12 @@ class FakeVectorPreferences {
|
||||||
fun givenIsBackgroundSyncEnabled(isEnabled: Boolean) {
|
fun givenIsBackgroundSyncEnabled(isEnabled: Boolean) {
|
||||||
every { instance.isBackgroundSyncEnabled() } returns isEnabled
|
every { instance.isBackgroundSyncEnabled() } returns isEnabled
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun givenShowIpAddressInSessionManagerScreens(show: Boolean) {
|
||||||
|
every { instance.showIpAddressInSessionManagerScreens() } returns show
|
||||||
|
}
|
||||||
|
|
||||||
|
fun verifySetIpAddressVisibilityInDeviceManagerScreens(isVisible: Boolean) {
|
||||||
|
verify { instance.setIpAddressVisibilityInDeviceManagerScreens(isVisible) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue