Add test for view navigation.

This commit is contained in:
Onuray Sahin 2022-09-16 17:41:51 +03:00
parent 61f5f81305
commit 6823258abb
3 changed files with 67 additions and 2 deletions

View File

@ -88,8 +88,8 @@ import im.vector.app.features.settings.account.deactivation.DeactivateAccountVie
import im.vector.app.features.settings.crosssigning.CrossSigningSettingsViewModel
import im.vector.app.features.settings.devices.DeviceVerificationInfoBottomSheetViewModel
import im.vector.app.features.settings.devices.DevicesViewModel
import im.vector.app.features.settings.devices.v2.othersessions.OtherSessionsViewModel
import im.vector.app.features.settings.devices.v2.details.SessionDetailsViewModel
import im.vector.app.features.settings.devices.v2.othersessions.OtherSessionsViewModel
import im.vector.app.features.settings.devices.v2.overview.SessionOverviewViewModel
import im.vector.app.features.settings.devtools.AccountDataViewModel
import im.vector.app.features.settings.devtools.GossipingEventsPaperTrailViewModel

View File

@ -52,8 +52,8 @@ class DevicesViewModelTest {
fakeActiveSessionHolder.instance,
getCurrentSessionCrossSigningInfoUseCase,
getDeviceFullInfoListUseCase,
refreshDevicesUseCase,
refreshDevicesOnCryptoDevicesChangeUseCase,
refreshDevicesUseCase,
)
}

View File

@ -0,0 +1,65 @@
/*
* 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.othersessions
import android.content.Intent
import im.vector.app.features.settings.devices.v2.overview.SessionOverviewActivity
import im.vector.app.test.fakes.FakeContext
import io.mockk.every
import io.mockk.mockk
import io.mockk.mockkObject
import io.mockk.unmockkAll
import io.mockk.verify
import org.junit.After
import org.junit.Before
import org.junit.Test
private const val A_DEVICE_ID = "A_DEVICE_ID"
class OtherSessionsViewNavigatorTest {
private val context = FakeContext()
private val otherSessionsViewNavigator = OtherSessionsViewNavigator()
@Before
fun setUp() {
mockkObject(SessionOverviewActivity)
}
@After
fun tearDown() {
unmockkAll()
}
@Test
fun `given a device id when navigating to overview then it starts the correct activity`() {
val intent = givenIntentForDeviceOverview(A_DEVICE_ID)
context.givenStartActivity(intent)
otherSessionsViewNavigator.navigateToSessionOverview(context.instance, A_DEVICE_ID)
verify {
context.instance.startActivity(intent)
}
}
private fun givenIntentForDeviceOverview(deviceId: String): Intent {
val intent = mockk<Intent>()
every { SessionOverviewActivity.newIntent(context.instance, deviceId) } returns intent
return intent
}
}